a few optimization and correction to the hashed grid removal stuff

This commit is contained in:
Paolo Cignoni 2009-12-02 15:08:49 +00:00
parent 08f9b6a4b3
commit 5a96ab4f8d
1 changed files with 35 additions and 20 deletions

View File

@ -150,7 +150,7 @@ protected:
{
}
///insert a new cell
bool RemoveObject(ObjType* s, const Point3i &cell)
{
std::pair<HashIterator,HashIterator> CellRange = hash_table.equal_range(cell);
@ -184,6 +184,16 @@ protected:
return bb;
}
///Remove all the objects contained in the cell containing s
// it removes s too.
bool RemoveCell(ObjType* s)
{
Point3i pi;
PToIP(s->cP(),pi);
std::pair<HashIterator,HashIterator> CellRange = hash_table.equal_range(pi);
hash_table.erase(CellRange.first,CellRange.second);
return true;
} ///insert a new cell
int RemoveInSphere(const Point3<ScalarType> &p, const ScalarType radius)
{
@ -192,6 +202,7 @@ int RemoveInSphere(const Point3<ScalarType> &p, const ScalarType radius)
BoxToIBox(b,bb);
ScalarType r2=radius*radius;
int cnt=0;
std::vector<HashIterator> toDel;
for (int i=bb.min.X();i<=bb.max.X();i++)
for (int j=bb.min.Y();j<=bb.max.Y();j++)
@ -203,10 +214,13 @@ int RemoveInSphere(const Point3<ScalarType> &p, const ScalarType radius)
if(SquaredDistance(p,hi->second->cP()) <= r2)
{
cnt++;
hash_table.erase(hi);
toDel.push_back(hi);
}
}
}
for(std::vector<HashIterator>::iterator vi=toDel.begin(); vi!=toDel.end();++vi)
hash_table.erase(*vi);
return cnt;
}
@ -259,6 +273,7 @@ int RemoveInSphere(const Point3<ScalarType> &p, const ScalarType radius)
voxel[0] = dim[0]/siz[0];
voxel[1] = dim[1]/siz[1];
voxel[2] = dim[2]/siz[2];
hash_table.clear();
}
/// Insert a mesh in the grid.