diff --git a/vcg/complex/trimesh/create/advancing_front.h b/vcg/complex/trimesh/create/advancing_front.h index d19daf01..ba4ceab7 100644 --- a/vcg/complex/trimesh/create/advancing_front.h +++ b/vcg/complex/trimesh/create/advancing_front.h @@ -9,6 +9,8 @@ namespace vcg { namespace tri { + +extern FILE *fp; class FrontEdge { public: @@ -50,11 +52,8 @@ template <class MESH> class AdvancingFront { MESH &mesh; //this structure will be filled by the algorithm AdvancingFront(MESH &_mesh): mesh(_mesh) { -// UpdateFlags<MESH>::VertexClear(mesh); - UpdateFlags<MESH>::Clear(mesh); -// UpdateTopology<MESH>::VertexFace(mesh); - //UpdateTopology<MESH>::TestVertexFace(mesh); //odd i would like to return a false not an assert... -// UpdateFlags<MESH>::FaceBorderFromVF(mesh); + + UpdateFlags<MESH>::FaceBorderFromNone(mesh); UpdateFlags<MESH>::VertexBorderFromFace(mesh); @@ -69,8 +68,10 @@ template <class MESH> class AdvancingFront { void BuildMesh(CallBackPos call = NULL, int interval = 512) { while(1) { if(call) call(0, "Advancing front"); - for(int i = 0; i < interval; i++) - if(!AddFace()) return; + for(int i = 0; i < interval; i++) { + if(!front.size() && !SeedFace()) return; + AddFace(); + } } } @@ -82,9 +83,9 @@ protected: bool CheckFrontEdge(int v0, int v1) { int tot = 0; //HACK to speed up things until i can use a seach structure - int i = mesh.face.size() - 4*(front.size()); - if(front.size() < 100) i = mesh.face.size() - 100; - // i = 0; +// int i = mesh.face.size() - 4*(front.size()); +// if(front.size() < 100) i = mesh.face.size() - 100; + i = 0; if(i < 0) i = 0; for(; i < (int)mesh.face.size(); i++) { FaceType &f = mesh.face[i]; @@ -176,9 +177,7 @@ protected: public: bool AddFace() { - if(!front.size()) { - return SeedFace(); - } + if(!front.size()) return false; std::list<FrontEdge>::iterator ei = front.begin(); FrontEdge ¤t = *ei; @@ -192,20 +191,20 @@ public: int v2 = Place(current, touch); if(v2 == -1) { KillEdge(ei); - return true; + return false; } assert(v2 != v0 && v2 != v1); if(touch != front.end()) { //check for orientation and manifoldness - //if(!CheckEdge(v0, v2) || !CheckEdge(v2, v1)) { //touch == current.previous? if(v2 == previous.v0) { if(!CheckEdge(v2, v1)) { + fprintf(fp, "killing\n"); KillEdge(ei); - return 0; + return false; } /*touching previous FrontEdge (we reuse previous) next @@ -231,8 +230,9 @@ public: //touch == (*current.next).next } else if(v2 == next.v1) { if(!CheckEdge(v0, v2)) { + fprintf(fp, "killing\n"); KillEdge(ei); - return 0; + return false; } /*touching next FrontEdge (we reuse next) previous @@ -256,7 +256,7 @@ public: } else { if(!CheckEdge(v0, v2) || !CheckEdge(v2, v1)) { KillEdge(ei); - return 0; + return false; } //touching some loop: split (or merge it is local does not matter. //like this @@ -276,7 +276,7 @@ public: //this would be a really bad join if(v1 == (*right).v0 || v0 == (*left).v1) { KillEdge(ei); - return 0; + return false; } nb[v2]++; @@ -300,8 +300,8 @@ public: } else { - assert(CheckEdge(v0, v2)); - assert(CheckEdge(v2, v1)); +// assert(CheckEdge(v0, v2)); +// assert(CheckEdge(v2, v1)); /* adding a new vertex v2 @@ -328,7 +328,7 @@ public: } AddFace(v0, v2, v1); - return 1; + return false; } protected: diff --git a/vcg/complex/trimesh/create/ball_pivoting.h b/vcg/complex/trimesh/create/ball_pivoting.h index bd5cf442..01e81bf4 100644 --- a/vcg/complex/trimesh/create/ball_pivoting.h +++ b/vcg/complex/trimesh/create/ball_pivoting.h @@ -14,6 +14,8 @@ */ namespace vcg { namespace tri { + +FILE *fp; template <class MESH> class BallPivoting: public AdvancingFront<MESH> { public: @@ -53,6 +55,10 @@ template <class MESH> class BallPivoting: public AdvancingFront<MESH> { radius = sqrt((this->mesh.bbox.Diag()*this->mesh.bbox.Diag())/this->mesh.vn); else radius *= this->mesh.bbox.Diag()/100; + + fp = fopen("prova.txt", "wb+"); + fprintf(fp, "radius %lf\n", radius); + min_edge *= radius; max_edge *= radius; @@ -67,7 +73,11 @@ template <class MESH> class BallPivoting: public AdvancingFront<MESH> { std::vector<ScalarType> dists; usedBit = VertexType::NewBitFlag(); - + for(int i = 0; i < (int)this->mesh.vert.size(); i++) + this->mesh.vert[i].ClearUserBit(usedBit); + + UpdateFlags<MESH>::VertexClearV(this->mesh); + for(int i = 0; i < (int)this->mesh.face.size(); i++) { FaceType &f = this->mesh.face[i]; if(f.IsD()) continue; @@ -87,7 +97,7 @@ template <class MESH> class BallPivoting: public AdvancingFront<MESH> { VertexType::DeleteBitFlag(usedBit); } - bool Seed(int &v0, int &v1, int &v2) { + bool Seed(int &v0, int &v1, int &v2) { bool use_normals = false; //get a sphere of neighbours std::vector<VertexType *> targets; @@ -195,6 +205,7 @@ template <class MESH> class BallPivoting: public AdvancingFront<MESH> { //select a new vertex, mark as Visited and mark as usedBit all neighbours (less than min_edge) int Place(FrontEdge &edge, std::list<FrontEdge>::iterator &touch) { + fprintf(fp, "place front.size() %d\n", this->front.size()); Point3x v0 = this->mesh.vert[edge.v0].P(); Point3x v1 = this->mesh.vert[edge.v1].P(); Point3x v2 = this->mesh.vert[edge.v2].P(); @@ -301,6 +312,9 @@ template <class MESH> class BallPivoting: public AdvancingFront<MESH> { if(normal * newnormal < max_angle || this->nb[id] >= 2) { return -1; } + + fprintf(fp, "isB: %d\n", candidate->IsB()); + //test if id is in some border (to return touch for(list<FrontEdge>::iterator k = this->front.begin(); k != this->front.end(); k++) if((*k).v0 == id) touch = k; @@ -308,7 +322,7 @@ template <class MESH> class BallPivoting: public AdvancingFront<MESH> { if((*k).v0 == id) touch = k; //mark vertices close to candidate - Mark(candidate); + Mark(candidate); return id; }