简介
Hexahedron 六面体网格,基于 openVolumeMesh 格式的程序生成cube
code
// C++ includes
#include <iostream>
#include <vector>
// Include vector classes
#include <OpenVolumeMesh/Geometry/VectorT.hh>
// Include polyhedral mesh kernel
#include <OpenVolumeMesh/Mesh/PolyhedralMesh.hh>
#include <OpenVolumeMesh/FileManager/FileManager.hh>
// Make some typedefs to facilitate(使...容易) your life
typedef OpenVolumeMesh::Geometry::Vec3f Vec3f;// 顶点的结构体
typedef OpenVolumeMesh::GeometryKernel<Vec3f> PolyhedralMeshV3f; // 体的定义
int main(int _argc, char** _argv) {
// Create mesh object
PolyhedralMeshV3f myMesh;
// Add eight(可能作者想生成一个体但是并没有,生成了一个四棱锥) vertices
OpenVolumeMesh::VertexHandle v0 = myMesh.add_vertex(Vec3f( 0.0, 0.0, 0.0));
OpenVolumeMesh::VertexHandle v1 = myMesh.add_vertex(Vec3f( 1.0, 0.0, 0.0));
OpenVolumeMesh::VertexHandle v2 = myMesh.add_vertex(Vec3f( 1.0, 1.0, 0.0));
OpenVolumeMesh::VertexHandle v3 = myMesh.add_vertex(Vec3f( 0.0, 1.0, 0.0));
OpenVolumeMesh::VertexHandle v4 = myMesh.add_vertex(Vec3f( 0.0, 0.0, 1.0));
OpenVolumeMesh::VertexHandle v5 = myMesh.add_vertex(Vec3f( 1.0, 0.0, 1.0));
OpenVolumeMesh::VertexHandle v6 = myMesh.add_vertex(Vec3f( 1.0, 1.0, 1.0));
OpenVolumeMesh::VertexHandle v7 = myMesh.add_vertex(Vec3f( 0.0, 1.0, 1.0));
std::vector<OpenVolumeMesh::VertexHandle> vertices;
// Add faces
vertices.push_back(v0); vertices.push_back(v3); vertices.push_back(v2); vertices.push_back(v1);
OpenVolumeMesh::FaceHandle f0 = myMesh.add_face(vertices);
vertices.clear();
vertices.push_back(v4); vertices.push_back(v5);vertices.push_back(v6); vertices.push_back(v7);
OpenVolumeMesh::FaceHandle f1 = myMesh.add_face(vertices);
vertices.clear();
vertices.push_back(v0); vertices.push_back(v1); vertices.push_back(v5); vertices.push_back(v4);
OpenVolumeMesh::FaceHandle f2 = myMesh.add_face(vertices);
vertices.clear();
vertices.push_back(v1); vertices.push_back(v2);vertices.push_back(v6); vertices.push_back(v5);
OpenVolumeMesh::FaceHandle f3 = myMesh.add_face(vertices);
vertices.clear();
vertices.push_back(v2); vertices.push_back(v3); vertices.push_back(v7); vertices.push_back(v6);
OpenVolumeMesh::FaceHandle f4 = myMesh.add_face(vertices);
vertices.clear();
vertices.push_back(v0); vertices.push_back(v4); vertices.push_back(v7); vertices.push_back(v3);
OpenVolumeMesh::FaceHandle f5 = myMesh.add_face(vertices);
std::vector<OpenVolumeMesh::HalfFaceHandle> halffaces;
// Add first Hexahedron
halffaces.push_back(myMesh.halfface_handle(f0, 1)); // 0 1 4 正面
halffaces.push_back(myMesh.halfface_handle(f1, 1)); // 1 2 4 正面
halffaces.push_back(myMesh.halfface_handle(f2, 1)); // 0 1 2 背面
halffaces.push_back(myMesh.halfface_handle(f3, 1)); // 0 4 2 底面
halffaces.push_back(myMesh.halfface_handle(f4, 1)); // 0 1 2 背面
halffaces.push_back(myMesh.halfface_handle(f5, 1)); // 0 4 2 底面
myMesh.add_cell(halffaces);
// Print positions of vertices to std out
for(OpenVolumeMesh::VertexIter v_it = myMesh.vertices_begin();
v_it != myMesh.vertices_end(); ++v_it) {
std::cout << "Position of vertex " << v_it->idx() << ": " <<
myMesh.vertex(*v_it) << std::endl;
}
OpenVolumeMesh::IO::FileManager fileManager;
fileManager.writeFile("cube.ovm", myMesh);
return 0;
}
file
OVM ASCII
Vertices
8
0 0 0
1 0 0
1 1 0
0 1 0
0 0 1
1 0 1
1 1 1
0 1 1
Edges
12
0 3
3 2
2 1
1 0
4 5
5 6
6 7
7 4
1 5
4 0
2 6
3 7
Faces
6
4 0 2 4 6
4 8 10 12 14
4 7 16 9 18
4 5 20 11 17
4 3 22 13 21
4 19 15 23 1
Polyhedra
1
6 1 3 5 7 9 11