VCG Library
polygonmesh_dual.cpp
1 /****************************************************************************
2 * VCGLib o o *
3 * Visual and Computer Graphics Library o o *
4 * _ O _ *
5 * Copyright(C) 2004-2016 \/)\/ *
6 * Visual Computing Lab /\/| *
7 * ISTI - Italian National Research Council | *
8 * \ *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
20 * for more details. *
21 * *
22 ****************************************************************************/
23 
24 #include <vcg/complex/complex.h>
25 
26 /*include the algorithms for updating: */
27 #include <vcg/complex/algorithms/update/bounding.h>
28 #include <vcg/complex/algorithms/update/normal.h>
29 
30 #include <vcg/complex/algorithms/clean.h>
31 #include <vcg/complex/algorithms/create/platonic.h>
32 
33 #include <wrap/io_trimesh/export_obj.h>
34 #include <wrap/io_trimesh/import_obj.h>
35 
36 #include <vcg/complex/algorithms/dual_meshing.h>
37 
38 #include <vcg/complex/algorithms/polygon_support.h>
39 
40 using namespace vcg;
41 using namespace std;
42 
43 // forward declarations
44 class TFace;
45 class TVertex;
46 
47 struct TUsedTypes: public vcg::UsedTypes< vcg::Use<TVertex>::AsVertexType, vcg::Use<TFace>::AsFaceType >{};
48 
49 /* Definition of a mesh of triangles
50 */
51 class TVertex : public Vertex< TUsedTypes,
52  vertex::BitFlags,
53  vertex::Coord3f,
54  vertex::Normal3f,
55  vertex::Mark >{};
56 
57 class TFace : public Face< TUsedTypes,
58  face::VertexRef, // three pointers to vertices
59  face::Normal3f, // normal
60  face::BitFlags, // flags
61  face::FFAdj // three pointers to adjacent faces
62 > {};
63 
64 /* the mesh is a container of vertices and a container of faces */
65 class TMesh : public vcg::tri::TriMesh< vector<TVertex>, vector<TFace> > {};
66 
67 
68 /* Definition of a mesh of polygons that also supports half-edges
69 */
70 class PFace;
71 class PVertex;
72 
73 struct PUsedTypes: public vcg::UsedTypes<vcg::Use<PVertex> ::AsVertexType,
74  vcg::Use<PFace> ::AsFaceType>{};
75 
76 class PVertex:public vcg::Vertex< PUsedTypes,
77  vcg::vertex::Coord3f,
78  vcg::vertex::Normal3f,
79  vcg::vertex::Mark,
80  vcg::vertex::BitFlags>{} ;
81 
82 class PFace:public vcg::Face<
83  PUsedTypes
84  ,vcg::face::PolyInfo // this is necessary if you use component in vcg/simplex/face/component_polygon.h
85  // It says "this class is a polygon and the memory for its components (e.g. pointer to its vertices
86  // will be allocated dynamically")
87  ,vcg::face::PFVAdj // Pointer to the vertices (just like FVAdj )
88  ,vcg::face::PFVAdj
89  ,vcg::face::PFFAdj // Pointer to edge-adjacent face (just like FFAdj )
90  ,vcg::face::BitFlags // bit flags
91  ,vcg::face::Normal3f // normal
92 > {};
93 
94 class PMesh: public
95  vcg::tri::TriMesh<
96  std::vector<PVertex>, // the vector of vertices
97  std::vector<PFace > // the vector of faces
98  >{};
99 
100 TMesh primalT;
101 PMesh primal,dual;
102 
103 int main(int argc, char *argv[])
104 {
105  (void)argc;
106  (void)argv;
107 
108  vcg::tri::Sphere<TMesh>(primalT,2);
109  vcg::tri::PolygonSupport<TMesh,PMesh>::ImportFromTriMesh(primal,primalT);
110 
111  vcg::tri::DualMeshing<PMesh>::MakeDual(primal,dual);
112  vcg::tri::io::ExporterOBJ<PMesh>::Save(dual,"./dual.obj",vcg::tri::io::Mask::IOM_BITPOLYGONAL);
113 
114  vcg::tri::DualMeshing<PMesh>::MakeDual(dual,primal);
115  vcg::tri::io::ExporterOBJ<PMesh>::Save(primal,"./dual_dual.obj",vcg::tri::io::Mask::IOM_BITPOLYGONAL);
116 
117 }
118 
119 
120