Better commnts and other minor beautifications
This commit is contained in:
parent
a546c88a7c
commit
017d27dc36
|
@ -24,11 +24,6 @@
|
|||
#ifndef VCGLIB_SPATIAL_HASHING
|
||||
#define VCGLIB_SPATIAL_HASHING
|
||||
|
||||
|
||||
#define HASH_P0 73856093u
|
||||
#define HASH_P1 19349663u
|
||||
#define HASH_P2 83492791u
|
||||
|
||||
#include <vcg/space/index/grid_util.h>
|
||||
#include <vcg/space/index/grid_closest.h>
|
||||
//#include <map>
|
||||
|
@ -50,14 +45,20 @@
|
|||
|
||||
namespace vcg{
|
||||
|
||||
// hashing function
|
||||
struct HashFunctor : public unary_function<Point3i, size_t>
|
||||
{
|
||||
size_t operator()(const Point3i &p) const
|
||||
{
|
||||
return size_t(p.V(0))*HASH_P0 ^ size_t(p.V(1))*HASH_P1 ^ size_t(p.V(2))*HASH_P2;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// hashing function
|
||||
struct HashFunctor : public unary_function<Point3i, size_t>
|
||||
{
|
||||
size_t operator()(const Point3i &p) const
|
||||
{
|
||||
static const size_t HASH_P0=73856093u;
|
||||
static const size_t HASH_P1=19349663u;
|
||||
static const size_t HASH_P2=83492791u;
|
||||
|
||||
return size_t(p.V(0))*HASH_P0 ^ size_t(p.V(1))*HASH_P1 ^ size_t(p.V(2))*HASH_P2;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/** Spatial Hash Table
|
||||
|
@ -70,20 +71,23 @@ namespace vcg{
|
|||
{
|
||||
|
||||
public:
|
||||
typedef SpatialHashTable SpatialHashType;
|
||||
typedef ObjType* ObjPtr;
|
||||
typedef typename ObjType::ScalarType ScalarType;
|
||||
typedef Point3<ScalarType> CoordType;
|
||||
typedef typename BasicGrid<FLT>::Box3x Box3x;
|
||||
typedef SpatialHashTable SpatialHashType;
|
||||
typedef ObjType* ObjPtr;
|
||||
typedef typename ObjType::ScalarType ScalarType;
|
||||
typedef Point3<ScalarType> CoordType;
|
||||
typedef typename BasicGrid<FLT>::Box3x Box3x;
|
||||
|
||||
// Hash table definition
|
||||
// the hash index directly the grid structure.
|
||||
// We use a MultiMap because we need to store many object (faces) inside each cell of the grid.
|
||||
// Hash table definition
|
||||
// the hash index directly the grid structure.
|
||||
// We use a MultiMap because we need to store many object (faces) inside each cell of the grid.
|
||||
|
||||
typedef typename STDEXT::hash_multimap<Point3i, ObjType *, HashFunctor> HashType;
|
||||
typedef typename HashType::iterator HashIterator;
|
||||
HashType hash_table;
|
||||
std::vector<Point3i> AllocatedCells;
|
||||
typedef typename STDEXT::hash_multimap<Point3i, ObjType *, HashFunctor> HashType;
|
||||
typedef typename HashType::iterator HashIterator;
|
||||
HashType hash_table; // The real HASH TABLE **************************************
|
||||
|
||||
// This vector is just a handy reference to all the allocated cells,
|
||||
// becouse hashed multimaps does not expose a direct list of all the different keys.
|
||||
std::vector<Point3i> AllocatedCells;
|
||||
|
||||
// Class to abstract a HashIterator (that stores also the key,
|
||||
// while the interface of the generic spatial indexing need only simple object (face) pointers.
|
||||
|
@ -93,18 +97,18 @@ namespace vcg{
|
|||
CellIterator(){}
|
||||
HashIterator t;
|
||||
ObjPtr &operator *(){return t->second;}
|
||||
bool operator != (const CellIterator & p) {return t!=p.t;}
|
||||
bool operator != (const CellIterator & p) const {return t!=p.t;}
|
||||
void operator ++() {t++;}
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
///insert a new cell
|
||||
void InsertObject(ObjType* s,Point3i cell)
|
||||
{
|
||||
if(hash_table.count(cell)==0) AllocatedCells.push_back(cell);
|
||||
hash_table.insert(typename HashType::value_type(cell, s));
|
||||
}
|
||||
///insert a new cell
|
||||
void InsertObject(ObjType* s, const Point3i &cell)
|
||||
{
|
||||
if(hash_table.count(cell)==0) AllocatedCells.push_back(cell);
|
||||
hash_table.insert(typename HashType::value_type(cell, s));
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
|
@ -147,15 +151,14 @@ namespace vcg{
|
|||
|
||||
/// Insert a mesh in the grid.
|
||||
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;
|
||||
Box3x b;
|
||||
Box3x &bbox = this->bbox;
|
||||
CoordType &dim = this->dim;
|
||||
Point3i &siz = this->siz;
|
||||
CoordType &voxel = this->voxel;
|
||||
Box3x &bbox = this->bbox;
|
||||
CoordType &dim = this->dim;
|
||||
Point3i &siz = this->siz;
|
||||
CoordType &voxel = this->voxel;
|
||||
|
||||
int _size=(int)std::distance<OBJITER>(_oBegin,_oEnd);
|
||||
if(!_bbox.IsNull()) this->bbox=_bbox;
|
||||
|
@ -167,20 +170,18 @@ namespace vcg{
|
|||
this->bbox.Add(b);
|
||||
}
|
||||
///inflate the bb calculated
|
||||
ScalarType infl=bbox.Diag()/_size;
|
||||
bbox.min -= CoordType(infl,infl,infl);
|
||||
bbox.max += CoordType(infl,infl,infl);
|
||||
bbox.Offset(bbox.Diag()/100.0) ;
|
||||
}
|
||||
|
||||
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];
|
||||
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];
|
||||
|
||||
for(i = _oBegin; i!= _oEnd; ++i)
|
||||
Add(&(*i));
|
||||
for(i = _oBegin; i!= _oEnd; ++i)
|
||||
Add(&(*i));
|
||||
}
|
||||
|
||||
|
||||
|
@ -206,11 +207,6 @@ namespace vcg{
|
|||
end.t=CellRange.second;
|
||||
}
|
||||
|
||||
|
||||
///return the number of cell created
|
||||
int CellNumber()
|
||||
{return (hash_table.size());}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
hash_table.clear();
|
||||
|
|
Loading…
Reference in New Issue