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
vcg/complex/algorithms
|
@ -24,7 +24,6 @@
|
||||||
#ifndef __VCGLIB_POLYGON_SUPPORT
|
#ifndef __VCGLIB_POLYGON_SUPPORT
|
||||||
#define __VCGLIB_POLYGON_SUPPORT
|
#define __VCGLIB_POLYGON_SUPPORT
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#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>
|
||||||
|
|
||||||
|
@ -49,7 +48,8 @@ namespace tri {
|
||||||
Given a tri mesh (with per-face normals and FF connectivity),
|
Given a tri mesh (with per-face normals and FF connectivity),
|
||||||
merges flat faces into larger polygons.
|
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::CoordType::ScalarType Scalar;
|
||||||
typedef typename TriMeshType::FaceIterator FaceIterator;
|
typedef typename TriMeshType::FaceIterator FaceIterator;
|
||||||
typedef typename TriMeshType::FaceType FaceType;
|
typedef typename TriMeshType::FaceType FaceType;
|
||||||
|
@ -69,7 +69,8 @@ namespace tri {
|
||||||
/**
|
/**
|
||||||
Import a trianglemesh from a polygon mesh
|
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<typename PolyMeshType::CoordType> points;
|
||||||
std::vector<int> faces;
|
std::vector<int> faces;
|
||||||
|
|
||||||
|
@ -108,57 +109,38 @@ namespace tri {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Import a polygon mesh from a triangle mesh
|
\brief Import a polygon mesh from a triangle mesh
|
||||||
**/
|
|
||||||
static void ImportFromTriMesh( PolyMeshType & pm, TriMeshType & tm){
|
|
||||||
|
|
||||||
|
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);
|
vcg::tri::UpdateFlags<TriMeshType>::FaceClearV(tm);
|
||||||
// the vertices are the same, simply import them
|
// the vertices are the same, simply import them
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
typename TriMeshType ::ConstVertexIterator tvi;
|
typename TriMeshType ::ConstVertexIterator tvi;
|
||||||
typename PolyMeshType::VertexIterator vi = vcg::tri::Allocator<PolyMeshType>::AddVertices(pm,tm.vert.size());
|
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)
|
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
|
// convert the faces
|
||||||
typename TriMeshType::FaceIterator tfi;
|
typename TriMeshType::FaceIterator tfi;
|
||||||
vcg::face::JumpingPos<typename TriMeshType::FaceType> p;
|
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::VertexPointer> vs;// vertices of the polygon
|
||||||
std::vector<typename TriMeshType::FacePointer> fs;// triangle faces corresponding to the polygon
|
ExtractPolygon(&*tfi,vs);
|
||||||
|
std::reverse(vs.begin(),vs.end());
|
||||||
|
|
||||||
// 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 );
|
|
||||||
|
|
||||||
//now vs contains all the vertices of the polygon (still in the trimesh)
|
//now vs contains all the vertices of the polygon (still in the trimesh)
|
||||||
typename PolyMeshType::FaceIterator pfi = vcg::tri::Allocator<PolyMeshType>::AddFaces(pm,1);
|
typename PolyMeshType::FaceIterator pfi = vcg::tri::Allocator<PolyMeshType>::AddFaces(pm,1);
|
||||||
(*pfi).Alloc(vs.size());
|
(*pfi).Alloc(vs.size());
|
||||||
for(size_t i = 0 ; i < vs.size(); ++i)
|
for(size_t i = 0 ; i < vs.size(); ++i)
|
||||||
(*pfi).V(i) = ( typename PolyMeshType::VertexType*) & pm.vert[vs[i]-&(*tm.vert.begin())];
|
(*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
|
if(tri::HasPerFaceColor(tm) && tri::HasPerFaceColor(pm)) pfi->C()=tfi->C();
|
||||||
// the property of the polygon (e.g. the normal, the color, the quality and so on)
|
if(tri::HasPerFaceQuality(tm) && tri::HasPerFaceQuality(pm)) pfi->Q()=tfi->Q();
|
||||||
// TODO
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue