From bc07762ab582536becfdd50df78d239ce780ae18 Mon Sep 17 00:00:00 2001 From: Paolo Cignoni Date: Sun, 2 Apr 2017 01:27:06 +0200 Subject: [PATCH] Moved and refactored SelectVertexCornerBorder from UpdateFlags to UpdateSelection Added also erode and dilate --- vcg/complex/algorithms/update/flag.h | 31 +-------------- vcg/complex/algorithms/update/selection.h | 47 ++++++++++++++++++++++- 2 files changed, 46 insertions(+), 32 deletions(-) diff --git a/vcg/complex/algorithms/update/flag.h b/vcg/complex/algorithms/update/flag.h index 98f8e673..359d3256 100644 --- a/vcg/complex/algorithms/update/flag.h +++ b/vcg/complex/algorithms/update/flag.h @@ -441,36 +441,7 @@ public: FaceFauxSignedCrease(m,-AngleRad,AngleRad); } - /// \brief Select the border vertices that form a corner along the boder - /// with an angle that is below a certain threshold - static void SelectVertexCornerBorder(MeshType &m,typename MeshType::ScalarType &angleRad) - { - typedef typename MeshType::ScalarType ScalarType; - - //get corner vertices - typename MeshType::template PerVertexAttributeHandle angleSumH = tri::Allocator:: template GetPerVertexAttribute (m); - - for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi) - angleSumH[vi]=0; - - for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi) - { - for(int i=0;i<(*fi).VN();++i) - { - typename MeshType::CoordType P0=fi->P(i); - typename MeshType::CoordType P1=fi->P((i+1)%(*fi).VN()); - typename MeshType::CoordType P2=fi->P((i+2)%(*fi).VN()); - angleSumH[fi->V(i)] += vcg::Angle(P2 - P0,P1 - P0); - } - } - - for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi) - { - if(angleSumH[vi]IsB()) - (*vi).SetS(); - } - } - + }; // end class } // End namespace tri diff --git a/vcg/complex/algorithms/update/selection.h b/vcg/complex/algorithms/update/selection.h index 1fefe694..7f6b4e81 100644 --- a/vcg/complex/algorithms/update/selection.h +++ b/vcg/complex/algorithms/update/selection.h @@ -373,6 +373,22 @@ static size_t FaceFromVertexLoose(MeshType &m, bool preserveSelection=false) } return selCnt; } +/// \brief This function dilate the face selection by simply first selecting all the vertices touched by the faces and then all the faces touched by these vertices +/// Note: it destroys the vertex selection. +static size_t FaceDilate(MeshType &m) +{ + tri::UpdateSelection::VertexFromFaceLoose(m); + return tri::UpdateSelection::FaceFromVertexLoose(m); +} + +/// \brief This function erode the face selection by simply first selecting only the vertices completely surrounded by face and then the only faces with all the selected vertices +/// Note: it destroys the vertex selection. +static size_t FaceErode(MeshType &m) +{ + tri::UpdateSelection::VertexFromFaceStrict(m); + return tri::UpdateSelection::FaceFromVertexStrict(m); +} + /// \brief This function select the vertices with the border flag set static size_t VertexFromBorderFlag(MeshType &m, bool preserveSelection=false) @@ -506,7 +522,7 @@ static size_t VertexFromQualityRange(MeshType &m,float minq, float maxq, bool pr } /// \brief Select the vertices contained in the specified Box -static int VertexInBox( MeshType & m, const Box3Type &bb, bool preserveSelection=false) +static size_t VertexInBox( MeshType & m, const Box3Type &bb, bool preserveSelection=false) { if(!preserveSelection) VertexClear(m); int selCnt=0; @@ -520,10 +536,37 @@ static int VertexInBox( MeshType & m, const Box3Type &bb, bool preserveSelection return selCnt; } +/// \brief Select the border vertices that form a corner along the border +/// with an angle that is below a certain threshold (e.g. with 90 will select all the acute angles) +static size_t VertexCornerBorder(MeshType &m, ScalarType angleRad, bool preserveSelection=false) +{ + if(!preserveSelection) VertexClear(m); + SimpleTempData angleSumH(m.vert,0); + int selCnt=0; + for(auto vi=m.vert.begin();vi!=m.vert.end();++vi) if(!(*vi).IsD()) + angleSumH[vi]=0; + + for(auto fi=m.face.begin();fi!=m.face.end();++fi) if(!(*fi).IsD()) + { + for(int i=0;i<(*fi).VN();++i) + angleSumH[fi->V(i)] += face::WedgeAngleRad(*fi,i); + } + + for(auto vi=m.vert.begin();vi!=m.vert.end();++vi) if(!(*vi).IsD()) + { + if(angleSumH[vi]IsB()) + { + (*vi).SetS(); + ++selCnt; + } + } + return selCnt; +} + void VertexNonManifoldEdges(MeshType &m, bool preserveSelection=false) { - assert(HasFFTopology(m)); + tri::RequireFFAdjacency(m); if(!preserveSelection) VertexClear(m); for (FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) if (!fi->IsD())