Improved polygonal support. Refactored convert tri to poly. Added support for face color and face quality
This commit is contained in:
parent
6e221cc7ab
commit
9de6cde470
|
@ -24,7 +24,6 @@
|
|||
#ifndef __VCGLIB_POLYGON_SUPPORT
|
||||
#define __VCGLIB_POLYGON_SUPPORT
|
||||
|
||||
#include <vector>
|
||||
#include <vcg/simplex/face/jumping_pos.h>
|
||||
#include <vcg/space/planar_polygon_tessellation.h>
|
||||
|
||||
|
@ -49,7 +48,8 @@ namespace tri {
|
|||
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){
|
||||
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;
|
||||
|
@ -69,7 +69,8 @@ namespace tri {
|
|||
/**
|
||||
Import a trianglemesh from a polygon mesh
|
||||
**/
|
||||
static void ImportFromPolyMesh(TriMeshType & tm, PolyMeshType & pm){
|
||||
static void ImportFromPolyMesh(TriMeshType & tm, PolyMeshType & pm)
|
||||
{
|
||||
std::vector<typename PolyMeshType::CoordType> points;
|
||||
std::vector<int> faces;
|
||||
|
||||
|
@ -108,57 +109,38 @@ namespace tri {
|
|||
|
||||
|
||||
/**
|
||||
Import a polygon mesh from a triangle mesh
|
||||
**/
|
||||
static void ImportFromTriMesh( PolyMeshType & pm, TriMeshType & tm){
|
||||
\brief Import a polygon mesh from a triangle mesh
|
||||
|
||||
It assumes that the mesh has the faux edges bit set for a polygonal mesh and that have the FFAdjacency already computed.
|
||||
**/
|
||||
static void ImportFromTriMesh( PolyMeshType & pm, TriMeshType & tm)
|
||||
{
|
||||
vcg::tri::RequireCompactness(tm);
|
||||
vcg::tri::RequireFFAdjacency(tm);
|
||||
vcg::tri::UpdateFlags<TriMeshType>::FaceClearV(tm);
|
||||
// the vertices are the same, simply import them
|
||||
int cnt = 0;
|
||||
typename TriMeshType ::ConstVertexIterator tvi;
|
||||
typename PolyMeshType::VertexIterator vi = vcg::tri::Allocator<PolyMeshType>::AddVertices(pm,tm.vert.size());
|
||||
for(tvi = tm.vert.begin(); tvi != tm.vert.end(); ++tvi,++vi,++cnt)
|
||||
if(!(*tvi).IsD())(*vi).ImportData(*tvi); else vcg::tri::Allocator<PolyMeshType> ::DeleteVertex(pm,(*vi));
|
||||
(*vi).ImportData(*tvi);
|
||||
|
||||
// convert the faces
|
||||
typename TriMeshType::FaceIterator tfi;
|
||||
vcg::face::JumpingPos<typename TriMeshType::FaceType> p;
|
||||
|
||||
for( tfi = tm.face.begin(); tfi != tm.face.end(); ++tfi) if(!(*tfi).IsD() && !(*tfi).IsV())
|
||||
for( tfi = tm.face.begin(); tfi != tm.face.end(); ++tfi) if(!(*tfi).IsV())
|
||||
{
|
||||
std::vector<typename TriMeshType::VertexPointer> vs;// vertices of the polygon
|
||||
std::vector<typename TriMeshType::FacePointer> fs;// triangle faces corresponding to the polygon
|
||||
|
||||
|
||||
// find a non tagged edge
|
||||
int se = 0;
|
||||
for(;se < 3;++se) if (!(*tfi).IsF(se)) break;
|
||||
|
||||
// initialize a pos on the first non tagged edge
|
||||
typename TriMeshType::VertexPointer v0 = (*tfi).V(se);
|
||||
p.F() = &(*tfi);
|
||||
p.E() = se;
|
||||
p.V() = p.F()->V(p.F()->Next(se));
|
||||
p.FlipE();
|
||||
|
||||
vs.push_back(p.F()->V(se));
|
||||
|
||||
do{
|
||||
while(p.F()->IsF(p.E())) { fs.push_back(p.F()); p.FlipF(); p.FlipE(); p.F()->SetV();}
|
||||
vs.push_back(p.F()->V(p.E()));
|
||||
p.FlipV();
|
||||
p.FlipE();
|
||||
} while( p.V() != v0 );
|
||||
|
||||
ExtractPolygon(&*tfi,vs);
|
||||
std::reverse(vs.begin(),vs.end());
|
||||
//now vs contains all the vertices of the polygon (still in the trimesh)
|
||||
typename PolyMeshType::FaceIterator pfi = vcg::tri::Allocator<PolyMeshType>::AddFaces(pm,1);
|
||||
(*pfi).Alloc(vs.size());
|
||||
for(size_t i = 0 ; i < vs.size(); ++i)
|
||||
(*pfi).V(i) = ( typename PolyMeshType::VertexType*) & pm.vert[vs[i]-&(*tm.vert.begin())];
|
||||
// here handle the other compoenents of the face (how the conponents of the n triangle faces goes in the
|
||||
// the property of the polygon (e.g. the normal, the color, the quality and so on)
|
||||
// TODO
|
||||
|
||||
if(tri::HasPerFaceColor(tm) && tri::HasPerFaceColor(pm)) pfi->C()=tfi->C();
|
||||
if(tri::HasPerFaceQuality(tm) && tri::HasPerFaceQuality(pm)) pfi->Q()=tfi->Q();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue