VCG Library
trimesh_create.cpp
Go to the documentation of this file.
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 ****************************************************************************/
29 #include<vcg/complex/complex.h>
30 #include<vcg/complex/algorithms/create/platonic.h>
31 
32 // input output
33 #include <wrap/io_trimesh/export_off.h>
34 
35 class MyFace;
36 class MyVertex;
37 
38 struct MyUsedTypes : public vcg::UsedTypes< vcg::Use<MyVertex>::AsVertexType, vcg::Use<MyFace>::AsFaceType>{};
39 
40 class MyVertex : public vcg::Vertex< MyUsedTypes, vcg::vertex::Coord3f, vcg::vertex::Normal3f, vcg::vertex::Color4b, vcg::vertex::BitFlags >{};
41 class MyFace : public vcg::Face < MyUsedTypes, vcg::face::VertexRef, vcg::face::Normal3f, vcg::face::FFAdj, vcg::face::BitFlags > {};
42 class MyMesh : public vcg::tri::TriMesh< std::vector<MyVertex>, std::vector<MyFace> > {};
43 
44 using namespace std;
45 using namespace vcg;
46 
47 int main()
48 {
49  MyMesh diskMesh;
50 
51  // Create a simple triangle mesh using just a vector of coords and a vector of indexes
52  vector<Point3f> coordVec;
53  vector<Point3i> indexVec;
54  coordVec.push_back(Point3f(0,0,0));
55  for(int i=0;i<36;++i) {
56  float angleRad = float(i)*M_PI/18.0;
57  coordVec.push_back(Point3f(sin(angleRad),cos(angleRad),0));
58  indexVec.push_back(Point3i(0,i+1,1+(i+1)%36));
59  }
60 
61  tri::BuildMeshFromCoordVectorIndexVector(diskMesh,coordVec,indexVec);
62  tri::io::ExporterOFF<MyMesh>::Save(diskMesh,"disc.off");
63 
64  // Create the platonic solids
65  MyMesh platonicMesh;
66  tri::Tetrahedron(platonicMesh);
67  tri::io::ExporterOFF<MyMesh>::Save(platonicMesh,"tetrahedron.off");
68  tri::Octahedron(platonicMesh);
69  tri::io::ExporterOFF<MyMesh>::Save(platonicMesh,"octahedron.off");
70  tri::Hexahedron(platonicMesh);
71  tri::io::ExporterOFF<MyMesh>::Save(platonicMesh,"hexahedron.off");
72  tri::Dodecahedron(platonicMesh);
73  tri::io::ExporterOFF<MyMesh>::Save(platonicMesh,"dodecahedron.off");
74  tri::Icosahedron(platonicMesh);
75  tri::io::ExporterOFF<MyMesh>::Save(platonicMesh,"icosahedron.off");
76 
77  // Procedurally transform a mesh into a solid collection of triangular prisms
78  MyMesh facePrismMesh;
79  tri::BuildPrismFaceShell(platonicMesh, facePrismMesh, 0.1f, 0.1f);
80  tri::io::ExporterOFF<MyMesh>::Save(facePrismMesh,"facePrism.off");
81 
82  return 0;
83 }