diff --git a/modules/geom/src/aligned_cuboid.hh b/modules/geom/src/aligned_cuboid.hh index 8937ce4c30ded96badc0e5105cf030cb7826e9a9..9d2298942f8f791942ccabd556ced21617951d70 100644 --- a/modules/geom/src/aligned_cuboid.hh +++ b/modules/geom/src/aligned_cuboid.hh @@ -34,6 +34,7 @@ namespace geom { /// For an arbitrarily oriented cuboid see \ref Cuboid class DLLEXPORT_OST_GEOM AlignedCuboid { public: + AlignedCuboid() :min_(), max_() {} AlignedCuboid(const Vec3& mmin, const Vec3& mmax) :min_(mmin), max_(mmax) {} Vec3 GetSize() const {return max_-min_;} diff --git a/modules/gfx/src/map_iso.cc b/modules/gfx/src/map_iso.cc index 0a575b192332811b507cafb45beb0fed57c30bb9..8e685e524215dabd1ff12b2abe28965829c2d7b8 100644 --- a/modules/gfx/src/map_iso.cc +++ b/modules/gfx/src/map_iso.cc @@ -73,7 +73,9 @@ MapIso::MapIso(const String& name, const img::MapHandle& mh, normals_calculated_(false), alg_(a), debug_octree_(false), - color_(1.0,1.0,1.0) + color_(1.0,1.0,1.0), + bb_(), + recalc_bb_(true) { // TODO replace with def mat for this gfx obj type if (mh_ != original_mh_) { @@ -93,15 +95,17 @@ MapIso::MapIso(const String& name, const img::MapHandle& mh, geom::AlignedCuboid MapIso::GetBoundingBox() const { - geom::Vec3 minc = mh_.IndexToCoord(mh_.GetExtent().GetStart()); - geom::Vec3 maxc = mh_.IndexToCoord(mh_.GetExtent().GetEnd()); - return geom::AlignedCuboid(minc,maxc); + if(recalc_bb_) { + bb_=va_.GetBoundingBox(); + recalc_bb_=false; + } + return bb_; } geom::Vec3 MapIso::GetCenter() const { - geom::Vec3 nrvo = mh_.IndexToCoord(mh_.GetExtent().GetCenter()); - return nrvo; + if(recalc_bb_) GetBoundingBox(); + return bb_.GetCenter(); } void MapIso::UpdateRenderParams() @@ -242,7 +246,7 @@ void MapIso::OnInput(const InputEvent& e) void MapIso::Rebuild() { if (mh_.IsFrequency() == true){ - throw Error("Error: Map not in real space. Cannot create of this map"); + throw Error("Error: Map not in real space"); } if (octree_.IsMapManageable(mh_) == false) { throw Error("Error: Map is too big for visualization"); @@ -264,6 +268,7 @@ void MapIso::Rebuild() va_.DrawNormals(true); #endif this->UpdateRenderParams(); + recalc_bb_=true; } void MapIso::SetLevel(float l) diff --git a/modules/gfx/src/map_iso.hh b/modules/gfx/src/map_iso.hh index 0791d40eb9bf84868f333c0e07b9be0dad48f2da..814dfa756399c592ddf3df72d3173e5c958a73c6 100644 --- a/modules/gfx/src/map_iso.hh +++ b/modules/gfx/src/map_iso.hh @@ -53,8 +53,10 @@ class DLLEXPORT_OST_GFX MapIso: public GfxObj { public: MapIso(const String& name, const img::MapHandle& mh,float level, uint a=0); + /// returns bounding box of iso-contour object, not overall map virtual geom::AlignedCuboid GetBoundingBox() const; - + + /// returns center of iso-contour object, not overall map virtual geom::Vec3 GetCenter() const; virtual void CustomRenderGL(RenderPass pass); @@ -150,26 +152,28 @@ protected: static img::ImageHandle DownsampleMap(const img::ImageHandle& mh); private: - img::MapHandle original_mh_; - img::MapHandle downsampled_mh_; - img::MapHandle mh_; - impl::MapOctree octree_; - mutable img::alg::Stat stat_; - mutable bool stat_calculated_; - 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_; + img::MapHandle original_mh_; + img::MapHandle downsampled_mh_; + img::MapHandle mh_; + impl::MapOctree octree_; + mutable img::alg::Stat stat_; + mutable bool stat_calculated_; + 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_; + mutable geom::AlignedCuboid bb_; + mutable bool recalc_bb_; }; }} diff --git a/modules/gfx/src/vertex_array.cc b/modules/gfx/src/vertex_array.cc index ab6db586b8f97c96f963da4c4314fe0f2f17f657..c1c53d57fa29110368a7b1a5a2da28fb2c7c5612 100644 --- a/modules/gfx/src/vertex_array.cc +++ b/modules/gfx/src/vertex_array.cc @@ -1413,4 +1413,24 @@ void IndexedVertexArray::draw_line_halo(bool use_buff) glLineWidth(line_width_); } +geom::AlignedCuboid IndexedVertexArray::GetBoundingBox() const +{ + if(entry_list_.empty()) { + return geom::AlignedCuboid(geom::Vec3(0,0,0),geom::Vec3(0,0,0)); + } else { + geom::Vec3 minc(std::numeric_limits<float>::max(), + std::numeric_limits<float>::max(), + std::numeric_limits<float>::max()); + geom::Vec3 maxc(-std::numeric_limits<float>::max(), + -std::numeric_limits<float>::max(), + -std::numeric_limits<float>::max()); + for(EntryList::const_iterator it=entry_list_.begin();it!=entry_list_.end();++it) { + geom::Vec3 p(it->v[0],it->v[1],it->v[2]); + minc=geom::Min(minc,p); + maxc=geom::Max(maxc,p); + } + return geom::AlignedCuboid(minc-1.0,maxc+1.0); + } +} + }} // ns diff --git a/modules/gfx/src/vertex_array.hh b/modules/gfx/src/vertex_array.hh index b7dcce4cd2bf16148517019312fc4f4d4e827b8c..1a945f7cf6094738b0a539bfad19d72ee1767d39 100644 --- a/modules/gfx/src/vertex_array.hh +++ b/modules/gfx/src/vertex_array.hh @@ -32,6 +32,7 @@ #include <ost/log.hh> #include <ost/geom/geom.hh> +#include <ost/geom/aligned_cuboid.hh> #include "color.hh" @@ -182,7 +183,9 @@ class DLLEXPORT_OST_GFX IndexedVertexArray { // experimental, do not use void SmoothVertices(float smoothf); + /// experimental void UseTex(bool b) {use_tex_=b;} + /// experimental uint& TexID() {return tex_id_;} const EntryList& GetEntries() const {return entry_list_;} @@ -190,6 +193,9 @@ class DLLEXPORT_OST_GFX IndexedVertexArray { const IndexList& GetTriIndices() const {return tri_index_list_;} const IndexList& GetLineIndices() const {return line_index_list_;} + /// return min/max of vertex entries - this call is not cached! + geom::AlignedCuboid GetBoundingBox() const; + private: bool initialized_;