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
42
43
44
45
46
47
48

\code
typedef OpenVolumeMesh::Geometry::Vec3d Vec3d
typedef OpenVolumeMesh::PolyhedralMesh<Vec3d> PolyhedralMeshV3d;

// Create mesh object
PolyhedralMeshV3d myMesh;

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

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

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

vertices.clear();
vertices.push_back(v2); vertices.push_back(v0);vertices.push_back(v3);
Mike Kremer's avatar
Mike Kremer committed
63
PolyhedralMeshV3d::FaceHandle f1 = myMesh.add_face(vertices);
Mike Kremer's avatar
Mike Kremer committed
64
65
66

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

vertices.clear();
vertices.push_back(v1); vertices.push_back(v4);vertices.push_back(v3);
Mike Kremer's avatar
Mike Kremer committed
71
PolyhedralMeshV3d::FaceHandle f3 = myMesh.add_face(vertices);
Mike Kremer's avatar
Mike Kremer committed
72
73
74

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

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

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

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

// Add first tetrahedron
Mike Kremer's avatar
Mike Kremer committed
88
89
90
91
92
halffaces.push_back(myMesh.halfface_handle(f0, 1));
halffaces.push_back(myMesh.halfface_handle(f1, 1));
halffaces.push_back(myMesh.halfface_handle(f2, 1)); 
halffaces.push_back(myMesh.halfface_handle(f6, 1)); 
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
97
98
99
100
halffaces.push_back(myMesh.halfface_handle(f3, 1));
halffaces.push_back(myMesh.halfface_handle(f4, 1));
halffaces.push_back(myMesh.halfface_handle(f5, 1)); 
halffaces.push_back(myMesh.halfface_handle(f6, 0)); 
myMesh.add_cell(halffaces);
Mike Kremer's avatar
Mike Kremer committed
101
102
103

\endcode

104
**/