exetended form BasicGrid, changed type of t in class Link (from Iterator to Pointer to the object)

This commit is contained in:
Nico Pietroni 2005-08-02 11:18:36 +00:00
parent 7bc4ef59fd
commit 66921c752b
1 changed files with 374 additions and 383 deletions

View File

@ -24,6 +24,9 @@
History
$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
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/line3.h>
#include <vcg/space/index/grid_util.h>
namespace vcg {
/** Static Uniform Grid
@ -106,11 +110,19 @@ namespace vcg {
*/
template < typename ContainerType >
class GridStaticPtr
template < typename ContainerType,class FLT=float >
class GridStaticPtr:public BasicGrid<FLT>
{
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.
Definizione Link dentro la griglia. Classe di supporto per GridStaticObj.
*/
@ -120,7 +132,7 @@ class GridStaticPtr
/// Costruttore di default
inline Link(){};
/// Costruttore con inizializzatori
inline Link( typename ContainerType::iterator const nt, const int ni ){
inline Link(ObjPtr nt, const int ni ){
assert(ni>=0);
t = nt;
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 typename ContainerType::iterator & Elem() {
inline typename ObjPtr & Elem() {
return t;
}
inline int & Index() {
@ -143,30 +155,20 @@ class GridStaticPtr
private:
/// Puntatore all'elemento T
typename ContainerType::iterator t;
ObjPtr t;
/// Indirizzo del voxel dentro la griglia
int i;
};//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;
Box3x bbox;
Point3x dim; /// Dimensione spaziale (lunghezza lati) del bbox
Point3i siz; /// Dimensioni griglia in celle
Point3x voxel; /// Dimensioni di una cella
typedef typename Cell CellIterator;
std::vector<Link> links; /// Insieme di tutti i links
std::vector<Cell> grid; /// Griglia vera e propria
/// Dato un punto, ritorna la cella che lo contiene
inline Cell* Grid( const Point3d & p )
{
@ -258,20 +260,6 @@ class GridStaticPtr
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)
@ -300,7 +288,7 @@ class GridStaticPtr
@param p a 3d point
@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 dy = ( (p[1]-bbox.min[1])/voxel[1] );
@ -326,7 +314,7 @@ class GridStaticPtr
tmp*=voxel[2];
if (radius>tmp) radius=tmp;
Point3x t_res;
CoordType t_res;
//ScalarType min_dist=1e10;
ObjPtr winner=NULL;
@ -430,13 +418,16 @@ class GridStaticPtr
for(x=ib.min[0];x<=ib.max[0];++x)
// Inserire calcolo cella corrente
// if( pt->Intersect( ... )
links.push_back( Link(pt,by+x) );
links.push_back( Link(&(*pt),by+x) );
}
}
}
}
// 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)));
// Ordinamento dei links