Refactored CountInSphere / RemoveInSphere for the PoissonDisk sampling optimizations (now you can just count the element inside a given sphere without removing them.

This commit is contained in:
Paolo Cignoni 2013-06-24 07:57:18 +00:00
parent 9ad68bc573
commit be3e74ca6a
1 changed files with 50 additions and 47 deletions

View File

@ -206,14 +206,13 @@ protected:
return true; return true;
} ///insert a new cell } ///insert a new cell
int RemoveInSphere(const Point3<ScalarType> &p, const ScalarType radius) int CountInSphere(const Point3<ScalarType> &p, const ScalarType radius, std::vector<HashIterator> &inSphVec)
{ {
Box3x b(p-Point3f(radius,radius,radius),p+Point3f(radius,radius,radius)); Box3x b(p-Point3f(radius,radius,radius),p+Point3f(radius,radius,radius));
vcg::Box3i bb; vcg::Box3i bb;
this->BoxToIBox(b,bb); this->BoxToIBox(b,bb);
ScalarType r2=radius*radius; ScalarType r2=radius*radius;
int cnt=0; inSphVec.clear();
std::vector<HashIterator> toDel;
for (int i=bb.min.X();i<=bb.max.X();i++) for (int i=bb.min.X();i<=bb.max.X();i++)
for (int j=bb.min.Y();j<=bb.max.Y();j++) for (int j=bb.min.Y();j<=bb.max.Y();j++)
@ -223,16 +222,20 @@ protected:
for(HashIterator hi = CellRange.first; hi!=CellRange.second;++hi) for(HashIterator hi = CellRange.first; hi!=CellRange.second;++hi)
{ {
if(SquaredDistance(p,hi->second->cP()) <= r2) if(SquaredDistance(p,hi->second->cP()) <= r2)
inSphVec.push_back(hi);
}
}
return inSphVec.size();
}
int RemoveInSphere(const Point3<ScalarType> &p, const ScalarType radius)
{ {
cnt++; std::vector<HashIterator> inSphVec;
toDel.push_back(hi); CountInSphere(p,radius,inSphVec);
} for(typename std::vector<HashIterator>::iterator vi=inSphVec.begin(); vi!=inSphVec.end();++vi)
}
}
for(typename std::vector<HashIterator>::iterator vi=toDel.begin(); vi!=toDel.end();++vi)
hash_table.erase(*vi); hash_table.erase(*vi);
return cnt; return inSphVec.size();
} }
// Specialized version that is able to take in input a // Specialized version that is able to take in input a
template<class DistanceFunctor> template<class DistanceFunctor>