From 53098faa1a82e3ef220a8df8e7d362491035352e Mon Sep 17 00:00:00 2001 From: valerio <valerio@5a81b35b-ba03-0410-adc8-b2c5c5119f08> Date: Thu, 22 Apr 2010 15:13:37 +0000 Subject: [PATCH] Preliminary implementation of map downsampling for MapIso git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2107 5a81b35b-ba03-0410-adc8-b2c5c5119f08 --- modules/gfx/pymod/export_map.cc | 1 + modules/gfx/src/map_iso.cc | 46 ++++++++++++++++++++++++------ modules/gfx/src/map_iso.hh | 13 +++++++-- modules/gui/src/scene_selection.cc | 2 +- 4 files changed, 50 insertions(+), 12 deletions(-) diff --git a/modules/gfx/pymod/export_map.cc b/modules/gfx/pymod/export_map.cc index 62dcb4ca7..cd88c771b 100644 --- a/modules/gfx/pymod/export_map.cc +++ b/modules/gfx/pymod/export_map.cc @@ -56,6 +56,7 @@ void export_Map() .def("GetLevel",&MapIso::GetLevel) .def("GetMean", &MapIso::GetMean) .def("GetMap", &MapIso::GetMap,return_value_policy<reference_existing_object>()) + .def("GetOriginalMap", &MapIso::GetOriginalMap,return_value_policy<reference_existing_object>()) .def("Rebuild", &MapIso::Rebuild) .def("SetNSF",&MapIso::SetNSF) .def("SetColor", &MapIso::SetColor) diff --git a/modules/gfx/src/map_iso.cc b/modules/gfx/src/map_iso.cc index a383bd737..5e340622b 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/stat.hh> +#include <ost/img/alg/discrete_shrink.hh> #include "gl_helper.hh" #include "glext_include.hh" @@ -40,6 +41,19 @@ #include "shader.hh" #endif +namespace { + +int compute_downsampling_fact(const ost::img::ImageHandle& mh) +{ + ost::img::Extent ext = mh.GetExtent(); + int max = ext.GetWidth(); + if (ext.GetHeight() > ext.GetWidth() && ext.GetHeight() > ext.GetDepth()) max=ext.GetHeight(); + if (ext.GetDepth() > ext.GetWidth() && ext.GetDepth() > ext.GetHeight()) max=ext.GetDepth(); + int fact = std::ceil(static_cast<float>(max)/64.0); + return fact; +} + +} namespace ost { @@ -47,17 +61,17 @@ namespace gfx { MapIso::MapIso(const String& name, const img::MapHandle& mh, float level): GfxObj(name), - mh_(mh), - octree_(mh), + original_mh_(mh), + downsampled_mh_(MapIso::DownsampleMap(mh)), + mh_(downsampled_mh_), + octree_(mh_), level_(level), normals_calculated_(false), alg_(0), smoothf_(0.2), debug_octree_(false), - color_(Color::WHITE) + color_(Color::GREY) { - // TODO replace with def mat for this gfx obj type - SetMat(0.0,1.0,0.1,32.0); mol::Transform tf=this->GetTF(); tf.SetCenter(this->GetCenter()); @@ -69,13 +83,15 @@ MapIso::MapIso(const String& name, const img::MapHandle& mh, float level): MapIso::MapIso(const String& name, const img::MapHandle& mh, float level, uint a): GfxObj(name), - mh_(mh), - octree_(mh), + original_mh_(mh), + downsampled_mh_(MapIso::DownsampleMap(mh)), + mh_(downsampled_mh_), + octree_(mh_), level_(level), normals_calculated_(false), alg_(a), debug_octree_(false), - color_(Color::WHITE) + color_(Color::GREY) { // TODO replace with def mat for this gfx obj type SetMat(0.0,1.0,0.1,32.0); @@ -278,6 +294,10 @@ img::ImageHandle& MapIso::GetMap() return mh_; } +img::ImageHandle& MapIso::GetOriginalMap() +{ + return original_mh_; +} float MapIso::GetMean() const { @@ -293,5 +313,15 @@ void MapIso::SetNSF(float nsf) Scene::Instance().RequestRedraw(); } +img::ImageHandle MapIso::DownsampleMap(const img::ImageHandle& mh) +{ + uint downsampling_fact = compute_downsampling_fact(mh); + img:: ImageHandle ret_mh = mh; + if (downsampling_fact != 1) { + img::alg::DiscreteShrink shrink_alg(img::Size(downsampling_fact,downsampling_fact,downsampling_fact)); + ret_mh = mh.Apply(shrink_alg); + } + return ret_mh; +} }} // ns diff --git a/modules/gfx/src/map_iso.hh b/modules/gfx/src/map_iso.hh index d69cfe760..87eda29a9 100644 --- a/modules/gfx/src/map_iso.hh +++ b/modules/gfx/src/map_iso.hh @@ -69,18 +69,23 @@ public: /// \brief get current isocontouring level float GetLevel() const; - + /// \brief get mean value of map float GetMean() const; /// \brief get std dev of map. float GetStdDev() const; - /// \brief get the map handle + /// \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 img::ImageHandle& GetMap(); + /// \brief get the map handle of the original 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 + img::ImageHandle& GetOriginalMap(); + /// \brief set color /// /// By default, the color is white. @@ -97,8 +102,11 @@ public: void SetDebugOctree(bool flag) { debug_octree_=flag; } protected: 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_; float level_; @@ -111,7 +119,6 @@ private: float min_max_; bool debug_octree_; Color color_; - }; }} diff --git a/modules/gui/src/scene_selection.cc b/modules/gui/src/scene_selection.cc index 5f792bf56..eb92c848e 100644 --- a/modules/gui/src/scene_selection.cc +++ b/modules/gui/src/scene_selection.cc @@ -143,7 +143,7 @@ void SceneSelection::ViewDensitySlices() { // The following is a hack. I need to pass a reference to an ImagHandle // that never goes out of scope, so I get a reference from the MapIso using // GetMap and pass it to the CreateDataViewer - img::gui::DataViewer* dv = GostyApp::Instance()->CreateDataViewer(obj->GetMap()); + img::gui::DataViewer* dv = GostyApp::Instance()->CreateDataViewer(obj->GetOriginalMap()); MainArea* ma = GostyApp::Instance()->GetPerspective()->GetMainArea(); ma->AddWidget(QString(obj->GetName().c_str()), dv) ; dv->show(); -- GitLab