diff --git a/vcg/complex/algorithms/cut_tree.h b/vcg/complex/algorithms/cut_tree.h index ab89b626..abc1b5b2 100644 --- a/vcg/complex/algorithms/cut_tree.h +++ b/vcg/complex/algorithms/cut_tree.h @@ -61,7 +61,6 @@ void OptimizeTree(KdTree &kdtree, MeshType &t) { lastEn=t.en; tri::UpdateTopology::VertexEdge(t); - tri::UpdateTopology::VertexFace(base); // First simple loop that search for 2->1 moves. for(VertexIterator vi=t.vert.begin();vi!=t.vert.end();++vi) @@ -97,21 +96,14 @@ bool ExistEdge(KdTree &kdtree, CoordType &p0, CoordType &p1, PosType v1 = &base.vert[veInd]; if(v0 && v1) { - face::VFIterator vfi(v0); - while(!vfi.End()) - { - if(vfi.V1()==v1) - { - fpos = PosType(vfi.F(),vfi.I(), v0); - return true; - } - if(vfi.V2()==v1) - { - fpos = PosType(vfi.F(),(vfi.I()+1)%3, v1); - return true; - } - ++vfi; - } + fpos =PosType(v0->VFp(),v0); + assert(fpos.V()==v0); + PosType startPos=fpos; + do + { + fpos.FlipE(); fpos.FlipF(); + if(fpos.VFlip()== v1) return true; + } while(startPos!=fpos); } return false; } @@ -145,13 +137,13 @@ bool IsBoundaryVertexOnBase(KdTree &kdtree, const CoordType &p) /** * @brief Retract * @param t the edgemesh containing the visit tree. - * We assume that the vertexes + * */ void Retract(KdTree &kdtree, MeshType &t) { printf("Retracting a tree of %i edges and %i vertices\n",t.en,t.vn); tri::UpdateTopology::VertexEdge(t); - + tri::Allocator::CompactEveryVector(t); std::stack vertStack; // Put on the stack all the vertex with just a single incident edge. @@ -159,7 +151,7 @@ void Retract(KdTree &kdtree, MeshType &t) { std::vector starVec; edge::VEStarVE(&*vi,starVec); - if(starVec.size()==1 && !IsBoundaryVertexOnBase(kdtree, vi->cP())) + if(starVec.size()==1)// && !IsBoundaryVertexOnBase(kdtree, vi->cP())) vertStack.push(&*vi); } @@ -186,9 +178,22 @@ void Retract(KdTree &kdtree, MeshType &t) } } assert(unvisitedEdgeNum >0); - - for(size_t i =0; i::DeleteEdge(t,t.edge[i]); + for(size_t i =0; i::DeleteEdge(t,t.edge[i]) ; + } assert(t.en >0); tri::Clean::RemoveUnreferencedVertex(t); tri::Allocator::CompactEveryVector(t); @@ -198,7 +203,7 @@ void Retract(KdTree &kdtree, MeshType &t) // \brief This function build a cut tree. // // First we make a bread first FF face visit. -// Each time that we encounter a visited face we cut add to the tree the edge +// Each time that we encounter a visited face we add to the tree the edge // that brings to the already visited face. // this structure build a dense graph and we retract this graph retracting each // leaf until we remains with just the loops that cuts the object. @@ -206,6 +211,8 @@ void Retract(KdTree &kdtree, MeshType &t) void BuildVisitTree(MeshType &dualMesh, int startingFaceInd=0) { tri::UpdateTopology::FaceFace(base); + tri::UpdateTopology::VertexFace(base); + tri::UpdateFlags::FaceClearV(base); tri::UpdateFlags::VertexBorderFromFaceAdj(base); std::vector > visitStack; // the stack contain the pos on the 'starting' face. @@ -235,8 +242,7 @@ void BuildVisitTree(MeshType &dualMesh, int startingFaceInd=0) } else { - if(!c.IsBorder()) - tri::Allocator::AddEdge(dualMesh,c.V()->P(),c.VFlip()->P()); + tri::Allocator::AddEdge(dualMesh,c.V()->P(),c.VFlip()->P()); } } assert(cnt==base.fn); @@ -245,6 +251,8 @@ void BuildVisitTree(MeshType &dualMesh, int startingFaceInd=0) KdTree kdtree(vdw); tri::Clean::RemoveDuplicateVertex(dualMesh); +// tri::io::ExporterPLY::Save(dualMesh,"fulltree.ply",tri::io::Mask::IOM_EDGEINDEX); + Retract(kdtree,dualMesh); OptimizeTree(kdtree, dualMesh); tri::UpdateBounding::Box(dualMesh);