diff --git a/vcg/space/index/grid_static_ptr.h b/vcg/space/index/grid_static_ptr.h index e9e10140..a85c8749 100644 --- a/vcg/space/index/grid_static_ptr.h +++ b/vcg/space/index/grid_static_ptr.h @@ -246,16 +246,15 @@ namespace vcg { { Box3 _bbox; Box3 b; - OBJITER i; - for(i = _oBegin; i!= _oEnd; ++i) + for(OBJITER i = _oBegin; i!= _oEnd; ++i) { (*i).GetBBox(b); _bbox.Add(b); } - ///inflate the bb calculated if(_size ==0) _size=(int)std::distance(_oBegin,_oEnd); - + + ///inflate the bb calculated ScalarType infl=_bbox.Diag()/_size; _bbox.min-=vcg::Point3(infl,infl,infl); _bbox.max+=vcg::Point3(infl,infl,infl); @@ -270,28 +269,28 @@ namespace vcg { // Note that the bbox must be already 'inflated' so to be sure that no object will fall on the border of the grid. template - inline void Set(const OBJITER & _oBegin, const OBJITER & _oEnd, const Box3x &_bbox, FLT radius) + inline void SetWithRadius(const OBJITER & _oBegin, const OBJITER & _oEnd, FLT _cellRadius) { - Point3i _siz; - Point3 _dim = _bbox.max - _bbox.min; - _dim/=radius; - assert(_dim[0]>0 && _dim[1]>0 && _dim[2]>0 ); - _siz[0] = (int)ceil(_dim[0]); - _siz[1] = (int)ceil(_dim[1]); - _siz[2] = (int)ceil(_dim[2]); + Box3 _bbox; + Box3 b; + for(OBJITER i = _oBegin; i!= _oEnd; ++i) + { + (*i).GetBBox(b); + _bbox.Add(b); + } - Point3 offset=Point3::Construct(_siz); - offset*=radius; - offset -= (_bbox.max - _bbox.min); - offset /=2; - - assert( offset[0]>=0 && offset[1]>=0 && offset[2]>=0 ); - - Box3x bb = _bbox; - bb.min -= offset; - bb.max += offset; - - Set(_oBegin,_oEnd, bb,_siz); + _bbox.min-=vcg::Point3(_cellRadius,_cellRadius,_cellRadius); + _bbox.max+=vcg::Point3(_cellRadius,_cellRadius,_cellRadius); + + Point3i _siz; + Point3 _dim = _bbox.max - _bbox.min; + _dim/=_cellRadius; + assert(_dim[0]>0 && _dim[1]>0 && _dim[2]>0 ); + _siz[0] = (int)ceil(_dim[0]); + _siz[1] = (int)ceil(_dim[1]); + _siz[2] = (int)ceil(_dim[2]); + + Set(_oBegin,_oEnd, _bbox,_siz); } @@ -312,6 +311,8 @@ namespace vcg { Set(_oBegin,_oEnd,_bbox,_siz); } + + // This is the REAL LOW LEVEL function template inline void Set(const OBJITER & _oBegin, const OBJITER & _oEnd, const Box3x &_bbox, Point3i _siz)