Better commnts and other minor beautifications

This commit is contained in:
Paolo Cignoni 2009-01-13 06:27:01 +00:00
parent a546c88a7c
commit 017d27dc36
1 changed files with 50 additions and 54 deletions

View File

@ -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,11 +45,17 @@
namespace vcg{
// 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;
}
};
@ -82,7 +83,10 @@ namespace vcg{
typedef typename STDEXT::hash_multimap<Point3i, ObjType *, HashFunctor> HashType;
typedef typename HashType::iterator HashIterator;
HashType hash_table;
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,
@ -93,14 +97,14 @@ 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)
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));
@ -149,7 +153,6 @@ namespace vcg{
template <class OBJITER>
void Set(const OBJITER & _oBegin, const OBJITER & _oEnd, const Box3x &_bbox=Box3x() )
{
OBJITER i;
Box3x b;
Box3x &bbox = this->bbox;
@ -167,9 +170,7 @@ 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;
@ -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();