tutorial_01.docu 3.89 KB
Newer Older
1
2
/**

Mike Kremer's avatar
Mike Kremer committed
3
\page tutorial_01 Tutorial 01: Creating a Simple Volume Mesh
4

Mike Kremer's avatar
Mike Kremer committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Creating a volumetric mesh with %OpenVolumeMesh is pretty simple.
In order to make available the different built-in vector types
that %OpenVolumeMesh provides, just include the following header:

\code
#include <OpenVolumeMesh/Geometry/VectorT.hh>
\endcode

Depending on whether you want to deal with hexahedral or general
polyhedral meshes, either of the following headers has to be
included, too:

\code
// Hexahedral meshes
#include <OpenVolumeMesh/HexahedralMesh/HexahedralMesh.hh>

// Polyhedral meshes
#include <OpenVolumeMesh/PolyhedralMesh/PolyhedralMesh.hh>
\endcode

Note that you can also handle hexahedral meshes with the
OpenVolumeMesh::PolyhedralMesh class, but class OpenVolumeMesh::HexahedralMesh
provides some specific topology checks and, more importantly,
a set of specialized iterators.

The following code creates a polyhedral mesh instance and fills it
Mike Kremer's avatar
Mike Kremer committed
31
32
33
34
35
36
37
38
39
with two adjacent tetrahedra. Note that when defining cells in %OpenVolumeMesh,
the incident half-faces that define a cell are supposed to form a two-manifold.
This particularly implies that they are supposed to have the same orientation
(whether their normal points inside the cell or outside the cell does not matter,
but convention assumes the half-face normals to point inside the cell).
%OpenVolumeMesh per default performs a check whether the specified half-faces
form a two-manifold when adding a cell. This check can explicitly turned off
by passing false as second parameter to OpenVolumeMesh::PolyhedralMesh<VecT>::add_face().
Note that in these cases, it is not guaranteed that a given mesh is three-manifold.
Mike Kremer's avatar
Mike Kremer committed
40
41

\code
42
43
typedef OpenVolumeMesh::Geometry::Vec3f Vec3f
typedef OpenVolumeMesh::PolyhedralMesh<Vec3f> PolyhedralMeshV3f;
Mike Kremer's avatar
Mike Kremer committed
44
45

// Create mesh object
46
PolyhedralMeshV3f myMesh;
Mike Kremer's avatar
Mike Kremer committed
47
48

// Add eight vertices
49
50
51
52
53
PolyhedralMeshV3f::VertexHandle v0 = myMesh.add_vertex(Vec3f(-1.0, 0.0, 0.0));
PolyhedralMeshV3f::VertexHandle v1 = myMesh.add_vertex(Vec3f( 0.0, 0.0, 1.0));
PolyhedralMeshV3f::VertexHandle v2 = myMesh.add_vertex(Vec3f( 1.0, 0.0, 0.0));
PolyhedralMeshV3f::VertexHandle v3 = myMesh.add_vertex(Vec3f( 0.0, 0.0,-1.0));
PolyhedralMeshV3f::VertexHandle v4 = myMesh.add_vertex(Vec3f( 0.0, 1.0, 0.0));
Mike Kremer's avatar
Mike Kremer committed
54

55
std::vector<PolyhedralMeshV3f::VertexHandle> vertices;
Mike Kremer's avatar
Mike Kremer committed
56
57

// Add faces
58
59
vertices.push_back(v0); vertices.push_back(v1);vertices.push_back(v4);
PolyhedralMeshV3f::FaceHandle f0 = myMesh.add_face(vertices);
Mike Kremer's avatar
Mike Kremer committed
60
61

vertices.clear();
62
63
vertices.push_back(v1); vertices.push_back(v2);vertices.push_back(v4);
PolyhedralMeshV3f::FaceHandle f1 = myMesh.add_face(vertices);
Mike Kremer's avatar
Mike Kremer committed
64
65

vertices.clear();
66
67
vertices.push_back(v0); vertices.push_back(v1);vertices.push_back(v2);
PolyhedralMeshV3f::FaceHandle f2 = myMesh.add_face(vertices);
Mike Kremer's avatar
Mike Kremer committed
68
69

vertices.clear();
70
71
vertices.push_back(v0); vertices.push_back(v4);vertices.push_back(v2);
PolyhedralMeshV3f::FaceHandle f3 = myMesh.add_face(vertices);
Mike Kremer's avatar
Mike Kremer committed
72
73

vertices.clear();
74
75
vertices.push_back(v0); vertices.push_back(v4);vertices.push_back(v3);
PolyhedralMeshV3f::FaceHandle f4 = myMesh.add_face(vertices);
Mike Kremer's avatar
Mike Kremer committed
76
77

vertices.clear();
78
79
vertices.push_back(v2); vertices.push_back(v3);vertices.push_back(v4);
PolyhedralMeshV3f::FaceHandle f5 = myMesh.add_face(vertices);
Mike Kremer's avatar
Mike Kremer committed
80
81

vertices.clear();
82
83
vertices.push_back(v0); vertices.push_back(v2);vertices.push_back(v3);
PolyhedralMeshV3f::FaceHandle f6 = myMesh.add_face(vertices);
Mike Kremer's avatar
Mike Kremer committed
84

85
std::vector<PolyhedralMeshV3f::HalfFaceHandle> halffaces;
Mike Kremer's avatar
Mike Kremer committed
86
87

// Add first tetrahedron
Mike Kremer's avatar
Mike Kremer committed
88
89
halffaces.push_back(myMesh.halfface_handle(f0, 1));
halffaces.push_back(myMesh.halfface_handle(f1, 1));
90
91
halffaces.push_back(myMesh.halfface_handle(f2, 0)); 
halffaces.push_back(myMesh.halfface_handle(f3, 1)); 
Mike Kremer's avatar
Mike Kremer committed
92
myMesh.add_cell(halffaces);
Mike Kremer's avatar
Mike Kremer committed
93
94
95

// Add second tetrahedron
halffaces.clear();
Mike Kremer's avatar
Mike Kremer committed
96
halffaces.push_back(myMesh.halfface_handle(f4, 1));
97
98
halffaces.push_back(myMesh.halfface_handle(f5, 1));
halffaces.push_back(myMesh.halfface_handle(f3, 0)); 
Mike Kremer's avatar
Mike Kremer committed
99
100
halffaces.push_back(myMesh.halfface_handle(f6, 0)); 
myMesh.add_cell(halffaces);
Mike Kremer's avatar
Mike Kremer committed
101
102
103

\endcode

104
**/