From dec783bcf098314f4503f60cc04db145a310e4c1 Mon Sep 17 00:00:00 2001 From: maxcorsini Date: Mon, 3 Sep 2012 13:50:42 +0000 Subject: [PATCH] add SetByPointers to deal with containers of pointers instead of containers of elements --- vcg/space/index/index2D/spatial_hashing_2D.h | 40 +++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/vcg/space/index/index2D/spatial_hashing_2D.h b/vcg/space/index/index2D/spatial_hashing_2D.h index fdcd6cc5..dc856532 100644 --- a/vcg/space/index/index2D/spatial_hashing_2D.h +++ b/vcg/space/index/index2D/spatial_hashing_2D.h @@ -409,7 +409,7 @@ namespace vcg{ { for(i = _oBegin; i!= _oEnd; ++i) { - (*i).GetBBox(b); + (*i)->GetBBox(b); this->bbox.Add(b); } ///inflate the bb calculated @@ -429,6 +429,44 @@ namespace vcg{ } } + /// Insert a mesh in the grid. + template + void SetByPointers(const OBJITER & _oBegin, const OBJITER & _oEnd, + bool subdivideBox=false,const Box2x &_bbox=Box2x() ) + { + OBJITER i; + Box2x b; + Box2x &bbox = this->bbox; + CoordType &dim = this->dim; + Point2i &siz = this->siz; + CoordType &voxel = this->voxel; + + int _size=(int)std::distance(_oBegin,_oEnd); + if(!_bbox.IsNull()) this->bbox=_bbox; + else + { + for(i = _oBegin; i!= _oEnd; ++i) + { + (*i)->GetBBox(b); + this->bbox.Add(b); + } + ///inflate the bb calculated + bbox.Offset(bbox.Diag()/100.0) ; + } + + dim = bbox.max - bbox.min; + BestDim2D( _size, dim, siz ); + // find voxel size + voxel[0] = dim[0]/siz[0]; + voxel[1] = dim[1]/siz[1]; + cell_size=voxel.Norm(); + + for(i = _oBegin; i!= _oEnd; ++i) + { + Add(*i,subdivideBox); + } + } + ///return the simplexes of the cell that contain p void GridReal( const Point2 & p, CellIterator & first, CellIterator & last ) {