Refactored selection face from vertices algorithms and added requiremnts for triangular mesh for the algorithm selecting vertices starting from face border flag

This commit is contained in:
Paolo Cignoni 2014-02-19 14:38:54 +00:00
parent 85c5274965
commit 18c0ac1681
1 changed files with 91 additions and 95 deletions

View File

@ -145,48 +145,48 @@ typedef typename vcg::Box3<ScalarType> Box3Type;
static size_t VertexAll(MeshType &m)
{
VertexIterator vi;
for(vi = m.vert.begin(); vi != m.vert.end(); ++vi)
if( !(*vi).IsD() ) (*vi).SetS();
VertexIterator vi;
for(vi = m.vert.begin(); vi != m.vert.end(); ++vi)
if( !(*vi).IsD() ) (*vi).SetS();
return m.vn;
}
static size_t EdgeAll(MeshType &m)
{
EdgeIterator ei;
for(ei = m.edge.begin(); ei != m.edge.end(); ++ei)
if( !(*ei).IsD() ) (*ei).SetS();
EdgeIterator ei;
for(ei = m.edge.begin(); ei != m.edge.end(); ++ei)
if( !(*ei).IsD() ) (*ei).SetS();
return m.fn;
}
static size_t FaceAll(MeshType &m)
{
FaceIterator fi;
for(fi = m.face.begin(); fi != m.face.end(); ++fi)
if( !(*fi).IsD() ) (*fi).SetS();
FaceIterator fi;
for(fi = m.face.begin(); fi != m.face.end(); ++fi)
if( !(*fi).IsD() ) (*fi).SetS();
return m.fn;
}
static size_t VertexClear(MeshType &m)
{
VertexIterator vi;
for(vi = m.vert.begin(); vi != m.vert.end(); ++vi)
if( !(*vi).IsD() ) (*vi).ClearS();
VertexIterator vi;
for(vi = m.vert.begin(); vi != m.vert.end(); ++vi)
if( !(*vi).IsD() ) (*vi).ClearS();
return 0;
}
static size_t EdgeClear(MeshType &m)
{
EdgeIterator ei;
for(ei = m.edge.begin(); ei != m.edge.end(); ++ei)
if( !(*ei).IsD() ) (*ei).ClearS();
EdgeIterator ei;
for(ei = m.edge.begin(); ei != m.edge.end(); ++ei)
if( !(*ei).IsD() ) (*ei).ClearS();
return 0;
}
static size_t FaceClear(MeshType &m)
{
FaceIterator fi;
for(fi = m.face.begin(); fi != m.face.end(); ++fi)
if( !(*fi).IsD() ) (*fi).ClearS();
FaceIterator fi;
for(fi = m.face.begin(); fi != m.face.end(); ++fi)
if( !(*fi).IsD() ) (*fi).ClearS();
return 0;
}
@ -200,7 +200,7 @@ static void Clear(MeshType &m)
static size_t FaceCount(MeshType &m)
{
size_t selCnt=0;
FaceIterator fi;
FaceIterator fi;
for(fi=m.face.begin();fi!=m.face.end();++fi)
if(!(*fi).IsD() && (*fi).IsS()) ++selCnt;
return selCnt;
@ -218,7 +218,7 @@ static size_t EdgeCount(MeshType &m)
static size_t VertexCount(MeshType &m)
{
size_t selCnt=0;
VertexIterator vi;
VertexIterator vi;
for(vi=m.vert.begin();vi!=m.vert.end();++vi)
if(!(*vi).IsD() && (*vi).IsS()) ++selCnt;
return selCnt;
@ -227,7 +227,7 @@ static size_t VertexCount(MeshType &m)
static size_t FaceInvert(MeshType &m)
{
size_t selCnt=0;
FaceIterator fi;
FaceIterator fi;
for(fi=m.face.begin();fi!=m.face.end();++fi)
if(!(*fi).IsD())
{
@ -243,7 +243,7 @@ static size_t FaceInvert(MeshType &m)
static size_t VertexInvert(MeshType &m)
{
size_t selCnt=0;
VertexIterator vi;
VertexIterator vi;
for(vi=m.vert.begin();vi!=m.vert.end();++vi)
if(!(*vi).IsD())
{
@ -303,16 +303,15 @@ static size_t VertexFromFaceStrict(MeshType &m)
static size_t FaceFromVertexStrict(MeshType &m)
{
size_t selCnt=0;
int i=0;
FaceClear(m);
FaceIterator fi;
for(fi = m.face.begin(); fi != m.face.end(); ++fi)
FaceClear(m);
for(FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi)
if( !(*fi).IsD())
{
for(i = 0; i < (*fi).VN(); ++i)
bool selFlag=true;
for(int i = 0; i < (*fi).VN(); ++i)
if(!(*fi).V(i)->IsS())
break;
if(i == (*fi).VN())
selFlag =false;
if(selFlag)
{
(*fi).SetS();
++selCnt;
@ -325,17 +324,15 @@ static size_t FaceFromVertexStrict(MeshType &m)
static size_t FaceFromVertexLoose(MeshType &m)
{
size_t selCnt=0;
int i=0;
FaceClear(m);
FaceIterator fi;
for(fi = m.face.begin(); fi != m.face.end(); ++fi)
if( !(*fi).IsD() && !(*fi).IsS())
FaceClear(m);
for(FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi)
if( !(*fi).IsD())
{
bool selVert=false;
for(int i = 0; i < (*fi).VN(); ++i)
if((*fi).V(i)->IsS())
break;
if(i < (*fi).VN())
{
if((*fi).V(i)->IsS()) selVert=true;
if(selVert) {
(*fi).SetS();
++selCnt;
}
@ -363,17 +360,16 @@ static size_t VertexFromBorderFlag(MeshType &m)
static size_t FaceFromBorderFlag(MeshType &m)
{
tri::RequireTriangularMesh(m);
size_t selCnt=0;
int i=0;
FaceClear(m);
FaceIterator fi;
for(fi = m.face.begin(); fi != m.face.end(); ++fi)
if( !(*fi).IsD() )
FaceClear(m);
for(FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi)
if( !(*fi).IsD() )
{
for(int i = 0; i < (*fi).VN(); ++i)
if((*fi).IsB(i))
break;
if(i < (*fi).VN())
bool bordFlag=false;
for(int i = 0; i < 3; ++i)
if((*fi).IsB(i)) bordFlag=true;
if(bordFlag)
{
(*fi).SetS();
++selCnt;
@ -409,32 +405,32 @@ static size_t FaceOutOfRangeEdge(MeshType &m, ScalarType MinEdgeThr=0, ScalarTyp
/// \brief This function expand current selection to cover the whole connected component.
static size_t FaceConnectedFF(MeshType &m)
{
// it also assumes that the FF adjacency is well computed.
assert (HasFFAdjacency(m));
UpdateFlags<MeshType>::FaceClearV(m);
// it also assumes that the FF adjacency is well computed.
assert (HasFFAdjacency(m));
UpdateFlags<MeshType>::FaceClearV(m);
std::deque<FacePointer> visitStack;
std::deque<FacePointer> visitStack;
size_t selCnt=0;
FaceIterator fi;
for(fi = m.face.begin(); fi != m.face.end(); ++fi)
if( !(*fi).IsD() && (*fi).IsS() && !(*fi).IsV() )
visitStack.push_back(&*fi);
for(fi = m.face.begin(); fi != m.face.end(); ++fi)
if( !(*fi).IsD() && (*fi).IsS() && !(*fi).IsV() )
visitStack.push_back(&*fi);
while(!visitStack.empty())
while(!visitStack.empty())
{
FacePointer fp = visitStack.front();
visitStack.pop_front();
assert(!fp->IsV());
fp->SetV();
FacePointer fp = visitStack.front();
visitStack.pop_front();
assert(!fp->IsV());
fp->SetV();
for(int i=0;i<fp->VN();++i) {
FacePointer ff = fp->FFp(i);
FacePointer ff = fp->FFp(i);
if(! ff->IsS())
{
ff->SetS();
++selCnt;
visitStack.push_back(ff);
assert(!ff->IsV());
}
{
ff->SetS();
++selCnt;
visitStack.push_back(ff);
assert(!ff->IsV());
}
}
}
return selCnt;
@ -463,16 +459,16 @@ static size_t VertexFromQualityRange(MeshType &m,float minq, float maxq)
{
size_t selCnt=0;
VertexClear(m);
VertexIterator vi;
assert(HasPerVertexQuality(m));
VertexIterator vi;
assert(HasPerVertexQuality(m));
for(vi=m.vert.begin();vi!=m.vert.end();++vi)
if(!(*vi).IsD())
{
if( (*vi).Q()>=minq && (*vi).Q()<=maxq )
{
(*vi).SetS();
++selCnt;
}
{
(*vi).SetS();
++selCnt;
}
}
return selCnt;
}