2008-12-19 16:36:15 +01:00
|
|
|
/****************************************************************************
|
2012-10-09 10:43:35 +02:00
|
|
|
* VCGLib o o *
|
|
|
|
* Visual and Computer Graphics Library o o *
|
|
|
|
* _ O _ *
|
|
|
|
* Copyright(C) 2004-2012 \/)\/ *
|
|
|
|
* Visual Computing Lab /\/| *
|
|
|
|
* ISTI - Italian National Research Council | *
|
|
|
|
* \ *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
|
|
|
* for more details. *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
2008-12-19 16:36:15 +01:00
|
|
|
|
2011-04-01 19:07:57 +02:00
|
|
|
#include <vcg/complex/complex.h>
|
2008-12-19 16:36:15 +01:00
|
|
|
|
|
|
|
/*include the algorithms for updating: */
|
2012-10-09 10:43:35 +02:00
|
|
|
#include <vcg/complex/algorithms/update/topology.h>
|
|
|
|
#include <vcg/complex/algorithms/update/bounding.h>
|
|
|
|
#include <vcg/complex/algorithms/update/normal.h>
|
2008-12-19 16:36:15 +01:00
|
|
|
|
|
|
|
/*include the algorithms for mesh fixing */
|
2011-04-01 19:07:57 +02:00
|
|
|
#include <vcg/complex/algorithms/clean.h>
|
2008-12-19 16:36:15 +01:00
|
|
|
|
|
|
|
#include <wrap/io_trimesh/import.h>
|
|
|
|
#include <wrap/io_trimesh/export_ply.h>
|
|
|
|
|
|
|
|
/* include the support for polygon meshes (function to convert from/to trimesh)*/
|
2011-04-01 19:07:57 +02:00
|
|
|
#include <vcg/complex/algorithms/polygon_support.h>
|
2008-12-19 16:36:15 +01:00
|
|
|
|
|
|
|
/* include the support for polygon meshes (the component for the face )*/
|
|
|
|
#include <vcg/simplex/face/component_polygon.h>
|
|
|
|
|
|
|
|
/* include the support for half edges */
|
2011-04-01 19:07:57 +02:00
|
|
|
#include <vcg/complex/algorithms/update/halfedge_indexed.h>
|
2008-12-19 16:36:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
using namespace vcg;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
// forward declarations
|
|
|
|
class CFace;
|
|
|
|
class CVertex;
|
2010-03-25 17:47:03 +01:00
|
|
|
class CHEdge;
|
2010-04-30 11:42:52 +02:00
|
|
|
class CEdge;
|
2008-12-19 16:36:15 +01:00
|
|
|
class MyPolyVertex;
|
|
|
|
|
[ Changes in definition of TriMesh: PART I ]
Note for the developers: the change to make to existing projects is very little
but strictly necessary to compile. This change IS NOT backward compliant.
==== OLD ==== way to define a TriMesh:
// forward declarations
class MyVertex;
class MyEdge;
class MyFace;
class MyVertex: public VertexSimp2 < MyVertex, MyEdge, MyFace, vertex::Coord3f,...other components>{};
class MyFace: public FaceSimp2 < MyVertex, MyEdge, MyFace, face::VertexRef,...other components>{};
class MyMesh: public TriMesh<vector<MyVertex>,vector<MyFace> >{};
==== NEW ==== way to define a TriMesh:
// forward declarations
class MyVertex;
class MyEdge;
class MyFace;
// declaration of which types is used as VertexType, which type is used as FaceType and so on...
class MyUsedTypes: public vcg::UsedType < vcg::Use<MyVertex>::AsVertexType,
vcg::Use<MyFace>::AsFaceType>{};
class MyVertex: public Vertex < MyUsedTypes, vertex::Coord3f,...other components>{};
class MyFace: public Face < MyUsedTypes, face::VertexRef,...other components>{};
class MyMesh: public TriMesh<vector<MyVertex>,vector<MyFace> >{};
===== classes introduced
[vcg::UsedType] : it is a class containing all the types that must be passed to the definition of Vertex, Face, Edge... This
class replaces the list of typenames to pass as first templates and the need to specify the maximal simplicial. So
<MyVertex, MyEdge, MyFace becomes <MyUsedTypes<
and
VertexSimp2 becomes Vertex
[vcg::Use] : an auxiliary class to give a simple way to specify the role of a type
Note 2: the order of templates parameters to vcg::UsedTypes is unimportant, e.g:
class MyUsedTypes: public vcg::UsedType <vcg::Use<MyVertex>::AsVertexType,
vcg::Use<MyEdge>::AsEdgeType,
vcg::Use<MyFace>::AsFaceType>{};
is the same as:
class MyUsedTypes: public vcg::UsedType <vcg::Use<MyFace>::AsFaceType,
vcg::Use<MyEdge>::AsEdgeType,
vcg::Use<MyVertex>::AsVertexType>{};
Note 3: you only need to specify the type you use. If you do not have edges you do not need
to include vcg::Use<MyEdge>::AsEdgeType in the template list of UsedTypes.
==== the Part II will be a tiny change to the class TriMesh it self.
2010-03-15 11:44:40 +01:00
|
|
|
struct CUsedTypes: public vcg::UsedTypes< vcg::Use<CVertex>::AsVertexType, vcg::Use<CFace>::AsFaceType >{};
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-12-19 16:36:15 +01:00
|
|
|
/* Definition of a mesh of triangles
|
|
|
|
*/
|
[ Changes in definition of TriMesh: PART I ]
Note for the developers: the change to make to existing projects is very little
but strictly necessary to compile. This change IS NOT backward compliant.
==== OLD ==== way to define a TriMesh:
// forward declarations
class MyVertex;
class MyEdge;
class MyFace;
class MyVertex: public VertexSimp2 < MyVertex, MyEdge, MyFace, vertex::Coord3f,...other components>{};
class MyFace: public FaceSimp2 < MyVertex, MyEdge, MyFace, face::VertexRef,...other components>{};
class MyMesh: public TriMesh<vector<MyVertex>,vector<MyFace> >{};
==== NEW ==== way to define a TriMesh:
// forward declarations
class MyVertex;
class MyEdge;
class MyFace;
// declaration of which types is used as VertexType, which type is used as FaceType and so on...
class MyUsedTypes: public vcg::UsedType < vcg::Use<MyVertex>::AsVertexType,
vcg::Use<MyFace>::AsFaceType>{};
class MyVertex: public Vertex < MyUsedTypes, vertex::Coord3f,...other components>{};
class MyFace: public Face < MyUsedTypes, face::VertexRef,...other components>{};
class MyMesh: public TriMesh<vector<MyVertex>,vector<MyFace> >{};
===== classes introduced
[vcg::UsedType] : it is a class containing all the types that must be passed to the definition of Vertex, Face, Edge... This
class replaces the list of typenames to pass as first templates and the need to specify the maximal simplicial. So
<MyVertex, MyEdge, MyFace becomes <MyUsedTypes<
and
VertexSimp2 becomes Vertex
[vcg::Use] : an auxiliary class to give a simple way to specify the role of a type
Note 2: the order of templates parameters to vcg::UsedTypes is unimportant, e.g:
class MyUsedTypes: public vcg::UsedType <vcg::Use<MyVertex>::AsVertexType,
vcg::Use<MyEdge>::AsEdgeType,
vcg::Use<MyFace>::AsFaceType>{};
is the same as:
class MyUsedTypes: public vcg::UsedType <vcg::Use<MyFace>::AsFaceType,
vcg::Use<MyEdge>::AsEdgeType,
vcg::Use<MyVertex>::AsVertexType>{};
Note 3: you only need to specify the type you use. If you do not have edges you do not need
to include vcg::Use<MyEdge>::AsEdgeType in the template list of UsedTypes.
==== the Part II will be a tiny change to the class TriMesh it self.
2010-03-15 11:44:40 +01:00
|
|
|
class CVertex : public Vertex< CUsedTypes,
|
2008-12-19 16:36:15 +01:00
|
|
|
vertex::BitFlags,
|
|
|
|
vertex::Coord3f,
|
|
|
|
vertex::Normal3f,
|
|
|
|
vertex::Mark >{};
|
|
|
|
|
[ Changes in definition of TriMesh: PART I ]
Note for the developers: the change to make to existing projects is very little
but strictly necessary to compile. This change IS NOT backward compliant.
==== OLD ==== way to define a TriMesh:
// forward declarations
class MyVertex;
class MyEdge;
class MyFace;
class MyVertex: public VertexSimp2 < MyVertex, MyEdge, MyFace, vertex::Coord3f,...other components>{};
class MyFace: public FaceSimp2 < MyVertex, MyEdge, MyFace, face::VertexRef,...other components>{};
class MyMesh: public TriMesh<vector<MyVertex>,vector<MyFace> >{};
==== NEW ==== way to define a TriMesh:
// forward declarations
class MyVertex;
class MyEdge;
class MyFace;
// declaration of which types is used as VertexType, which type is used as FaceType and so on...
class MyUsedTypes: public vcg::UsedType < vcg::Use<MyVertex>::AsVertexType,
vcg::Use<MyFace>::AsFaceType>{};
class MyVertex: public Vertex < MyUsedTypes, vertex::Coord3f,...other components>{};
class MyFace: public Face < MyUsedTypes, face::VertexRef,...other components>{};
class MyMesh: public TriMesh<vector<MyVertex>,vector<MyFace> >{};
===== classes introduced
[vcg::UsedType] : it is a class containing all the types that must be passed to the definition of Vertex, Face, Edge... This
class replaces the list of typenames to pass as first templates and the need to specify the maximal simplicial. So
<MyVertex, MyEdge, MyFace becomes <MyUsedTypes<
and
VertexSimp2 becomes Vertex
[vcg::Use] : an auxiliary class to give a simple way to specify the role of a type
Note 2: the order of templates parameters to vcg::UsedTypes is unimportant, e.g:
class MyUsedTypes: public vcg::UsedType <vcg::Use<MyVertex>::AsVertexType,
vcg::Use<MyEdge>::AsEdgeType,
vcg::Use<MyFace>::AsFaceType>{};
is the same as:
class MyUsedTypes: public vcg::UsedType <vcg::Use<MyFace>::AsFaceType,
vcg::Use<MyEdge>::AsEdgeType,
vcg::Use<MyVertex>::AsVertexType>{};
Note 3: you only need to specify the type you use. If you do not have edges you do not need
to include vcg::Use<MyEdge>::AsEdgeType in the template list of UsedTypes.
==== the Part II will be a tiny change to the class TriMesh it self.
2010-03-15 11:44:40 +01:00
|
|
|
class CFace : public Face< CUsedTypes,
|
2008-12-19 16:36:15 +01:00
|
|
|
face::VertexRef, // three pointers to vertices
|
|
|
|
face::Normal3f, // normal
|
|
|
|
face::BitFlags, // flags
|
|
|
|
face::FFAdj // three pointers to adjacent faces
|
|
|
|
> {};
|
|
|
|
|
|
|
|
/* the mesh is a container of vertices and a container of faces */
|
|
|
|
class CMesh : public vcg::tri::TriMesh< vector<CVertex>, vector<CFace> > {};
|
|
|
|
|
|
|
|
|
|
|
|
/* Definition of a mesh of polygons that also supports half-edges
|
|
|
|
*/
|
|
|
|
class MyPolyFace;
|
[ Changes in definition of TriMesh: PART I ]
Note for the developers: the change to make to existing projects is very little
but strictly necessary to compile. This change IS NOT backward compliant.
==== OLD ==== way to define a TriMesh:
// forward declarations
class MyVertex;
class MyEdge;
class MyFace;
class MyVertex: public VertexSimp2 < MyVertex, MyEdge, MyFace, vertex::Coord3f,...other components>{};
class MyFace: public FaceSimp2 < MyVertex, MyEdge, MyFace, face::VertexRef,...other components>{};
class MyMesh: public TriMesh<vector<MyVertex>,vector<MyFace> >{};
==== NEW ==== way to define a TriMesh:
// forward declarations
class MyVertex;
class MyEdge;
class MyFace;
// declaration of which types is used as VertexType, which type is used as FaceType and so on...
class MyUsedTypes: public vcg::UsedType < vcg::Use<MyVertex>::AsVertexType,
vcg::Use<MyFace>::AsFaceType>{};
class MyVertex: public Vertex < MyUsedTypes, vertex::Coord3f,...other components>{};
class MyFace: public Face < MyUsedTypes, face::VertexRef,...other components>{};
class MyMesh: public TriMesh<vector<MyVertex>,vector<MyFace> >{};
===== classes introduced
[vcg::UsedType] : it is a class containing all the types that must be passed to the definition of Vertex, Face, Edge... This
class replaces the list of typenames to pass as first templates and the need to specify the maximal simplicial. So
<MyVertex, MyEdge, MyFace becomes <MyUsedTypes<
and
VertexSimp2 becomes Vertex
[vcg::Use] : an auxiliary class to give a simple way to specify the role of a type
Note 2: the order of templates parameters to vcg::UsedTypes is unimportant, e.g:
class MyUsedTypes: public vcg::UsedType <vcg::Use<MyVertex>::AsVertexType,
vcg::Use<MyEdge>::AsEdgeType,
vcg::Use<MyFace>::AsFaceType>{};
is the same as:
class MyUsedTypes: public vcg::UsedType <vcg::Use<MyFace>::AsFaceType,
vcg::Use<MyEdge>::AsEdgeType,
vcg::Use<MyVertex>::AsVertexType>{};
Note 3: you only need to specify the type you use. If you do not have edges you do not need
to include vcg::Use<MyEdge>::AsEdgeType in the template list of UsedTypes.
==== the Part II will be a tiny change to the class TriMesh it self.
2010-03-15 11:44:40 +01:00
|
|
|
class MyPolyVertex;
|
2010-03-25 17:47:03 +01:00
|
|
|
struct PolyUsedTypes: public vcg::UsedTypes<vcg::Use<MyPolyVertex> ::AsVertexType,
|
2010-04-30 11:42:52 +02:00
|
|
|
vcg::Use<CEdge> ::AsEdgeType,
|
|
|
|
vcg::Use<CHEdge> ::AsHEdgeType,
|
|
|
|
vcg::Use<MyPolyFace> ::AsFaceType
|
|
|
|
>{};
|
2010-03-25 17:47:03 +01:00
|
|
|
|
2010-04-30 11:42:52 +02:00
|
|
|
//class DummyEdge: public vcg::Edge<PolyUsedTypes>{};
|
2010-03-25 17:47:03 +01:00
|
|
|
class MyPolyVertex:public vcg::Vertex< PolyUsedTypes,
|
|
|
|
vcg::vertex::Coord3f,
|
|
|
|
vcg::vertex::Normal3f,
|
|
|
|
vcg::vertex::Mark,
|
|
|
|
vcg::vertex::BitFlags,
|
|
|
|
vcg::vertex::VHAdj>{} ;
|
|
|
|
|
2010-04-30 11:42:52 +02:00
|
|
|
class CEdge : public Edge<PolyUsedTypes>{};
|
2010-03-25 17:47:03 +01:00
|
|
|
class CHEdge : public HEdge< PolyUsedTypes, hedge::BitFlags,
|
|
|
|
//hedge::HFAdj, // pointer to the face
|
|
|
|
//hedge::HOppAdj, // pointer to the opposite edge
|
|
|
|
//hedge::HVAdj, // pointer to the vertex
|
|
|
|
//hedge::HNextAdj, // pointer to the next halfedge
|
|
|
|
hedge::HEdgeData // the previous 4 components (just more handy, you can comment this and uncomment the previous four lines)
|
|
|
|
//,hedge::HPrevAdj // pointer to the previous halfedge
|
2008-12-19 16:36:15 +01:00
|
|
|
>{};
|
|
|
|
|
[ Changes in definition of TriMesh: PART I ]
Note for the developers: the change to make to existing projects is very little
but strictly necessary to compile. This change IS NOT backward compliant.
==== OLD ==== way to define a TriMesh:
// forward declarations
class MyVertex;
class MyEdge;
class MyFace;
class MyVertex: public VertexSimp2 < MyVertex, MyEdge, MyFace, vertex::Coord3f,...other components>{};
class MyFace: public FaceSimp2 < MyVertex, MyEdge, MyFace, face::VertexRef,...other components>{};
class MyMesh: public TriMesh<vector<MyVertex>,vector<MyFace> >{};
==== NEW ==== way to define a TriMesh:
// forward declarations
class MyVertex;
class MyEdge;
class MyFace;
// declaration of which types is used as VertexType, which type is used as FaceType and so on...
class MyUsedTypes: public vcg::UsedType < vcg::Use<MyVertex>::AsVertexType,
vcg::Use<MyFace>::AsFaceType>{};
class MyVertex: public Vertex < MyUsedTypes, vertex::Coord3f,...other components>{};
class MyFace: public Face < MyUsedTypes, face::VertexRef,...other components>{};
class MyMesh: public TriMesh<vector<MyVertex>,vector<MyFace> >{};
===== classes introduced
[vcg::UsedType] : it is a class containing all the types that must be passed to the definition of Vertex, Face, Edge... This
class replaces the list of typenames to pass as first templates and the need to specify the maximal simplicial. So
<MyVertex, MyEdge, MyFace becomes <MyUsedTypes<
and
VertexSimp2 becomes Vertex
[vcg::Use] : an auxiliary class to give a simple way to specify the role of a type
Note 2: the order of templates parameters to vcg::UsedTypes is unimportant, e.g:
class MyUsedTypes: public vcg::UsedType <vcg::Use<MyVertex>::AsVertexType,
vcg::Use<MyEdge>::AsEdgeType,
vcg::Use<MyFace>::AsFaceType>{};
is the same as:
class MyUsedTypes: public vcg::UsedType <vcg::Use<MyFace>::AsFaceType,
vcg::Use<MyEdge>::AsEdgeType,
vcg::Use<MyVertex>::AsVertexType>{};
Note 3: you only need to specify the type you use. If you do not have edges you do not need
to include vcg::Use<MyEdge>::AsEdgeType in the template list of UsedTypes.
==== the Part II will be a tiny change to the class TriMesh it self.
2010-03-15 11:44:40 +01:00
|
|
|
class MyPolyFace:public vcg::Face<
|
|
|
|
PolyUsedTypes
|
2008-12-19 16:36:15 +01:00
|
|
|
,vcg::face::PolyInfo // this is necessary if you use component in vcg/simplex/face/component_polygon.h
|
|
|
|
// It says "this class is a polygon and the memory for its components (e.g. pointer to its vertices
|
|
|
|
// will be allocated dynamically")
|
|
|
|
,vcg::face::PFVAdj // Pointer to the vertices (just like FVAdj )
|
2010-03-25 17:47:03 +01:00
|
|
|
,vcg::face::PFVAdj
|
2008-12-19 16:36:15 +01:00
|
|
|
,vcg::face::PFFAdj // Pointer to edge-adjacent face (just like FFAdj )
|
2010-03-25 17:47:03 +01:00
|
|
|
,vcg::face::PFHAdj // Pointer its half -edges ( you may need this if you use half edges)
|
2008-12-19 16:36:15 +01:00
|
|
|
,vcg::face::BitFlags // bit flags
|
|
|
|
,vcg::face::Normal3f // normal
|
|
|
|
> {};
|
|
|
|
|
|
|
|
class MyPolyMesh: public
|
2010-04-30 11:42:52 +02:00
|
|
|
vcg::tri::TriMesh<
|
|
|
|
std::vector<MyPolyVertex>, // the vector of vertices
|
|
|
|
std::vector<MyPolyFace >, // the vector of faces
|
|
|
|
std::vector<CHEdge> , // the vector of edges
|
|
|
|
std::vector<CEdge> // the vector of edges
|
2008-12-19 16:36:15 +01:00
|
|
|
>{};
|
|
|
|
|
|
|
|
MyPolyMesh pm;
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Globals: the mesh, the OpenGL wrapper to draw the mesh and the trackball.
|
|
|
|
CMesh mesh,mesh1;
|
|
|
|
|
2010-04-30 11:42:52 +02:00
|
|
|
int main(int argc, char *argv[]) {
|
2008-12-19 16:36:15 +01:00
|
|
|
|
|
|
|
int loadmask;
|
|
|
|
|
|
|
|
vcg::tri::io::PlyInfo pi;
|
|
|
|
|
2010-03-25 17:47:03 +01:00
|
|
|
// pm.hedge.reserve(100000);
|
2011-03-31 17:47:27 +02:00
|
|
|
if(true){
|
2008-12-19 16:36:15 +01:00
|
|
|
/*
|
|
|
|
first way:
|
|
|
|
1) read a polygon mesh that will be automatically converted in a triangle mesh tagging
|
|
|
|
the internal edges (i.e. the edges that have been added for triangulating the polygons)
|
|
|
|
2) make some cleaning
|
|
|
|
3) import the tagged triangle mesh in a polygon mesh
|
|
|
|
*/
|
2011-03-31 17:47:27 +02:00
|
|
|
// vcg::tri::io::ImporterOBJ<CMesh>::Open(mesh,argv[1],loadmask);
|
|
|
|
vcg::tri::io::ImporterOFF<CMesh>::Open(mesh,argv[1],loadmask);
|
2008-12-19 16:36:15 +01:00
|
|
|
|
|
|
|
vcg::tri::Clean<CMesh>::RemoveUnreferencedVertex(mesh);
|
|
|
|
vcg::tri::Clean<CMesh>::RemoveZeroAreaFace(mesh);
|
|
|
|
vcg::tri::UpdateTopology<CMesh>::FaceFace(mesh);
|
|
|
|
vcg::tri::Clean<CMesh>::RemoveNonManifoldFace(mesh);
|
|
|
|
vcg::tri::UpdateTopology<CMesh>::FaceFace(mesh);
|
2010-04-30 11:42:52 +02:00
|
|
|
assert(vcg::tri::Clean<CMesh>::CountNonManifoldEdgeFF(mesh)==0);
|
|
|
|
assert(vcg::tri::Clean<CMesh>::CountNonManifoldVertexFF(mesh)==0);
|
|
|
|
|
2008-12-19 16:36:15 +01:00
|
|
|
// create a polygon meshe from a trimesh with tagged faces
|
|
|
|
vcg::tri::PolygonSupport<CMesh,MyPolyMesh>::ImportFromTriMesh(pm,mesh);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* second way:
|
|
|
|
Load into a polygon mesh straight away.
|
|
|
|
*/
|
|
|
|
vcg::tri::io::ImporterOBJ<MyPolyMesh>::Open(pm,argv[1],loadmask);
|
|
|
|
vcg::tri::UpdateTopology<MyPolyMesh>::FaceFace(pm);
|
|
|
|
vcg::tri::Clean<MyPolyMesh>::RemoveNonManifoldFace(pm);
|
|
|
|
vcg::tri::UpdateTopology<MyPolyMesh>::FaceFace(pm);
|
2010-04-30 11:42:52 +02:00
|
|
|
assert(vcg::tri::Clean<MyPolyMesh>::CountNonManifoldEdgeFF(pm));
|
2008-12-19 16:36:15 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// compute the half edges because I'm a half-edge programmer
|
2010-03-25 17:47:03 +01:00
|
|
|
vcg::tri::UpdateHalfEdges<MyPolyMesh>::FromIndexed(pm);
|
2008-12-19 16:36:15 +01:00
|
|
|
|
|
|
|
// .... my half edge based code ......
|
|
|
|
|
|
|
|
// check for consistency
|
2010-03-25 17:47:03 +01:00
|
|
|
assert(vcg::tri::UpdateHalfEdges<MyPolyMesh>::CheckConsistency(pm));
|
2008-12-19 16:36:15 +01:00
|
|
|
|
|
|
|
int size = pm.face.size();
|
|
|
|
|
|
|
|
// add a face to each face with more than 3 vertices ( just one pass)
|
2010-03-25 17:47:03 +01:00
|
|
|
|
2008-12-19 16:36:15 +01:00
|
|
|
for(int i = 0; i < size; ++i)
|
|
|
|
if(!(pm.face[i].IsD()))
|
|
|
|
if(pm.face[i].VN()>3){
|
2010-03-25 17:47:03 +01:00
|
|
|
MyPolyMesh::HEdgePointer ef = pm.face[i].FHp();
|
|
|
|
MyPolyMesh::HEdgePointer ef1 = ef -> HNp();
|
|
|
|
ef1 = ef1->HNp();
|
|
|
|
vcg::tri::UpdateHalfEdges<MyPolyMesh>::AddHEdge(pm, ef, ef1 );
|
2008-12-19 16:36:15 +01:00
|
|
|
}
|
2010-03-25 17:47:03 +01:00
|
|
|
assert(vcg::tri::UpdateHalfEdges<MyPolyMesh>::CheckConsistency(pm));
|
2008-12-19 16:36:15 +01:00
|
|
|
size = pm.face.size();
|
|
|
|
|
|
|
|
// remove an edge for each face
|
2010-03-25 17:47:03 +01:00
|
|
|
|
2008-12-19 16:36:15 +01:00
|
|
|
for(int i = 0; i < size; ++i)
|
|
|
|
if(!(pm.face[i].IsD() ))
|
|
|
|
{
|
2010-03-25 17:47:03 +01:00
|
|
|
MyPolyMesh::HEdgePointer ef = pm.face[i].FHp();
|
|
|
|
if( ef->HOp()->HFp() !=NULL){
|
|
|
|
vcg::tri::UpdateHalfEdges<MyPolyMesh>::RemoveHEdge(pm,ef);
|
2008-12-19 16:36:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for consistency
|
2010-03-25 17:47:03 +01:00
|
|
|
assert(vcg::tri::UpdateHalfEdges<MyPolyMesh>::CheckConsistency(pm));
|
2008-12-19 16:36:15 +01:00
|
|
|
|
|
|
|
// recompute indexed data structure from the half edge data structure
|
2010-03-25 17:47:03 +01:00
|
|
|
vcg::tri::UpdateIndexed<MyPolyMesh>::FromHalfEdges(pm );
|
2008-12-19 16:36:15 +01:00
|
|
|
|
|
|
|
// create a triangle mesh from a polygon mesh
|
2010-03-25 17:47:03 +01:00
|
|
|
vcg::tri::PolygonSupport<CMesh,MyPolyMesh>::ImportFromPolyMesh(mesh1,pm);
|
2008-12-19 16:36:15 +01:00
|
|
|
|
|
|
|
// write out the triangle mesh
|
|
|
|
vcg::tri::io::ExporterPLY<CMesh>::Save(mesh1,"converted_out.ply",true,pi);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|