Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
simple_mesh.cc
1 // C++ includes
2 #include <iostream>
3 #include <vector>
4 
5 // Include vector classes
6 #include <OpenVolumeMesh/Geometry/VectorT.hh>
7 
8 // Include polyhedral mesh kernel
9 #include <OpenVolumeMesh/Mesh/PolyhedralMesh.hh>
10 
11 // Make some typedefs to facilitate your life
14 
15 int main(int _argc, char** _argv) {
16 
17  // Create mesh object
18  PolyhedralMeshV3f myMesh;
19 
20  // Add eight vertices
21  OpenVolumeMesh::VertexHandle v0 = myMesh.add_vertex(Vec3f(-1.0, 0.0, 0.0));
22  OpenVolumeMesh::VertexHandle v1 = myMesh.add_vertex(Vec3f( 0.0, 0.0, 1.0));
23  OpenVolumeMesh::VertexHandle v2 = myMesh.add_vertex(Vec3f( 1.0, 0.0, 0.0));
24  OpenVolumeMesh::VertexHandle v3 = myMesh.add_vertex(Vec3f( 0.0, 0.0,-1.0));
25  OpenVolumeMesh::VertexHandle v4 = myMesh.add_vertex(Vec3f( 0.0, 1.0, 0.0));
26 
27  std::vector<OpenVolumeMesh::VertexHandle> vertices;
28 
29  // Add faces
30  vertices.push_back(v0); vertices.push_back(v1);vertices.push_back(v4);
31  OpenVolumeMesh::FaceHandle f0 = myMesh.add_face(vertices);
32 
33  vertices.clear();
34  vertices.push_back(v1); vertices.push_back(v2);vertices.push_back(v4);
35  OpenVolumeMesh::FaceHandle f1 = myMesh.add_face(vertices);
36 
37  vertices.clear();
38  vertices.push_back(v0); vertices.push_back(v1);vertices.push_back(v2);
39  OpenVolumeMesh::FaceHandle f2 = myMesh.add_face(vertices);
40 
41  vertices.clear();
42  vertices.push_back(v0); vertices.push_back(v4);vertices.push_back(v2);
43  OpenVolumeMesh::FaceHandle f3 = myMesh.add_face(vertices);
44 
45  vertices.clear();
46  vertices.push_back(v0); vertices.push_back(v4);vertices.push_back(v3);
47  OpenVolumeMesh::FaceHandle f4 = myMesh.add_face(vertices);
48 
49  vertices.clear();
50  vertices.push_back(v2); vertices.push_back(v3);vertices.push_back(v4);
51  OpenVolumeMesh::FaceHandle f5 = myMesh.add_face(vertices);
52 
53  vertices.clear();
54  vertices.push_back(v0); vertices.push_back(v2);vertices.push_back(v3);
55  OpenVolumeMesh::FaceHandle f6 = myMesh.add_face(vertices);
56 
57  std::vector<OpenVolumeMesh::HalfFaceHandle> halffaces;
58 
59  // Add first tetrahedron
60  halffaces.push_back(myMesh.halfface_handle(f0, 1));
61  halffaces.push_back(myMesh.halfface_handle(f1, 1));
62  halffaces.push_back(myMesh.halfface_handle(f2, 0));
63  halffaces.push_back(myMesh.halfface_handle(f3, 1));
64  myMesh.add_cell(halffaces);
65 
66  // Add second tetrahedron
67  halffaces.clear();
68  halffaces.push_back(myMesh.halfface_handle(f4, 1));
69  halffaces.push_back(myMesh.halfface_handle(f5, 1));
70  halffaces.push_back(myMesh.halfface_handle(f3, 0));
71  halffaces.push_back(myMesh.halfface_handle(f6, 0));
72  myMesh.add_cell(halffaces);
73 
74  // Print positions of vertices to std out
75  for(OpenVolumeMesh::VertexIter v_it = myMesh.vertices_begin();
76  v_it != myMesh.vertices_end(); ++v_it) {
77 
78  std::cout << "Position of vertex " << v_it->idx() << ": " <<
79  myMesh.vertex(*v_it) << std::endl;
80  }
81 
82  return 0;
83 }
const VecT & vertex(const VertexHandle &_vh) const
Get point _vh's coordinates.
virtual VertexHandle add_vertex()
Override of empty add_vertex function.