added method MergeFlatFaces (does what it says). Plus clean-ups.

This commit is contained in:
mtarini 2012-07-18 21:46:12 +00:00
parent 45b0deb7eb
commit 240b88a582
1 changed files with 108 additions and 88 deletions

View File

@ -29,8 +29,7 @@
#include <vcg/simplex/face/jumping_pos.h> #include <vcg/simplex/face/jumping_pos.h>
#include <vcg/space/planar_polygon_tessellation.h> #include <vcg/space/planar_polygon_tessellation.h>
namespace vcg namespace vcg {
{
namespace tri { namespace tri {
/// \ingroup trimesh /// \ingroup trimesh
@ -47,6 +46,27 @@ namespace vcg
template <class TriMeshType,class PolyMeshType > template <class TriMeshType,class PolyMeshType >
struct PolygonSupport{ struct PolygonSupport{
/**
Given a tri mesh (with per-face normals and FF connectivity),
merges flat faces into larger polygons.
**/
static void MergeFlatFaces(TriMeshType & tm, double tolerance = 0.1E-4){
typedef typename TriMeshType::CoordType::ScalarType Scalar;
typedef typename TriMeshType::FaceIterator FaceIterator;
typedef typename TriMeshType::FaceType FaceType;
Scalar minDist = 1 - Scalar(tolerance);
for (FaceIterator fi=tm.face.begin(); fi!=tm.face.end(); fi++) {
FaceType *fa = &*fi;
for (int w=0; w<3; w++) {
FaceType *fb = fa->FFp(w);
if ( (fb>fa) && (fa->N()*fb->N() > minDist) ) {
fa->SetF( w );
fb->SetF( fa->FFi(w) ); // reciprocate
}
}
}
}
/** /**
Import a trianglemesh from a polygon mesh Import a trianglemesh from a polygon mesh
**/ **/