Refactored crease_cut to correctly work with boundary creases

This commit is contained in:
Paolo Cignoni 2017-08-31 11:39:26 +02:00
parent d30bcfe4f3
commit c71321a3b6
1 changed files with 32 additions and 23 deletions

View File

@ -52,7 +52,7 @@ void CutMeshAlongNonFauxEdges(MESH_TYPE &m)
{ {
typedef typename MESH_TYPE::FaceIterator FaceIterator; typedef typename MESH_TYPE::FaceIterator FaceIterator;
typedef typename MESH_TYPE::FaceType FaceType; typedef typename MESH_TYPE::FaceType FaceType;
typedef typename face::Pos<FaceType> PosType;
tri::Allocator<MESH_TYPE>::CompactVertexVector(m); tri::Allocator<MESH_TYPE>::CompactVertexVector(m);
tri::Allocator<MESH_TYPE>::CompactFaceVector(m); tri::Allocator<MESH_TYPE>::CompactFaceVector(m);
tri::RequireFFAdjacency(m); tri::RequireFFAdjacency(m);
@ -68,37 +68,46 @@ void CutMeshAlongNonFauxEdges(MESH_TYPE &m)
{ {
(*fi).V(j)->SetV(); (*fi).V(j)->SetV();
face::JumpingPos<FaceType> iPos(&*fi,j,(*fi).V(j)); PosType startPos(&*fi,j,(*fi).V(j));
size_t vertInd = Index(m, iPos.V()); PosType curPos=startPos;
bool isBorderVertex = iPos.FindBorder(); // for border vertex we start from the border. bool borderVertexFlag=false; // on border vertex swe startfrom border edges (so we are sure that we cross the crease once)
face::JumpingPos<FaceType> startPos=iPos; do
if(!isBorderVertex) // for internal vertex we search the first crease and start from it
{ {
do { curPos.FlipF();curPos.FlipE();
bool creaseFlag = !iPos.IsFaux(); if(curPos.IsBorder()) {
iPos.NextFE(); borderVertexFlag=true;
if(creaseFlag) break; break;
} while (startPos!=iPos); }
startPos=iPos; // the found crease become the new starting pos. } while(curPos!=startPos);
}
assert(borderVertexFlag == curPos.IsBorder());
startPos=curPos;
if(!borderVertexFlag) // on internal vertex we start on creases.
{
do {
curPos.FlipF();curPos.FlipE();
if(!curPos.IsFaux())
break;
} while(curPos!=startPos);
startPos=curPos;
}
int locCreaseCounter=0; int locCreaseCounter=0;
int curVertexCounter=vertInd; int curVertexCounter= Index(m, curPos.V());
do { // The real Loop // The real Loop; we assume that if there is border we are starting from a border pos;
size_t faceInd = Index(m,iPos.F()); // the idea is that just before jumping on the next face, if we cross a crease, we increase the vertex counter.
indVec[faceInd*3+ iPos.VInd()] = curVertexCounter; do {
size_t faceInd = Index(m,curPos.F());
if(!iPos.IsFaux()) indVec[faceInd*3+ curPos.VInd()] = curVertexCounter;
curPos.FlipE();
if(!curPos.IsFaux())
{ //qDebug(" Crease FOUND"); { //qDebug(" Crease FOUND");
++locCreaseCounter; ++locCreaseCounter;
curVertexCounter=newVertexCounter; curVertexCounter=newVertexCounter;
newVertexCounter++; newVertexCounter++;
} }
iPos.NextFE(); curPos.FlipF();
} while (startPos!=iPos); } while (startPos!=curPos && !curPos.IsBorder());
if (locCreaseCounter > 0) newVertexCounter--;
//printf("For vertex %i found %i creases\n",vertInd,locCreaseCounter);
} }
} // end foreach face/vert } // end foreach face/vert