From 3449199f07aa34bc266c4337668a74418fee9d69 Mon Sep 17 00:00:00 2001 From: "T.Alderighi" Date: Thu, 16 Jan 2020 18:36:41 +0100 Subject: [PATCH] added splitinmanifoldComponents --- vcg/complex/algorithms/clean.h | 57 +++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/vcg/complex/algorithms/clean.h b/vcg/complex/algorithms/clean.h index 052405a3..67cf0c7e 100644 --- a/vcg/complex/algorithms/clean.h +++ b/vcg/complex/algorithms/clean.h @@ -33,6 +33,7 @@ #include #include #include +#include namespace vcg { namespace tri{ @@ -634,7 +635,8 @@ public: do { faceSet.insert(std::make_pair(curPos.F(),curPos.VInd())); - curPos.NextE(); + curPos.FlipE(); + curPos.NextF(); } while (curPos != startPos); ToSplitVec.push_back(make_pair((*fi).V(i),std::vector())); @@ -671,6 +673,59 @@ public: return int(ToSplitVec.size()); } + /// \brief This function expand current selection to cover the whole connected component. + static size_t SplitManifoldComponents(MeshType &m) + { + typedef typename MeshType::FacePointer FacePointer; + typedef typename MeshType::FaceIterator FaceIterator; + // it also assumes that the FF adjacency is well computed. + RequireFFAdjacency(m); + + UpdateFlags::FaceClearV(m); + UpdateFlags::FaceClearS(m); + + MeshType tmpMesh; + + size_t selCnt=0; + + for(FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) + if( !(*fi).IsD() && !(*fi).IsV() ) + { + UpdateFlags::FaceClearS(m); + + std::deque visitStack; + visitStack.push_back(&*fi); + + while(!visitStack.empty()) + { + FacePointer fp = visitStack.front(); + visitStack.pop_front(); + + fp->Q() = selCnt; + fp->SetS(); + + assert(!fp->IsV()); + fp->SetV(); + + for(int i=0;iVN();++i) { + FacePointer ff = fp->FFp(i); + + if(face::IsManifold(*fp, i) && !ff->IsS()) + { + visitStack.push_back(ff); + assert(!ff->IsV()); + } + } + } + Append::Mesh(tmpMesh, m, true); + ++selCnt; + } + + UpdateSelection::Clear(tmpMesh); + Append::MeshCopy(m, tmpMesh); + return selCnt; + } + // Auxiliary function for sorting the non manifold faces according to their area. Used in RemoveNonManifoldFace struct CompareAreaFP {