diff --git a/modules/gfx/pymod/export_map.cc b/modules/gfx/pymod/export_map.cc index 6bfc908656f6f7f692a1a116556bd1ecc0d7e1b8..ea334ead8a8e3dc69808af841d26c1fee46d805a 100644 --- a/modules/gfx/pymod/export_map.cc +++ b/modules/gfx/pymod/export_map.cc @@ -47,6 +47,9 @@ void ms_color_by_04(MapSlab *s, const Color& c1, const Color& c2) s->ColorBy(c1,c2); } +bool get_gds() {return MapIso::global_downsampling_flag;} +void set_gds(bool f) {MapIso::global_downsampling_flag=f;} + } // anon ns void export_Map() @@ -82,6 +85,7 @@ void export_Map() .def("SetColor", &MapIso::SetColor) .def("GetColor", &MapIso::GetColor, return_value_policy<copy_const_reference>()) .def("SetDebugOctree", &MapIso::SetDebugOctree) + .add_static_property("global_downsampling_flag",get_gds,set_gds) ; class_<MapSlab, bases<GfxObj>, boost::shared_ptr<MapSlab>, diff --git a/modules/gfx/src/map_iso.cc b/modules/gfx/src/map_iso.cc index 7a2c5160c435badb6bd25267759c6fd9a119ebed..fdcf0a3fe95724e0d5082d144b25835fb2615378 100644 --- a/modules/gfx/src/map_iso.cc +++ b/modules/gfx/src/map_iso.cc @@ -59,6 +59,8 @@ namespace ost { namespace gfx { +bool MapIso::global_downsampling_flag=true; + MapIso::MapIso(const String& name, const img::MapHandle& mh, float level, uint a): GfxObj(name), @@ -71,7 +73,6 @@ MapIso::MapIso(const String& name, const img::MapHandle& mh, histogram_bin_count_(100), level_(level), normals_calculated_(false), - alg_(a), debug_octree_(false), color_(1.0,1.0,1.0), bb_(), @@ -412,6 +413,7 @@ bool MapIso::IsDownsampledMapAvailable() const img::ImageHandle MapIso::DownsampleMap(const img::ImageHandle& mh) { + if(!MapIso::global_downsampling_flag) return mh; uint downsampling_fact = compute_downsampling_fact(mh); img:: ImageHandle ret_mh = mh; if (downsampling_fact != 1) { diff --git a/modules/gfx/src/map_iso.hh b/modules/gfx/src/map_iso.hh index bb47a129c1d0b04d223387dba693fc89031b12a0..cee9025fa6e60598d3a08df3642cf7c4fff8781b 100644 --- a/modules/gfx/src/map_iso.hh +++ b/modules/gfx/src/map_iso.hh @@ -144,6 +144,8 @@ public: /// \brief checks is the octree needs to be rebuilt bool IfOctreeDirty() const; + static bool global_downsampling_flag; + protected: void UpdateRenderParams(); void CalculateStat() const; @@ -163,7 +165,6 @@ private: int histogram_bin_count_; float level_; bool normals_calculated_; - uint alg_; float smoothf_; float min_; float max_; diff --git a/modules/img/alg/src/discrete_shrink.cc b/modules/img/alg/src/discrete_shrink.cc index ba01ae54635d9c4bab555b1772f38f5c43b1129b..6aef59bcfa03c4c6bbd1332d1254916b73a3e465 100644 --- a/modules/img/alg/src/discrete_shrink.cc +++ b/modules/img/alg/src/discrete_shrink.cc @@ -49,7 +49,6 @@ void do_shrink(const ImageStateImpl<T,D>& isi, T& dest, const Extent& inner_ext) T sum(0); Real count=0.0; for(ExtentIterator bit(inner_ext);!bit.AtEnd();++bit) { - LOG_VERBOSE("inner extent point:" << Point(bit)<<","<<isi.GetExtent().Contains(Point(bit))); sum+=isi.Value(bit); count+=1.0; } diff --git a/modules/io/src/img/map_io_dx_handler.cc b/modules/io/src/img/map_io_dx_handler.cc index 4509d327d51187961802658a214d69c8b8bdf245..5ecaab90479a1f878a151ccf3af10e6f2da14bca 100644 --- a/modules/io/src/img/map_io_dx_handler.cc +++ b/modules/io/src/img/map_io_dx_handler.cc @@ -108,9 +108,11 @@ void MapIODxHandler::Import(img::MapHandle& mh, std::istream& infile, const Imag } String line; - int u_size,v_size,w_size; - Real x_orig=0, y_orig=0, z_orig=0; - Real u_spacing=0, v_spacing=0, w_spacing=0; + int u_size=0,v_size=0,w_size=0; + Real x_orig=0.0, y_orig=0.0, z_orig=0.0; + Real u_spacing=1.0, v_spacing=1.0, w_spacing=1.0; + size_t delta_count=0; + Real deltas[][3]={{1.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0}}; int num_gridpoints; img::MapHandle mh2; std::vector<String> tokens; @@ -120,6 +122,7 @@ void MapIODxHandler::Import(img::MapHandle& mh, std::istream& infile, const Imag } // read gridpoints line if (boost::iequals(line.substr(0,35), "object 1 class gridpositions counts")) { + LOG_DEBUG("DXImport: reading gridpoints line [" << line << "]"); boost::split(tokens, line, boost::is_any_of(" "), boost::token_compress_on); int tokens_size = (int)tokens.size(); if(tokens_size < 3) { @@ -137,6 +140,7 @@ void MapIODxHandler::Import(img::MapHandle& mh, std::istream& infile, const Imag } // read grid origin line else if (boost::iequals(line.substr(0,6), "origin")) { + LOG_DEBUG("DXImport: reading origin line [" << line << "]"); boost::split(tokens, line, boost::is_any_of(" "), boost::token_compress_on); int tokens_size = (int)tokens.size(); if(tokens_size < 3) { @@ -154,42 +158,24 @@ void MapIODxHandler::Import(img::MapHandle& mh, std::istream& infile, const Imag } // read grid spacing line else if (boost::iequals(line.substr(0,5), "delta")) { - boost::split(tokens, line, boost::is_any_of(" "), boost::token_compress_on); - int tokens_size = (int)tokens.size(); - if(tokens_size < 3) { - String msg="Bad spacing line: Can't read spacing of grid points"; + LOG_DEBUG("DXImport: reading delta line [" << line << "]"); + boost::split(tokens, line, boost::is_any_of("\t "), boost::token_compress_on); + if(tokens.size() < 4) { + String msg="DXImport: expected delta line with 3 floats"; throw IOException(msg); } try { - Real tmp; - tmp = boost::lexical_cast<Real>(boost::trim_copy(tokens[tokens_size-3])); - if(tmp != 0) { - u_spacing=tmp; - } else if(tmp == 0) { - tmp = boost::lexical_cast<Real>(boost::trim_copy(tokens[tokens_size-2])); - if(tmp != 0) { - v_spacing=tmp; - } else if(tmp == 0) { - tmp = boost::lexical_cast<Real>(boost::trim_copy(tokens[tokens_size-1])); - if(tmp != 0) { - w_spacing=tmp; - } else { - String msg="Bad spacing line: Can't read spacing of grid points"; - throw IOException(msg); - } + if(delta_count<3) { + for(size_t i=0;i<3;++i) { + deltas[delta_count][i] = boost::lexical_cast<Real>(tokens[i+1]); } + ++delta_count; } } catch(boost::bad_lexical_cast&) { - format fmer= format("Bad spacing line: Can't convert String of origin" - " '%s' to Real constant.") % line; + format fmer= format("Bad spacing line: Can't convert String of delta" + " '%s' to Real constants.") % line; throw IOException(fmer.str()); } - // create map handle - if(u_spacing != 0 && v_spacing != 0 && w_spacing != 0) { - mh2 = CreateMap(img::Size(u_size,v_size,w_size)); - mh2.SetAbsoluteOrigin(geom::Vec3(x_orig, y_orig, z_orig)); - mh2.SetSpatialSampling(geom::Vec3(u_spacing,v_spacing,w_spacing)); - } } // read number of data points if (boost::iequals(line.substr(0,25), "object 3 class array type")) { @@ -207,6 +193,25 @@ void MapIODxHandler::Import(img::MapHandle& mh, std::istream& infile, const Imag throw IOException(fmer.str()); } + // at this point enough info should be available to create map + if(u_size>1e5 || v_size>1e5 || w_size>1e5) { + format fmer=format("DXImport: nonsense mapsize read (%d %d %d)") % u_size % v_size % w_size; + throw IOException(fmer.str()); + } + LOG_DEBUG("DXImport: creating map of size " << img::Size(u_size,v_size,w_size)); + LOG_DEBUG(" at absolute origin " << geom::Vec3(x_orig, y_orig, z_orig)); + mh2 = CreateMap(img::Size(u_size,v_size,w_size)); + mh2.SetAbsoluteOrigin(geom::Vec3(x_orig, y_orig, z_orig)); + if(delta_count==3) { + u_spacing=deltas[0][0]; + v_spacing=deltas[1][1]; + w_spacing=deltas[2][2]; + LOG_DEBUG(" and spatial sampling " << geom::Vec3(u_spacing,v_spacing,w_spacing)); + mh2.SetSpatialSampling(geom::Vec3(u_spacing,v_spacing,w_spacing)); + } + + // and read in the values + // TODO: this is glacially slow Real value=0; for(int i=0; i<num_gridpoints; i+=3) { std::getline(infile,line); @@ -226,6 +231,7 @@ void MapIODxHandler::Import(img::MapHandle& mh, std::istream& infile, const Imag mh.Swap(mh2); } + void MapIODxHandler::Export(const img::MapHandle& mh2, const bf::path& loc,const ImageFormatBase& formatstruct) const {