Added some help and inndentation
This commit is contained in:
parent
ed7382539c
commit
956a626273
|
@ -24,6 +24,9 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.3 2004/05/12 18:50:58 ganovelli
|
||||||
|
changed calls to Dist
|
||||||
|
|
||||||
Revision 1.2 2004/05/11 14:33:46 ganovelli
|
Revision 1.2 2004/05/11 14:33:46 ganovelli
|
||||||
changed to grid_static_obj to grid_static_ptr
|
changed to grid_static_obj to grid_static_ptr
|
||||||
|
|
||||||
|
@ -46,17 +49,38 @@ Initial commit
|
||||||
namespace vcg {
|
namespace vcg {
|
||||||
|
|
||||||
/** Static Uniform Grid
|
/** Static Uniform Grid
|
||||||
A spatial search structure for a accessing a container of objects. It is based on a uniform grid overlayed over a protion of space.
|
A spatial search structure for a accessing a container of objects.
|
||||||
The grid partion the space into cells. Cells contains just pointers to the object that are stored elsewhere.
|
It is based on a uniform grid overlayed over a protion of space.
|
||||||
The set of object is meant to be static and pointer stable.
|
The grid partion the space into cells. Cells contains just pointers
|
||||||
Useful for situation were many space related query are issued over the same dataset (ray tracing, measuring distances between meshes, re-detailing ecc.). Works well for distribution that ar reasonably uniform.
|
to the object that are stored elsewhere.
|
||||||
|
The set of objects is meant to be static and pointer stable.
|
||||||
|
|
||||||
|
Useful for situation were many space related query are issued over
|
||||||
|
the same dataset (ray tracing, measuring distances between meshes,
|
||||||
|
re-detailing ecc.).
|
||||||
|
Works well for distribution that ar reasonably uniform.
|
||||||
How to use it:
|
How to use it:
|
||||||
|
ContainerType must have a 'value_type' typedef inside.
|
||||||
|
(stl containers already have it)
|
||||||
|
|
||||||
|
Objects pointed by cells (of kind 'value_type') must have
|
||||||
|
a 'ScalarType' typedef (float or double usually)
|
||||||
|
and 2 member functions:
|
||||||
|
|
||||||
|
bool Dist(const Point3f &point, ScalarType &mindist, Point3f &result);
|
||||||
|
which return true if the distance from point to the object is < mindist
|
||||||
|
and set mindist to said distance, and result must be set as the closest
|
||||||
|
point of the object to point)
|
||||||
|
|
||||||
|
void GetBBox(Box3<ScalarType> &b)
|
||||||
|
which return the bounding box of the object
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template < typename ContainerType >
|
template < typename ContainerType >
|
||||||
class GridStaticPtr
|
class GridStaticPtr
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/** Internal class for keeping the first pointer of object.
|
/** Internal class for keeping the first pointer of object.
|
||||||
Definizione Link dentro la griglia. Classe di supporto per GridStaticObj.
|
Definizione Link dentro la griglia. Classe di supporto per GridStaticObj.
|
||||||
|
@ -110,10 +134,9 @@ public:
|
||||||
Point3i siz; /// Dimensioni griglia in celle
|
Point3i siz; /// Dimensioni griglia in celle
|
||||||
Point3x voxel; /// Dimensioni di una cella
|
Point3x voxel; /// Dimensioni di una cella
|
||||||
|
|
||||||
/// Insieme di tutti i links
|
|
||||||
std::vector<Link> links;
|
std::vector<Link> links; /// Insieme di tutti i links
|
||||||
/// Griglia vera e propria
|
std::vector<Cell> grid; /// Griglia vera e propria
|
||||||
std::vector<Cell> grid;
|
|
||||||
|
|
||||||
/// Dato un punto, ritorna la cella che lo contiene
|
/// Dato un punto, ritorna la cella che lo contiene
|
||||||
inline Cell* Grid( const Point3d & p )
|
inline Cell* Grid( const Point3d & p )
|
||||||
|
@ -151,7 +174,9 @@ public:
|
||||||
std::vector<Point3i> &o)
|
std::vector<Point3i> &o)
|
||||||
{
|
{
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if ( p[0]<0 || p[0]>siz[0] || p[1]<0 || p[1]>siz[1] || p[2]<0 || p[2]>siz[2] )
|
if ( p[0]<0 || p[0]>siz[0] ||
|
||||||
|
p[1]<0 || p[1]>siz[1] ||
|
||||||
|
p[2]<0 || p[2]>siz[2] )
|
||||||
assert(0);
|
assert(0);
|
||||||
//return NULL;
|
//return NULL;
|
||||||
else
|
else
|
||||||
|
@ -269,9 +294,14 @@ public:
|
||||||
ScalarType radius=(dx-ScalarType(ix));
|
ScalarType radius=(dx-ScalarType(ix));
|
||||||
if (radius>0.5) radius=(1.0-radius); radius*=voxel[0];
|
if (radius>0.5) radius=(1.0-radius); radius*=voxel[0];
|
||||||
|
|
||||||
ScalarType
|
ScalarType tmp=dy-ScalarType(iy);
|
||||||
tmp=dy-ScalarType(iy); if (tmp>0.5) tmp=1.0-tmp; tmp*=voxel[1]; if (radius>tmp) radius=tmp;
|
if (tmp>0.5) tmp=1.0-tmp;
|
||||||
tmp=dz-ScalarType(iz); if (tmp>0.5) tmp=1.0-tmp; tmp*=voxel[2]; if (radius>tmp) radius=tmp;
|
tmp*=voxel[1];
|
||||||
|
if (radius>tmp) radius=tmp;
|
||||||
|
tmp=dz-ScalarType(iz);
|
||||||
|
if (tmp>0.5) tmp=1.0-tmp;
|
||||||
|
tmp*=voxel[2];
|
||||||
|
if (radius>tmp) radius=tmp;
|
||||||
|
|
||||||
Point3x t_res;
|
Point3x t_res;
|
||||||
//ScalarType min_dist=1e10;
|
//ScalarType min_dist=1e10;
|
||||||
|
@ -279,7 +309,8 @@ public:
|
||||||
|
|
||||||
Link *first, *last;
|
Link *first, *last;
|
||||||
Link *l;
|
Link *l;
|
||||||
if ((ix>=0) && (iy>=0) && (iz>=0) && (ix<siz[0]) && (iy<siz[1]) && (iz<siz[2])) {
|
if ((ix>=0) && (iy>=0) && (iz>=0) &&
|
||||||
|
(ix<siz[0]) && (iy<siz[1]) && (iz<siz[2])) {
|
||||||
|
|
||||||
Grid( ix, iy, iz, first, last );
|
Grid( ix, iy, iz, first, last );
|
||||||
for(l=first;l!=last;++l)
|
for(l=first;l!=last;++l)
|
||||||
|
@ -382,7 +413,8 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Push della sentinella
|
// Push della sentinella
|
||||||
links.push_back( Link((typename ContainerType::iterator)NULL,(grid.size()-1)));
|
links.push_back( Link((typename ContainerType::iterator)NULL,
|
||||||
|
(grid.size()-1)));
|
||||||
|
|
||||||
// Ordinamento dei links
|
// Ordinamento dei links
|
||||||
sort( links.begin(), links.end() );
|
sort( links.begin(), links.end() );
|
||||||
|
@ -481,7 +513,8 @@ public:
|
||||||
|
|
||||||
int MemUsed()
|
int MemUsed()
|
||||||
{
|
{
|
||||||
return sizeof(GridStaticObj)+ sizeof(Link)*links.size() + sizeof(Cell) * grid.size();
|
return sizeof(GridStaticObj)+ sizeof(Link)*links.size() +
|
||||||
|
sizeof(Cell) * grid.size();
|
||||||
}
|
}
|
||||||
}; //end class GridStaticObj
|
}; //end class GridStaticObj
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue