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:
#include <OpenVolumeMesh/Geometry/VectorT.hh>
Depending on whether you want to deal with hexahedral or general polyhedral meshes, either of the following headers has to be included, too:
#include <OpenVolumeMesh/Mesh/HexahedralMesh.hh>
#include <OpenVolumeMesh/Mesh/PolyhedralMesh.hh>
This provides two different mesh types each:
The first header, for example, predefines a set of commonly used mesh types:
- TopologicPolyhedralMesh: A purely topological polyhedral mesh (no embedding)
- GeometricPolyhedralMeshV3i: A geometric polyhedral mesh with embedding in
- GeometricPolyhedralMeshV3ui: A geometric polyhedral mesh with embedding in
- GeometricPolyhedralMeshV3f: A geometric polyhedral mesh with embedding in , single precision
- GeometricPolyhedralMeshV3d: A geometric polyhedral mesh with embedding in , double precision
- GeometricPolyhedralMeshV3c: A geometric polyhedral mesh with embedding in
- GeometricPolyhedralMeshV3uc: A geometric polyhedral mesh with embedding in
Of course, the second header defines the same mesh types for hexahedral meshes. Just replace Polyhedral by Hexahedral.
- Note
- Note that you can also represent hexahedral meshes using the polyhedral mesh kernel,
-
but the hexahedral mesh classes are equipped with some specialized functionality
-
and iterators for hexahedral meshes.
The following code creates a polyhedral mesh instance and fills it 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::TopologyKernel::add_face(). Note that in these cases, it is not guaranteed that a given mesh is three-manifold.
GeometricPolyhedralMeshV3f myMesh;
std::vector<OpenVolumeMesh::VertexHandle> vertices;
vertices.push_back(v0); vertices.push_back(v1);vertices.push_back(v4);
vertices.clear();
vertices.push_back(v1); vertices.push_back(v2);vertices.push_back(v4);
vertices.clear();
vertices.push_back(v0); vertices.push_back(v1);vertices.push_back(v2);
vertices.clear();
vertices.push_back(v0); vertices.push_back(v4);vertices.push_back(v2);
vertices.clear();
vertices.push_back(v0); vertices.push_back(v4);vertices.push_back(v3);
vertices.clear();
vertices.push_back(v2); vertices.push_back(v3);vertices.push_back(v4);
vertices.clear();
vertices.push_back(v0); vertices.push_back(v2);vertices.push_back(v3);
std::vector<OpenVolumeMesh::HalfFaceHandle> halffaces;
halffaces.push_back(myMesh.halfface_handle(f0, 1));
halffaces.push_back(myMesh.halfface_handle(f1, 1));
halffaces.push_back(myMesh.halfface_handle(f2, 0));
halffaces.push_back(myMesh.halfface_handle(f3, 1));
myMesh.add_cell(halffaces);
halffaces.clear();
halffaces.push_back(myMesh.halfface_handle(f4, 1));
halffaces.push_back(myMesh.halfface_handle(f5, 1));
halffaces.push_back(myMesh.halfface_handle(f3, 0));
halffaces.push_back(myMesh.halfface_handle(f6, 0));
myMesh.add_cell(halffaces);