diff --git a/modules/gfx/pymod/export_map.cc b/modules/gfx/pymod/export_map.cc index f4957efb4f2847c0d84f2facf2eca9f7c82343ea..4fd9ae0ece7fdfa0c4e2706b61b3f089b1514973 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 9acb420c4703c86072b40924d9b1073858c166ce..a6bbdfa7f1e48a940ad013aa5b73d21d715abf92 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 5e45bd82f3881227634b63463c6a8c16253cdfc3..ac7ec91e5d13fa1e741f711a9f6f0dd2310930df 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_;