Refactored a bit CountConnectedComponents (added requiremens)

This commit is contained in:
Paolo Cignoni 2013-03-25 10:33:22 +00:00
parent 6913bc81a7
commit 668bf05a1d
1 changed files with 31 additions and 38 deletions
vcg/complex/algorithms

View File

@ -1066,17 +1066,12 @@ private:
static int ConnectedComponents(MeshType &m, std::vector< std::pair<int,FacePointer> > &CCV) static int ConnectedComponents(MeshType &m, std::vector< std::pair<int,FacePointer> > &CCV)
{ {
FaceIterator fi; tri::RequireFFAdjacency(m);
FacePointer l;
CCV.clear(); CCV.clear();
tri::UpdateSelection<MeshType>::FaceClear(m);
for(fi=m.face.begin();fi!=m.face.end();++fi)
(*fi).ClearS();
int Compindex=0;
std::stack<FacePointer> sf; std::stack<FacePointer> sf;
FacePointer fpt=&*(m.face.begin()); FacePointer fpt=&*(m.face.begin());
for(fi=m.face.begin();fi!=m.face.end();++fi) for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
{ {
if(!((*fi).IsD()) && !(*fi).IsS()) if(!((*fi).IsD()) && !(*fi).IsS())
{ {
@ -1092,7 +1087,7 @@ private:
{ {
if( !face::IsBorder(*fpt,j) ) if( !face::IsBorder(*fpt,j) )
{ {
l=fpt->FFp(j); FacePointer l = fpt->FFp(j);
if( !(*l).IsS() ) if( !(*l).IsS() )
{ {
(*l).SetS(); (*l).SetS();
@ -1101,11 +1096,9 @@ private:
} }
} }
} }
Compindex++;
} }
} }
assert(int(CCV.size())==Compindex); return int(CCV.size());
return Compindex;
} }