corrected bug on Set Function .... bbox must be exetended in order to have'nt any object on his borde
This commit is contained in:
parent
f0724dd9e9
commit
a3d7b98a34
|
@ -24,6 +24,9 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.29 2005/10/03 13:57:56 pietroni
|
||||||
|
added GetInSphere and GetInBox functions
|
||||||
|
|
||||||
Revision 1.28 2005/10/02 23:15:26 cignoni
|
Revision 1.28 2005/10/02 23:15:26 cignoni
|
||||||
Inveted the boolean sign of an assert in Grid()
|
Inveted the boolean sign of an assert in Grid()
|
||||||
|
|
||||||
|
@ -33,9 +36,9 @@ Added possibility of setting BBox explicitly in Set(...)
|
||||||
|
|
||||||
Revision 1.26 2005/09/30 13:15:21 pietroni
|
Revision 1.26 2005/09/30 13:15:21 pietroni
|
||||||
added wrapping to functions defined in GridClosest:
|
added wrapping to functions defined in GridClosest:
|
||||||
- GetClosest
|
- GetClosest
|
||||||
- GetKClosest
|
- GetKClosest
|
||||||
- DoRay
|
- DoRay
|
||||||
|
|
||||||
Revision 1.25 2005/09/21 09:22:51 pietroni
|
Revision 1.25 2005/09/21 09:22:51 pietroni
|
||||||
removed closest functions. Closest function is now on index\\Closest.h
|
removed closest functions. Closest function is now on index\\Closest.h
|
||||||
|
@ -260,15 +263,15 @@ namespace vcg {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////
|
|
||||||
// Official access functions
|
|
||||||
////////////////
|
////////////////
|
||||||
/// BY CELL
|
// Official access functions
|
||||||
Cell* Grid(const int i) {
|
////////////////
|
||||||
|
/// BY CELL
|
||||||
|
Cell* Grid(const int i) {
|
||||||
return &grid[i];
|
return &grid[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
void Grid( const Cell* g, Cell & first, Cell & last )
|
void Grid( const Cell* g, Cell & first, Cell & last )
|
||||||
{
|
{
|
||||||
first = *g;
|
first = *g;
|
||||||
last = *(g+1);
|
last = *(g+1);
|
||||||
|
@ -278,25 +281,25 @@ namespace vcg {
|
||||||
inline Cell* Grid( const int x, const int y, const int z )
|
inline Cell* Grid( const int x, const int y, const int z )
|
||||||
{
|
{
|
||||||
assert(!( x<0 || x>=siz[0] || y<0 || y>=siz[1] || z<0 || z>=siz[2] ));
|
assert(!( x<0 || x>=siz[0] || y<0 || y>=siz[1] || z<0 || z>=siz[2] ));
|
||||||
assert(grid.size()>0);
|
assert(grid.size()>0);
|
||||||
return &*grid.begin() + ( x+siz[0]*(y+siz[1]*z) );
|
return &*grid.begin() + ( x+siz[0]*(y+siz[1]*z) );
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Cell* Grid( const Point3i &pi)
|
inline Cell* Grid( const Point3i &pi)
|
||||||
{
|
|
||||||
return Grid(pi[0],pi[1],pi[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Grid( const int x, const int y, const int z, Cell & first, Cell & last )
|
|
||||||
{
|
|
||||||
Cell* g = Grid(x,y,z);
|
|
||||||
first = *g;
|
|
||||||
last = *(g+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Grid( const Point3d & p, Cell & first, Cell & last )
|
|
||||||
{
|
{
|
||||||
Cell* g = Grid(GridP(p));
|
return Grid(pi[0],pi[1],pi[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Grid( const int x, const int y, const int z, Cell & first, Cell & last )
|
||||||
|
{
|
||||||
|
Cell* g = Grid(x,y,z);
|
||||||
|
first = *g;
|
||||||
|
last = *(g+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Grid( const Point3d & p, Cell & first, Cell & last )
|
||||||
|
{
|
||||||
|
Cell* g = Grid(GridP(p));
|
||||||
|
|
||||||
first = *g;
|
first = *g;
|
||||||
last = *(g+1);
|
last = *(g+1);
|
||||||
|
@ -306,7 +309,7 @@ namespace vcg {
|
||||||
/// Set the bounding box of the grid
|
/// Set the bounding box of the grid
|
||||||
///We need some extra space for numerical precision.
|
///We need some extra space for numerical precision.
|
||||||
template <class Box3Type>
|
template <class Box3Type>
|
||||||
void SetBBox( const Box3Type & b )
|
void SetBBox( const Box3Type & b )
|
||||||
{
|
{
|
||||||
bbox.Import( b );
|
bbox.Import( b );
|
||||||
ScalarType t = bbox.Diag()/100.0;
|
ScalarType t = bbox.Diag()/100.0;
|
||||||
|
@ -342,83 +345,91 @@ namespace vcg {
|
||||||
|
|
||||||
/// Insert a mesh in the grid
|
/// Insert a mesh in the grid
|
||||||
template <class OBJITER>
|
template <class OBJITER>
|
||||||
void Set(const OBJITER & _oBegin, const OBJITER & _oEnd, const Box3x &_bbox=Box3x() )
|
void Set(const OBJITER & _oBegin, const OBJITER & _oEnd, const Box3x &_bbox=Box3x() )
|
||||||
{
|
{
|
||||||
OBJITER i;
|
OBJITER i;
|
||||||
Box3<FLT> b;
|
Box3<FLT> b;
|
||||||
|
|
||||||
if(!_bbox.IsNull()) bbox=_bbox;
|
|
||||||
else
|
|
||||||
for(i = _oBegin; i!= _oEnd; ++i)
|
|
||||||
{
|
|
||||||
(*i).GetBBox(b);
|
|
||||||
bbox.Add(b);
|
|
||||||
}
|
|
||||||
int _size=std::distance<OBJITER>(_oBegin,_oEnd);
|
int _size=std::distance<OBJITER>(_oBegin,_oEnd);
|
||||||
dim = bbox.max - bbox.min;
|
if(!_bbox.IsNull())
|
||||||
BestDim( _size, dim, siz );
|
bbox=_bbox;
|
||||||
// find voxel size
|
else
|
||||||
voxel[0] = dim[0]/siz[0];
|
|
||||||
voxel[1] = dim[1]/siz[1];
|
|
||||||
voxel[2] = dim[2]/siz[2];
|
|
||||||
|
|
||||||
|
|
||||||
// "Alloca" la griglia: +1 per la sentinella
|
|
||||||
grid.resize( siz[0]*siz[1]*siz[2]+1 );
|
|
||||||
|
|
||||||
// Ciclo inserimento dei tetraedri: creazione link
|
|
||||||
links.clear();
|
|
||||||
for(i=_oBegin; i!=_oEnd; ++i)
|
|
||||||
{
|
{
|
||||||
Box3x bb; // Boundig box del tetraedro corrente
|
for(i = _oBegin; i!= _oEnd; ++i)
|
||||||
(*i).GetBBox(bb);
|
|
||||||
bb.Intersect(bbox);
|
|
||||||
if(! bb.IsNull() )
|
|
||||||
{
|
{
|
||||||
|
(*i).GetBBox(b);
|
||||||
|
bbox.Add(b);
|
||||||
|
|
||||||
Box3i ib; // Boundig box in voxels
|
}
|
||||||
BoxToIBox( bb,ib );
|
///inflate the bb calculated
|
||||||
int x,y,z;
|
ScalarType infl=bbox.Diag()/_size;
|
||||||
for(z=ib.min[2];z<=ib.max[2];++z)
|
bbox.min-=vcg::Point3d(infl,infl,infl);
|
||||||
|
bbox.max+=vcg::Point3d(infl,infl,infl);
|
||||||
|
}
|
||||||
|
|
||||||
|
dim = bbox.max - bbox.min;
|
||||||
|
BestDim( _size, dim, siz );
|
||||||
|
// find voxel size
|
||||||
|
voxel[0] = dim[0]/siz[0];
|
||||||
|
voxel[1] = dim[1]/siz[1];
|
||||||
|
voxel[2] = dim[2]/siz[2];
|
||||||
|
|
||||||
|
|
||||||
|
// "Alloca" la griglia: +1 per la sentinella
|
||||||
|
grid.resize( siz[0]*siz[1]*siz[2]+1 );
|
||||||
|
|
||||||
|
// Ciclo inserimento dei tetraedri: creazione link
|
||||||
|
links.clear();
|
||||||
|
for(i=_oBegin; i!=_oEnd; ++i)
|
||||||
|
{
|
||||||
|
Box3x bb; // Boundig box del tetraedro corrente
|
||||||
|
(*i).GetBBox(bb);
|
||||||
|
bb.Intersect(bbox);
|
||||||
|
if(! bb.IsNull() )
|
||||||
{
|
{
|
||||||
int bz = z*siz[1];
|
|
||||||
for(y=ib.min[1];y<=ib.max[1];++y)
|
Box3i ib; // Boundig box in voxels
|
||||||
|
BoxToIBox( bb,ib );
|
||||||
|
int x,y,z;
|
||||||
|
for(z=ib.min[2];z<=ib.max[2];++z)
|
||||||
{
|
{
|
||||||
int by = (y+bz)*siz[0];
|
int bz = z*siz[1];
|
||||||
for(x=ib.min[0];x<=ib.max[0];++x)
|
for(y=ib.min[1];y<=ib.max[1];++y)
|
||||||
// Inserire calcolo cella corrente
|
{
|
||||||
// if( pt->Intersect( ... )
|
int by = (y+bz)*siz[0];
|
||||||
links.push_back( Link(&(*i),by+x) );
|
for(x=ib.min[0];x<=ib.max[0];++x)
|
||||||
|
// Inserire calcolo cella corrente
|
||||||
|
// if( pt->Intersect( ... )
|
||||||
|
links.push_back( Link(&(*i),by+x) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
// Push della sentinella
|
||||||
// Push della sentinella
|
/*links.push_back( Link((typename ContainerType::iterator)NULL,
|
||||||
/*links.push_back( Link((typename ContainerType::iterator)NULL,
|
(grid.size()-1)));*/
|
||||||
(grid.size()-1)));*/
|
|
||||||
|
|
||||||
links.push_back( Link(NULL,
|
links.push_back( Link(NULL,
|
||||||
(grid.size()-1)));
|
(grid.size()-1)));
|
||||||
|
|
||||||
// Ordinamento dei links
|
// Ordinamento dei links
|
||||||
sort( links.begin(), links.end() );
|
sort( links.begin(), links.end() );
|
||||||
|
|
||||||
// Creazione puntatori ai links
|
// Creazione puntatori ai links
|
||||||
typename std::vector<Link>::iterator pl;
|
typename std::vector<Link>::iterator pl;
|
||||||
unsigned int pg;
|
unsigned int pg;
|
||||||
pl = links.begin();
|
pl = links.begin();
|
||||||
for(pg=0;pg<grid.size();++pg)
|
for(pg=0;pg<grid.size();++pg)
|
||||||
{
|
|
||||||
assert(pl!=links.end());
|
|
||||||
|
|
||||||
grid[pg] = &*pl;
|
|
||||||
while( (int)pg == pl->Index() ) // Trovato inizio
|
|
||||||
{
|
{
|
||||||
++pl; // Ricerca prossimo blocco
|
assert(pl!=links.end());
|
||||||
if(pl==links.end())
|
|
||||||
break;
|
grid[pg] = &*pl;
|
||||||
|
while( (int)pg == pl->Index() ) // Trovato inizio
|
||||||
|
{
|
||||||
|
++pl; // Ricerca prossimo blocco
|
||||||
|
if(pl==links.end())
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -446,17 +457,17 @@ namespace vcg {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class OBJPOINTDISTFUNCTOR, class OBJMARKER, class OBJPTRCONTAINER, class DISTCONTAINER, class POINTCONTAINER>
|
template <class OBJPOINTDISTFUNCTOR, class OBJMARKER, class OBJPTRCONTAINER, class DISTCONTAINER, class POINTCONTAINER>
|
||||||
unsigned int GetInSphere(OBJPOINTDISTFUNCTOR & _getPointDistance,
|
unsigned int GetInSphere(OBJPOINTDISTFUNCTOR & _getPointDistance,
|
||||||
OBJMARKER & _marker,
|
OBJMARKER & _marker,
|
||||||
const CoordType & _p,
|
const CoordType & _p,
|
||||||
const ScalarType & _r,
|
const ScalarType & _r,
|
||||||
OBJPTRCONTAINER & _objectPtrs,
|
OBJPTRCONTAINER & _objectPtrs,
|
||||||
DISTCONTAINER & _distances,
|
DISTCONTAINER & _distances,
|
||||||
POINTCONTAINER & _points)
|
POINTCONTAINER & _points)
|
||||||
{
|
{
|
||||||
return(vcg::GridGetInSphere<GridPtrType,
|
return(vcg::GridGetInSphere<GridPtrType,
|
||||||
OBJPOINTDISTFUNCTOR,OBJMARKER,OBJPTRCONTAINER,DISTCONTAINER,POINTCONTAINER>
|
OBJPOINTDISTFUNCTOR,OBJMARKER,OBJPTRCONTAINER,DISTCONTAINER,POINTCONTAINER>
|
||||||
(*this,_getPointDistance,_marker,_p,_r,_maxDist,_objectPtrs,_distances,_points));
|
(*this,_getPointDistance,_marker,_p,_r,_objectPtrs,_distances,_points));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class OBJMARKER, class OBJPTRCONTAINER>
|
template <class OBJMARKER, class OBJPTRCONTAINER>
|
||||||
|
@ -465,11 +476,11 @@ namespace vcg {
|
||||||
OBJPTRCONTAINER & _objectPtrs)
|
OBJPTRCONTAINER & _objectPtrs)
|
||||||
{
|
{
|
||||||
return(vcg::GridGetInBox<GridPtrType,OBJMARKER,OBJPTRCONTAINER>
|
return(vcg::GridGetInBox<GridPtrType,OBJMARKER,OBJPTRCONTAINER>
|
||||||
(*this,_marker,_bbox,_objectPtrs));
|
(*this,_marker,_bbox,_objectPtrs));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class OBJRAYISECTFUNCTOR, class OBJMARKER>
|
template <class OBJRAYISECTFUNCTOR, class OBJMARKER>
|
||||||
ObjPtr DoRay(OBJRAYISECTFUNCTOR & _rayIntersector, OBJMARKER & _marker, const Ray3<ScalarType> & _ray, const ScalarType & _maxDist, ScalarType & _t)
|
ObjPtr DoRay(OBJRAYISECTFUNCTOR & _rayIntersector, OBJMARKER & _marker, const Ray3<ScalarType> & _ray, const ScalarType & _maxDist, ScalarType & _t)
|
||||||
{
|
{
|
||||||
return(vcg::GridDoRay<GridPtrType,OBJRAYISECTFUNCTOR,OBJMARKER>(*this,_rayIntersector,_marker,_ray,_maxDist,_t));
|
return(vcg::GridDoRay<GridPtrType,OBJRAYISECTFUNCTOR,OBJMARKER>(*this,_rayIntersector,_marker,_ray,_maxDist,_t));
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.12 2005/10/03 13:58:21 pietroni
|
||||||
|
added GetInSphere and GetInBox functions
|
||||||
|
|
||||||
Revision 1.11 2005/10/03 10:05:26 pietroni
|
Revision 1.11 2005/10/03 10:05:26 pietroni
|
||||||
changed Set functions, added possibility to pass the bbox as parameter
|
changed Set functions, added possibility to pass the bbox as parameter
|
||||||
|
|
||||||
|
@ -347,15 +350,21 @@ namespace vcg{
|
||||||
{
|
{
|
||||||
OBJITER i;
|
OBJITER i;
|
||||||
Box3<FLT> b;
|
Box3<FLT> b;
|
||||||
|
int _size=std::distance<OBJITER>(_oBegin,_oEnd);
|
||||||
if(!_bbox.IsNull()) bbox=_bbox;
|
if(!_bbox.IsNull()) bbox=_bbox;
|
||||||
else
|
else
|
||||||
|
{
|
||||||
for(i = _oBegin; i!= _oEnd; ++i)
|
for(i = _oBegin; i!= _oEnd; ++i)
|
||||||
{
|
{
|
||||||
(*i).GetBBox(b);
|
(*i).GetBBox(b);
|
||||||
bbox.Add(b);
|
bbox.Add(b);
|
||||||
}
|
}
|
||||||
|
///inflate the bb calculated
|
||||||
|
ScalarType infl=bbox.Diag()/_size;
|
||||||
|
bbox.min-=vcg::Point3d(infl,infl,infl);
|
||||||
|
bbox.max+=vcg::Point3d(infl,infl,infl);
|
||||||
|
}
|
||||||
|
|
||||||
int _size=std::distance<OBJITER>(_oBegin,_oEnd);
|
|
||||||
dim = bbox.max - bbox.min;
|
dim = bbox.max - bbox.min;
|
||||||
BestDim( _size, dim, siz );
|
BestDim( _size, dim, siz );
|
||||||
// find voxel size
|
// find voxel size
|
||||||
|
|
Loading…
Reference in New Issue