From d066cb31dd207d81df413e1b16e66efe52200e57 Mon Sep 17 00:00:00 2001 From: stefan <stefan@5a81b35b-ba03-0410-adc8-b2c5c5119f08> Date: Fri, 4 Jun 2010 14:27:20 +0000 Subject: [PATCH] MapIso, added GetMinLevel and GetMaxLevel git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2336 5a81b35b-ba03-0410-adc8-b2c5c5119f08 --- modules/gfx/pymod/export_map.cc | 2 ++ modules/gfx/src/map_iso.cc | 32 +++++++++++++++++++++++++------- modules/gfx/src/map_iso.hh | 8 ++++++++ 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/modules/gfx/pymod/export_map.cc b/modules/gfx/pymod/export_map.cc index f4957efb4..4fd9ae0ec 100644 --- a/modules/gfx/pymod/export_map.cc +++ b/modules/gfx/pymod/export_map.cc @@ -60,6 +60,8 @@ void export_Map() boost::noncopyable>("MapIso", init<const String&, const ::img::MapHandle&, float, optional<uint> >()) .def("SetLevel",&MapIso::SetLevel) .def("GetLevel",&MapIso::GetLevel) + .def("GetMinLevel",&MapIso::GetMinLevel) + .def("GetMaxLevel",&MapIso::GetMaxLevel) .def("GetMean", &MapIso::GetMean) .def("GetMap", &MapIso::GetMap,return_value_policy<reference_existing_object>()) .def("GetOriginalMap", &MapIso::GetOriginalMap,return_value_policy<reference_existing_object>()) diff --git a/modules/gfx/src/map_iso.cc b/modules/gfx/src/map_iso.cc index 9acb420c4..a6bbdfa7f 100644 --- a/modules/gfx/src/map_iso.cc +++ b/modules/gfx/src/map_iso.cc @@ -24,7 +24,6 @@ #include <ost/profile.hh> #include <ost/profile.hh> #include <ost/base.hh> -#include <ost/img/alg/stat.hh> #include <ost/img/alg/discrete_shrink.hh> #include "gl_helper.hh" @@ -65,6 +64,7 @@ MapIso::MapIso(const String& name, const img::MapHandle& mh, float level): downsampled_mh_(), mh_(MapIso::DownsampleMap(mh)), octree_(mh_), + stat_calculated_(false), level_(level), normals_calculated_(false), alg_(0), @@ -302,6 +302,24 @@ void MapIso::SetLevel(float l) Scene::Instance().RequestRedraw(); } +void MapIso::CalculateStat() const +{ + mh_.ApplyIP(stat_); + stat_calculated_=true; +} + +float MapIso::GetMinLevel() const +{ + if(!stat_calculated_)CalculateStat(); + return stat_.GetMinimum(); +} + +float MapIso::GetMaxLevel() const +{ + if(!stat_calculated_)CalculateStat(); + return stat_.GetMaximum(); +} + float MapIso::GetLevel() const { return level_; @@ -309,9 +327,8 @@ float MapIso::GetLevel() const float MapIso::GetStdDev() const { - img::alg::Stat stat; - mh_.Apply(stat); - return stat.GetStandardDeviation(); + if(!stat_calculated_)CalculateStat(); + return stat_.GetStandardDeviation(); } img::ImageHandle& MapIso::GetMap() @@ -331,9 +348,8 @@ img::ImageHandle& MapIso::GetDownsampledMap() float MapIso::GetMean() const { - img::alg::Stat stat; - mh_.Apply(stat); - return static_cast<float>(stat.GetMean()); + if(!stat_calculated_)CalculateStat(); + return static_cast<float>(stat_.GetMean()); } void MapIso::SetNSF(float nsf) @@ -348,6 +364,7 @@ void MapIso::ShowDownsampledMap() { if (downsampled_mh_.IsValid()) mh_ = downsampled_mh_; MakeOctreeDirty(); + stat_calculated_ = false; Rebuild(); Scene::Instance().RequestRedraw(); } @@ -357,6 +374,7 @@ void MapIso::ShowOriginalMap() { if (original_mh_.IsValid()) mh_ = original_mh_; MakeOctreeDirty(); + stat_calculated_ = false; Rebuild(); Scene::Instance().RequestRedraw(); } diff --git a/modules/gfx/src/map_iso.hh b/modules/gfx/src/map_iso.hh index 5e45bd82f..ac7ec91e5 100644 --- a/modules/gfx/src/map_iso.hh +++ b/modules/gfx/src/map_iso.hh @@ -26,6 +26,8 @@ #include <boost/shared_ptr.hpp> #include <ost/img/map.hh> +#include <ost/img/alg/stat.hh> + #include <ost/gfx/impl/map_octree.hh> #include "gfx_object.hh" #include "map_iso_prop.hh" @@ -72,6 +74,9 @@ public: /// Will force rebuild of the vertex buffers/indices void SetLevel(float l); + float GetMinLevel() const; + float GetMaxLevel() const; + /// \brief get current isocontouring level float GetLevel() const; @@ -130,6 +135,7 @@ public: bool IfOctreeDirty() const; protected: + void CalculateStat() const; virtual void CustomPreRenderGL(bool flag); static img::ImageHandle DownsampleMap(const img::ImageHandle& mh); @@ -138,6 +144,8 @@ private: img::MapHandle downsampled_mh_; img::MapHandle mh_; impl::MapOctree octree_; + mutable img::alg::Stat stat_; + mutable bool stat_calculated_; float level_; bool normals_calculated_; uint alg_; -- GitLab