Improved float/double consistency removing some wrong Point3f and substitued with MeshType::CoordType

and removed a small bug (in the initialization the first ball sphere could fail for approx errors)
This commit is contained in:
Paolo Cignoni 2014-06-19 10:25:50 +00:00
parent 59779347ab
commit 3bc58b7018
1 changed files with 132 additions and 131 deletions

View File

@ -31,8 +31,8 @@ template <class MESH> class BallPivoting: public AdvancingFront<MESH> {
public: public:
// if radius ==0 an autoguess for the ball pivoting radius is attempted // if radius ==0 an autoguess for the ball pivoting radius is attempted
// otherwise the passed value (in absolute mesh units) is used. // otherwise the passed value (in absolute mesh units) is used.
BallPivoting(MESH &_mesh, float _radius = 0, BallPivoting(MESH &_mesh, float _radius = 0,
float minr = 0.2, float angle = M_PI/2): float minr = 0.2, float angle = M_PI/2):
@ -44,12 +44,12 @@ template <class MESH> class BallPivoting: public AdvancingFront<MESH> {
//compute bbox //compute bbox
baricenter = Point3x(0, 0, 0); baricenter = Point3x(0, 0, 0);
UpdateBounding<MESH>::Box(_mesh); UpdateBounding<MESH>::Box(_mesh);
for(VertexIterator vi=this->mesh.vert.begin();vi!=this->mesh.vert.end();++vi) for(VertexIterator vi=this->mesh.vert.begin();vi!=this->mesh.vert.end();++vi)
if( !(*vi).IsD() ) baricenter += (*vi).P(); if( !(*vi).IsD() ) baricenter += (*vi).P();
baricenter /= this->mesh.vn; baricenter /= this->mesh.vn;
assert(this->mesh.vn > 3); assert(this->mesh.vn > 3);
if(radius == 0) // radius ==0 means that an auto guess should be attempted. if(radius == 0) // radius ==0 means that an auto guess should be attempted.
radius = sqrt((this->mesh.bbox.Diag()*this->mesh.bbox.Diag())/this->mesh.vn); radius = sqrt((this->mesh.bbox.Diag()*this->mesh.bbox.Diag())/this->mesh.vn);
@ -58,7 +58,7 @@ template <class MESH> class BallPivoting: public AdvancingFront<MESH> {
max_edge *= radius; max_edge *= radius;
VertexConstDataWrapper<MESH> ww(this->mesh); VertexConstDataWrapper<MESH> ww(this->mesh);
tree = new KdTree<float>(ww); tree = new KdTree<ScalarType>(ww);
tree->setMaxNofNeighbors(16); tree->setMaxNofNeighbors(16);
usedBit = VertexType::NewBitFlag(); usedBit = VertexType::NewBitFlag();
@ -81,8 +81,8 @@ template <class MESH> class BallPivoting: public AdvancingFront<MESH> {
bool Seed(int &v0, int &v1, int &v2) { bool Seed(int &v0, int &v1, int &v2) {
//get a sphere of neighbours //get a sphere of neighbours
std::vector<VertexType *> targets;
while(++last_seed < (int)(this->mesh.vert.size())) { while(++last_seed < (int)(this->mesh.vert.size())) {
std::vector<VertexType *> targets;
VertexType &seed = this->mesh.vert[last_seed]; VertexType &seed = this->mesh.vert[last_seed];
if(seed.IsD() || seed.IsUserBit(usedBit)) continue; if(seed.IsD() || seed.IsUserBit(usedBit)) continue;
@ -151,7 +151,8 @@ template <class MESH> class BallPivoting: public AdvancingFront<MESH> {
//check no other point inside //check no other point inside
int t; int t;
for(t = 0; t < n; t++) { for(t = 0; t < n; t++) {
if((center - targets[t]->P()).Norm() <= radius) ScalarType rr= Distance(center, targets[t]->P());
if( rr < radius - min_edge)
break; break;
} }
if(t < n) { if(t < n) {
@ -295,23 +296,23 @@ template <class MESH> class BallPivoting: public AdvancingFront<MESH> {
return -1; return -1;
} }
//test if id is in some border (to return touch //test if id is in some border (to return touch
for(std::list<FrontEdge>::iterator k = this->front.begin(); k != this->front.end(); k++) for(std::list<FrontEdge>::iterator k = this->front.begin(); k != this->front.end(); k++)
{ {
if((*k).v0 == candidateIndex) if((*k).v0 == candidateIndex)
{ {
touch.first = AdvancingFront<MESH>::FRONT; touch.first = AdvancingFront<MESH>::FRONT;
touch.second = k; touch.second = k;
} }
} }
for(std::list<FrontEdge>::iterator k = this->deads.begin(); k != this->deads.end(); k++) for(std::list<FrontEdge>::iterator k = this->deads.begin(); k != this->deads.end(); k++)
{ {
if((*k).v0 == candidateIndex) if((*k).v0 == candidateIndex)
{ {
touch.first = AdvancingFront<MESH>::DEADS; touch.first = AdvancingFront<MESH>::DEADS;
touch.second = k; touch.second = k;
} }
} }
//mark vertices close to candidate //mark vertices close to candidate
Mark(candidate); Mark(candidate);
@ -322,7 +323,7 @@ template <class MESH> class BallPivoting: public AdvancingFront<MESH> {
int last_seed; //used for new seeds when front is empty int last_seed; //used for new seeds when front is empty
int usedBit; //use to detect if a vertex has been already processed. int usedBit; //use to detect if a vertex has been already processed.
Point3x baricenter;//used for the first seed. Point3x baricenter;//used for the first seed.
KdTree<float> *tree; KdTree<ScalarType> *tree;
/* returns the sphere touching p0, p1, p2 of radius r such that /* returns the sphere touching p0, p1, p2 of radius r such that