Corrected bugs in cut tree retraction for meshes with boundaries

This commit is contained in:
Paolo Cignoni 2017-08-31 08:44:15 +02:00
parent babd1de3fc
commit d30bcfe4f3
1 changed files with 28 additions and 9 deletions

View File

@ -53,7 +53,7 @@ public:
CutTree(MeshType &_m) :base(_m){} CutTree(MeshType &_m) :base(_m){}
void OptimizeTree(MeshType &t) void OptimizeTree(KdTree<ScalarType> &kdtree, MeshType &t)
{ {
tri::Allocator<MeshType>::CompactEveryVector(t); tri::Allocator<MeshType>::CompactEveryVector(t);
int lastEn=t.en; int lastEn=t.en;
@ -62,8 +62,6 @@ void OptimizeTree(MeshType &t)
lastEn=t.en; lastEn=t.en;
tri::UpdateTopology<MeshType>::VertexEdge(t); tri::UpdateTopology<MeshType>::VertexEdge(t);
tri::UpdateTopology<MeshType>::VertexFace(base); tri::UpdateTopology<MeshType>::VertexFace(base);
VertexConstDataWrapper<MeshType > vdw(base);
KdTree<ScalarType> kdtree(vdw);
// First simple loop that search for 2->1 moves. // First simple loop that search for 2->1 moves.
for(VertexIterator vi=t.vert.begin();vi!=t.vert.end();++vi) for(VertexIterator vi=t.vert.begin();vi!=t.vert.end();++vi)
@ -133,7 +131,23 @@ int findNonVisitedEdgesDuringRetract(VertexType * vp, EdgeType * &ep)
return cnt; return cnt;
} }
void Retract(MeshType &t) bool IsBoundaryVertexOnBase(KdTree<ScalarType> &kdtree, const CoordType &p)
{
VertexType *v0=0;
unsigned int veInd;
ScalarType sqdist;
kdtree.doQueryClosest(p,veInd,sqdist);
if(sqdist>0) { assert(0); }
v0 = &base.vert[veInd];
return v0->IsB();
}
/**
* @brief Retract
* @param t the edgemesh containing the visit tree.
* We assume that the vertexes
*/
void Retract(KdTree<ScalarType> &kdtree, MeshType &t)
{ {
printf("Retracting a tree of %i edges and %i vertices\n",t.en,t.vn); printf("Retracting a tree of %i edges and %i vertices\n",t.en,t.vn);
tri::UpdateTopology<MeshType>::VertexEdge(t); tri::UpdateTopology<MeshType>::VertexEdge(t);
@ -145,10 +159,10 @@ void Retract(MeshType &t)
{ {
std::vector<EdgeType *> starVec; std::vector<EdgeType *> starVec;
edge::VEStarVE(&*vi,starVec); edge::VEStarVE(&*vi,starVec);
if(starVec.size()==1) if(starVec.size()==1 && !IsBoundaryVertexOnBase(kdtree, vi->cP()))
vertStack.push(&*vi); vertStack.push(&*vi);
} }
tri::UpdateFlags<MeshType>::EdgeClearV(t); tri::UpdateFlags<MeshType>::EdgeClearV(t);
tri::UpdateFlags<MeshType>::VertexClearV(t); tri::UpdateFlags<MeshType>::VertexClearV(t);
@ -193,6 +207,7 @@ void BuildVisitTree(MeshType &dualMesh, int startingFaceInd=0)
{ {
tri::UpdateTopology<MeshType>::FaceFace(base); tri::UpdateTopology<MeshType>::FaceFace(base);
tri::UpdateFlags<MeshType>::FaceClearV(base); tri::UpdateFlags<MeshType>::FaceClearV(base);
tri::UpdateFlags<MeshType>::VertexBorderFromFaceAdj(base);
std::vector<face::Pos<FaceType> > visitStack; // the stack contain the pos on the 'starting' face. std::vector<face::Pos<FaceType> > visitStack; // the stack contain the pos on the 'starting' face.
base.face[startingFaceInd].SetV(); base.face[startingFaceInd].SetV();
@ -220,14 +235,18 @@ void BuildVisitTree(MeshType &dualMesh, int startingFaceInd=0)
} }
else else
{ {
tri::Allocator<MeshType>::AddEdge(dualMesh,c.V()->P(),c.VFlip()->P()); if(!c.IsBorder())
tri::Allocator<MeshType>::AddEdge(dualMesh,c.V()->P(),c.VFlip()->P());
} }
} }
assert(cnt==base.fn); assert(cnt==base.fn);
VertexConstDataWrapper<MeshType > vdw(base);
KdTree<ScalarType> kdtree(vdw);
tri::Clean<MeshType>::RemoveDuplicateVertex(dualMesh); tri::Clean<MeshType>::RemoveDuplicateVertex(dualMesh);
Retract(dualMesh); Retract(kdtree,dualMesh);
OptimizeTree(dualMesh); OptimizeTree(kdtree, dualMesh);
tri::UpdateBounding<MeshType>::Box(dualMesh); tri::UpdateBounding<MeshType>::Box(dualMesh);
} }