Moved and refactored SelectVertexCornerBorder from UpdateFlags to UpdateSelection

Added also erode and dilate
This commit is contained in:
Paolo Cignoni 2017-04-02 01:27:06 +02:00
parent 16369d6006
commit bc07762ab5
2 changed files with 46 additions and 32 deletions

View File

@ -441,35 +441,6 @@ 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<ScalarType> angleSumH = tri::Allocator<MeshType>:: template GetPerVertexAttribute<ScalarType> (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]<angleRad && vi->IsB())
(*vi).SetS();
}
}
}; // end class

View File

@ -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<MeshType>::VertexFromFaceLoose(m);
return tri::UpdateSelection<MeshType>::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<MeshType>::VertexFromFaceStrict(m);
return tri::UpdateSelection<MeshType>::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<typename MeshType::VertContainer, ScalarType > 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]<angleRad && 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())