exetended form BasicGrid, changed type of t in class Link (from Iterator to Pointer to the object)
This commit is contained in:
parent
7bc4ef59fd
commit
66921c752b
|
|
@ -21,9 +21,12 @@
|
||||||
* *
|
* *
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.13 2005/04/14 17:23:08 ponchio
|
||||||
|
*** empty log message ***
|
||||||
|
|
||||||
Revision 1.12 2005/03/15 11:43:18 cignoni
|
Revision 1.12 2005/03/15 11:43:18 cignoni
|
||||||
Removed BestDim function from the grid_static_ptr class and moved to a indipendent file (grid_util.h) for sake of generality.
|
Removed BestDim function from the grid_static_ptr class and moved to a indipendent file (grid_util.h) for sake of generality.
|
||||||
|
|
||||||
|
|
@ -75,6 +78,7 @@ Initial commit
|
||||||
#include <vcg/space/box3.h>
|
#include <vcg/space/box3.h>
|
||||||
#include <vcg/space/line3.h>
|
#include <vcg/space/line3.h>
|
||||||
#include <vcg/space/index/grid_util.h>
|
#include <vcg/space/index/grid_util.h>
|
||||||
|
|
||||||
namespace vcg {
|
namespace vcg {
|
||||||
|
|
||||||
/** Static Uniform Grid
|
/** Static Uniform Grid
|
||||||
|
|
@ -106,11 +110,19 @@ namespace vcg {
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template < typename ContainerType >
|
template < typename ContainerType,class FLT=float >
|
||||||
class GridStaticPtr
|
class GridStaticPtr:public BasicGrid<FLT>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
typedef typename ContainerType::value_type ObjType;
|
||||||
|
typedef ObjType* ObjPtr;
|
||||||
|
typedef typename ObjType::ScalarType ScalarType;
|
||||||
|
typedef Point3<ScalarType> CoordType;
|
||||||
|
typedef Box3<ScalarType> Box3x;
|
||||||
|
typedef Line3<ScalarType> Line3x;
|
||||||
|
|
||||||
|
|
||||||
/** 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.
|
||||||
*/
|
*/
|
||||||
|
|
@ -120,7 +132,7 @@ class GridStaticPtr
|
||||||
/// Costruttore di default
|
/// Costruttore di default
|
||||||
inline Link(){};
|
inline Link(){};
|
||||||
/// Costruttore con inizializzatori
|
/// Costruttore con inizializzatori
|
||||||
inline Link( typename ContainerType::iterator const nt, const int ni ){
|
inline Link(ObjPtr nt, const int ni ){
|
||||||
assert(ni>=0);
|
assert(ni>=0);
|
||||||
t = nt;
|
t = nt;
|
||||||
i = ni;
|
i = ni;
|
||||||
|
|
@ -134,7 +146,7 @@ class GridStaticPtr
|
||||||
inline bool operator == ( const Link & l ) const{ return i == l.i; }
|
inline bool operator == ( const Link & l ) const{ return i == l.i; }
|
||||||
inline bool operator != ( const Link & l ) const{ return i != l.i; }
|
inline bool operator != ( const Link & l ) const{ return i != l.i; }
|
||||||
|
|
||||||
inline typename ContainerType::iterator & Elem() {
|
inline typename ObjPtr & Elem() {
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
inline int & Index() {
|
inline int & Index() {
|
||||||
|
|
@ -143,30 +155,20 @@ class GridStaticPtr
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// Puntatore all'elemento T
|
/// Puntatore all'elemento T
|
||||||
typename ContainerType::iterator t;
|
ObjPtr t;
|
||||||
/// Indirizzo del voxel dentro la griglia
|
/// Indirizzo del voxel dentro la griglia
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
|
||||||
};//end class Link
|
};//end class Link
|
||||||
|
|
||||||
typedef typename ContainerType::value_type ObjType;
|
|
||||||
typedef ObjType* ObjPtr;
|
|
||||||
typedef typename ObjType::ScalarType ScalarType;
|
|
||||||
typedef Point3<ScalarType> Point3x;
|
|
||||||
typedef Box3<ScalarType> Box3x;
|
|
||||||
typedef Line3<ScalarType> Line3x;
|
|
||||||
typedef Link* Cell;
|
typedef Link* Cell;
|
||||||
|
typedef typename Cell CellIterator;
|
||||||
Box3x bbox;
|
|
||||||
Point3x dim; /// Dimensione spaziale (lunghezza lati) del bbox
|
|
||||||
Point3i siz; /// Dimensioni griglia in celle
|
|
||||||
Point3x voxel; /// Dimensioni di una cella
|
|
||||||
|
|
||||||
|
|
||||||
std::vector<Link> links; /// Insieme di tutti i links
|
std::vector<Link> links; /// Insieme di tutti i links
|
||||||
std::vector<Cell> grid; /// Griglia vera e propria
|
std::vector<Cell> grid; /// Griglia vera e propria
|
||||||
|
|
||||||
|
|
||||||
/// 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 )
|
||||||
{
|
{
|
||||||
|
|
@ -258,20 +260,6 @@ class GridStaticPtr
|
||||||
dim = bbox.max - bbox.min;
|
dim = bbox.max - bbox.min;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Dato un punto 3d ritorna l'indice del box corrispondente
|
|
||||||
inline void PToIP(const Point3x & p, Point3i &pi ) const
|
|
||||||
{
|
|
||||||
Point3x t = p - bbox.min;
|
|
||||||
pi[0] = int( t[0]/voxel[0] );
|
|
||||||
pi[1] = int( t[1]/voxel[1] );
|
|
||||||
pi[2] = int( t[2]/voxel[2] );
|
|
||||||
}
|
|
||||||
/// Dato un box reale ritorna gli indici dei voxel compresi dentro un ibox
|
|
||||||
void BoxToIBox( const Box3x & b, Box3i & ib ) const
|
|
||||||
{
|
|
||||||
PToIP(b.min,ib.min);
|
|
||||||
PToIP(b.max,ib.max);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ShowStats(FILE *fp)
|
void ShowStats(FILE *fp)
|
||||||
|
|
@ -300,7 +288,7 @@ class GridStaticPtr
|
||||||
@param p a 3d point
|
@param p a 3d point
|
||||||
@return The closest element
|
@return The closest element
|
||||||
*/
|
*/
|
||||||
ObjPtr GetClosest( const Point3x & p, ScalarType & min_dist, Point3x & res)
|
ObjPtr GetClosest( const CoordType & p, ScalarType & min_dist, CoordType & res)
|
||||||
{
|
{
|
||||||
ScalarType dx = ( (p[0]-bbox.min[0])/voxel[0] );
|
ScalarType dx = ( (p[0]-bbox.min[0])/voxel[0] );
|
||||||
ScalarType dy = ( (p[1]-bbox.min[1])/voxel[1] );
|
ScalarType dy = ( (p[1]-bbox.min[1])/voxel[1] );
|
||||||
|
|
@ -326,7 +314,7 @@ class GridStaticPtr
|
||||||
tmp*=voxel[2];
|
tmp*=voxel[2];
|
||||||
if (radius>tmp) radius=tmp;
|
if (radius>tmp) radius=tmp;
|
||||||
|
|
||||||
Point3x t_res;
|
CoordType t_res;
|
||||||
//ScalarType min_dist=1e10;
|
//ScalarType min_dist=1e10;
|
||||||
ObjPtr winner=NULL;
|
ObjPtr winner=NULL;
|
||||||
|
|
||||||
|
|
@ -430,13 +418,16 @@ class GridStaticPtr
|
||||||
for(x=ib.min[0];x<=ib.max[0];++x)
|
for(x=ib.min[0];x<=ib.max[0];++x)
|
||||||
// Inserire calcolo cella corrente
|
// Inserire calcolo cella corrente
|
||||||
// if( pt->Intersect( ... )
|
// if( pt->Intersect( ... )
|
||||||
links.push_back( Link(pt,by+x) );
|
links.push_back( Link(&(*pt),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)));*/
|
||||||
|
|
||||||
|
links.push_back( Link(NULL,
|
||||||
(grid.size()-1)));
|
(grid.size()-1)));
|
||||||
|
|
||||||
// Ordinamento dei links
|
// Ordinamento dei links
|
||||||
|
|
@ -467,7 +458,7 @@ class GridStaticPtr
|
||||||
return sizeof(GridStaticPtr)+ sizeof(Link)*links.size() +
|
return sizeof(GridStaticPtr)+ sizeof(Link)*links.size() +
|
||||||
sizeof(Cell) * grid.size();
|
sizeof(Cell) * grid.size();
|
||||||
}
|
}
|
||||||
}; //end class GridStaticObj
|
}; //end class GridStaticObj
|
||||||
|
|
||||||
}; // end namespace
|
}; // end namespace
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue