Skip to content
Snippets Groups Projects
Commit 53098faa authored by valerio's avatar valerio
Browse files

Preliminary implementation of map downsampling for MapIso

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2107 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent eac6d6ec
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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
......@@ -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_;
};
}}
......
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment