diff --git a/modules/base/pymod/wrap_base.cc b/modules/base/pymod/wrap_base.cc index 3ac10d7e6f6a782bea3bd40f353362f0d1bc896c..728cb5ab68cda8b8647f9afafbb1be84ecad3718 100644 --- a/modules/base/pymod/wrap_base.cc +++ b/modules/base/pymod/wrap_base.cc @@ -44,5 +44,9 @@ BOOST_PYTHON_MODULE(_base) ; class_<std::vector<String> >("StringList", init<>()) .def(vector_indexing_suite<std::vector<String> >()) - ; + ; + typedef std::vector<int> IntList; + class_<std::vector<int> >("IntList", init<>()) + .def(vector_indexing_suite<std::vector<int> >()) + ; } diff --git a/modules/gfx/pymod/export_map.cc b/modules/gfx/pymod/export_map.cc index 4fd9ae0ece7fdfa0c4e2706b61b3f089b1514973..7ba389b904f3ede92584241eb1890bce10833387 100644 --- a/modules/gfx/pymod/export_map.cc +++ b/modules/gfx/pymod/export_map.cc @@ -17,6 +17,7 @@ // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA //------------------------------------------------------------------------------ #include <boost/python.hpp> +#include <boost/python/suite/indexing/vector_indexing_suite.hpp> using namespace boost::python; #include <ost/gfx/map_iso.hh> @@ -63,6 +64,10 @@ void export_Map() .def("GetMinLevel",&MapIso::GetMinLevel) .def("GetMaxLevel",&MapIso::GetMaxLevel) .def("GetMean", &MapIso::GetMean) + .def("GetHistogram",&MapIso::GetHistogram) + .def("SetHistogramBinCount",&MapIso::SetHistogramBinCount) + .def("GetHistogramBinCount",&MapIso::GetHistogramBinCount) + .def("GetMap", &MapIso::GetMap,return_value_policy<reference_existing_object>()) .def("GetOriginalMap", &MapIso::GetOriginalMap,return_value_policy<reference_existing_object>()) .def("GetDownsampledMap", &MapIso::GetDownsampledMap,return_value_policy<reference_existing_object>()) diff --git a/modules/gfx/src/map_iso.cc b/modules/gfx/src/map_iso.cc index a6bbdfa7f1e48a940ad013aa5b73d21d715abf92..06183729ac58cbdbb5fd054858addd2795314a0f 100644 --- a/modules/gfx/src/map_iso.cc +++ b/modules/gfx/src/map_iso.cc @@ -25,6 +25,7 @@ #include <ost/profile.hh> #include <ost/base.hh> #include <ost/img/alg/discrete_shrink.hh> +#include <ost/img/alg/histogram.hh> #include "gl_helper.hh" #include "glext_include.hh" @@ -65,6 +66,8 @@ MapIso::MapIso(const String& name, const img::MapHandle& mh, float level): mh_(MapIso::DownsampleMap(mh)), octree_(mh_), stat_calculated_(false), + histogram_calculated_(false), + histogram_bin_count_(100), level_(level), normals_calculated_(false), alg_(0), @@ -95,6 +98,9 @@ MapIso::MapIso(const String& name, const img::MapHandle& mh, downsampled_mh_(), mh_(MapIso::DownsampleMap(mh)), octree_(mh_), + stat_calculated_(false), + histogram_calculated_(false), + histogram_bin_count_(100), level_(level), normals_calculated_(false), alg_(a), @@ -308,6 +314,13 @@ void MapIso::CalculateStat() const stat_calculated_=true; } +void MapIso::CalculateHistogram() const +{ + histogram_ = img::alg::HistogramBase(histogram_bin_count_, this->GetMinLevel(), this->GetMaxLevel()); + mh_.ApplyIP(histogram_); + histogram_calculated_=true; +} + float MapIso::GetMinLevel() const { if(!stat_calculated_)CalculateStat(); @@ -331,6 +344,25 @@ float MapIso::GetStdDev() const return stat_.GetStandardDeviation(); } +void MapIso::SetHistogramBinCount(int count) +{ + if (count > 0){ + histogram_bin_count_ = count; + histogram_calculated_ = false; + } +} + +int MapIso::GetHistogramBinCount() const +{ + return histogram_bin_count_; +} + +std::vector<int> MapIso::GetHistogram() const +{ + if(!histogram_calculated_)CalculateHistogram(); + return histogram_.GetBins(); +} + img::ImageHandle& MapIso::GetMap() { return mh_; @@ -365,6 +397,7 @@ void MapIso::ShowDownsampledMap() if (downsampled_mh_.IsValid()) mh_ = downsampled_mh_; MakeOctreeDirty(); stat_calculated_ = false; + histogram_calculated_ = false; Rebuild(); Scene::Instance().RequestRedraw(); } @@ -375,6 +408,7 @@ void MapIso::ShowOriginalMap() if (original_mh_.IsValid()) mh_ = original_mh_; MakeOctreeDirty(); stat_calculated_ = false; + histogram_calculated_ = false; Rebuild(); Scene::Instance().RequestRedraw(); } diff --git a/modules/gfx/src/map_iso.hh b/modules/gfx/src/map_iso.hh index ac7ec91e5d13fa1e741f711a9f6f0dd2310930df..9ed928632c301b6d500b604babc085f24ce72e08 100644 --- a/modules/gfx/src/map_iso.hh +++ b/modules/gfx/src/map_iso.hh @@ -27,6 +27,7 @@ #include <ost/img/map.hh> #include <ost/img/alg/stat.hh> +#include <ost/img/alg/histogram.hh> #include <ost/gfx/impl/map_octree.hh> #include "gfx_object.hh" @@ -86,6 +87,16 @@ public: /// \brief get std dev of map. float GetStdDev() const; + + /// \brief get histogram + std::vector<int> GetHistogram() const; + + /// \brief set Histogram bin count + void SetHistogramBinCount(int count); + + /// \brief get Histogram bin count + int GetHistogramBinCount() const; + /// \brief get the map handle of the currently displayed map // The following is a hack. For the DataViewer I need to pass a reference to an ImagHandle // that never goes out of scope, so I get a reference from here @@ -136,27 +147,31 @@ public: protected: void CalculateStat() const; + void CalculateHistogram() const; virtual void CustomPreRenderGL(bool flag); static img::ImageHandle DownsampleMap(const img::ImageHandle& mh); private: - img::MapHandle original_mh_; - img::MapHandle downsampled_mh_; - img::MapHandle mh_; - impl::MapOctree octree_; + img::MapHandle original_mh_; + 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_; - float smoothf_; - float min_; - float max_; - float std_dev_; - float min_max_; - bool debug_octree_; - Color color_; - bool dirty_octree_; + mutable img::alg::Histogram histogram_; + mutable bool histogram_calculated_; + int histogram_bin_count_; + float level_; + bool normals_calculated_; + uint alg_; + float smoothf_; + float min_; + float max_; + float std_dev_; + float min_max_; + bool debug_octree_; + Color color_; + bool dirty_octree_; }; }} diff --git a/modules/img/alg/src/histogram.hh b/modules/img/alg/src/histogram.hh index f974247da64b4f51f1c8d5d87afc1e59b608f022..7805d40fcb86740c0d85eadc35d97111f17eed75 100644 --- a/modules/img/alg/src/histogram.hh +++ b/modules/img/alg/src/histogram.hh @@ -17,6 +17,8 @@ // along with this library; if not, write to the Free Software Foundation, Inc., // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA //------------------------------------------------------------------------------ +#ifndef OST_IMG_ALG_HISTOGRAM_HH +#define OST_IMG_ALG_HISTOGRAM_HH /* Author: Ansgar Philippsen @@ -75,3 +77,5 @@ typedef ImageStateNonModAlgorithm<HistogramBase> Histogram; OST_IMG_ALG_EXPLICIT_INST_DECL(class,ImageStateNonModAlgorithm<alg::HistogramBase>) }} // namespaces + +#endif