Redesigned the function for the removal of faces according to their area and edge lenght

This commit is contained in:
Paolo Cignoni 2006-05-16 21:51:07 +00:00
parent 740b84c8c6
commit b9cb941529
1 changed files with 63 additions and 15 deletions

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.38 2006/05/03 21:40:27 cignoni
Changed HasMark to HasPerFaceMark(m) and commented some unused internal vars of the class
Revision 1.37 2006/04/18 07:01:22 zifnab1974 Revision 1.37 2006/04/18 07:01:22 zifnab1974
added a ; how could this ever compile? added a ; how could this ever compile?
@ -381,28 +384,73 @@ private:
/* /*
This function remove faces that are geometrically degenerate The following functions remove faces that are geometrically "bad" according to edges and area criteria.
They remove the faces that are out of a given range of area or edges (e.g. faces too large or too small, or with edges too short or too long)
but that could be topologically correct. but that could be topologically correct.
These functions can optionally take into account only the selected faces.
*/ */
static int RemoveZeroAreaFace(MeshType& m, ScalarType epsilon=0) template<bool Selected>
static int RemoveFaceOutOfRangeAreaSel(MeshType& m, ScalarType MinAreaThr=0, ScalarType MaxAreaThr=numeric_limits<ScalarType>::max())
{ {
FaceIterator fi; FaceIterator fi;
int count_fd = 0; int count_fd = 0;
MinAreaThr*=2;
MaxAreaThr*=2;
for(fi=m.face.begin(); fi!=m.face.end();++fi) for(fi=m.face.begin(); fi!=m.face.end();++fi)
if(DoubleArea<FaceType>(*fi) <= epsilon) if(!(*fi).IsD())
if(!Selected || (*fi).IsS())
{
const ScalarType doubleArea=DoubleArea<FaceType>(*fi);
if((doubleArea<=MinAreaThr) || (doubleArea>=MaxAreaThr) )
{ {
count_fd++; count_fd++;
fi->SetD(); fi->SetD();
m.fn--; m.fn--;
} }
}
return count_fd;
}
template<bool Selected>
static int RemoveFaceOutOfRangeEdgeSel( MeshType& m, ScalarType MinEdgeThr=0, ScalarType MaxEdgeThr=numeric_limits<ScalarType>::max())
{
FaceIterator fi;
int count_fd = 0;
MinEdgeThr=MinEdgeThr*MinEdgeThr;
MaxEdgeThr=MaxEdgeThr*MaxEdgeThr;
for(fi=m.face.begin(); fi!=m.face.end();++fi)
if(!(*fi).IsD())
if(!Selected || (*fi).IsS())
{
for(unsigned int i=0;i<3;++i)
{
const ScalarType squaredEdge=SquaredDistance((*fi).V0(i)->cP(),(*fi).V1(i)->cP());
if((squaredEdge<=MinEdgeThr) || (squaredEdge>=MaxEdgeThr) )
{
count_fd++;
fi->SetD();
m.fn--;
break; // skip the rest of the edges of the tri
}
}
}
return count_fd; return count_fd;
} }
/** This function removes that are not referenced by any face. The function updates the vn counter. // alias for the old style. Kept for backward compatibility
@param m The mesh static int RemoveZeroAreaFace(MeshType& m) { return RemoveFaceOutOfRangeArea(m);}
@return The number of removed vertices
*/ // Aliases for the functions that do not look at selection
static int RemoveFaceOutOfRangeArea(MeshType& m, ScalarType MinAreaThr=0, ScalarType MaxAreaThr=numeric_limits<ScalarType>::max())
{
return RemoveFaceOutOfRangeArea<false>(m,MinAreaThr,MaxAreaThr);
}
static int RemoveFaceOutOfRangeEdge(MeshType& m, ScalarType MinEdgeThr=0, ScalarType MaxEdgeThr=numeric_limits<ScalarType>::max())
{
return RemoveFaceOutOfRangeEdgeSel<false>(m,MinEdgeThr,MaxEdgeThr);
}
static int ClipWithBox( MeshType & m, Box3Type &bb) static int ClipWithBox( MeshType & m, Box3Type &bb)