简介
参考链接
openVolumeMesh 官网链接
https://www.graphics.rwth-aachen.de/software/openvolumemesh/download/
中国科技大学 - Volumetric Mesh Framework
http://staff.ustc.edu.cn/~fuxm/code/index.html
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(-1.0, 0.0, 0.0));
OpenVolumeMesh::VertexHandle v1 = myMesh.add_vertex(Vec3f( 0.0, 0.0, 1.0));
OpenVolumeMesh::VertexHandle v2 = myMesh.add_vertex(Vec3f( 1.0, 0.0, 0.0));
//OpenVolumeMesh::VertexHandle v3 = myMesh.add_vertex(Vec3f( 0.0, 0.0,-1.0));
OpenVolumeMesh::VertexHandle v4 = myMesh.add_vertex(Vec3f( 0.0, 1.0, 0.0));
std::vector<OpenVolumeMesh::VertexHandle> vertices;
// Add faces
vertices.push_back(v0); vertices.push_back(v1);vertices.push_back(v4);
OpenVolumeMesh::FaceHandle f0 = myMesh.add_face(vertices);
vertices.clear();
vertices.push_back(v1); vertices.push_back(v2);vertices.push_back(v4);
OpenVolumeMesh::FaceHandle f1 = myMesh.add_face(vertices);
vertices.clear();
vertices.push_back(v0); vertices.push_back(v1);vertices.push_back(v2);
OpenVolumeMesh::FaceHandle f2 = myMesh.add_face(vertices);
vertices.clear();
vertices.push_back(v0); vertices.push_back(v4);vertices.push_back(v2);
OpenVolumeMesh::FaceHandle f3 = myMesh.add_face(vertices);
//vertices.clear();
//vertices.push_back(v0); vertices.push_back(v4);vertices.push_back(v3);
//OpenVolumeMesh::FaceHandle f4 = myMesh.add_face(vertices);
//
//vertices.clear();
//vertices.push_back(v2); vertices.push_back(v3);vertices.push_back(v4);
//OpenVolumeMesh::FaceHandle f5 = myMesh.add_face(vertices);
//
//vertices.clear();
//vertices.push_back(v0); vertices.push_back(v2);vertices.push_back(v3);
//OpenVolumeMesh::FaceHandle f6 = myMesh.add_face(vertices);
std::vector<OpenVolumeMesh::HalfFaceHandle> halffaces;
// Add first tetrahedron
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);
// Add second tetrahedron
//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);
// 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("test.ovm", myMesh);
// save_mesh_graph("test.ovm", myMesh);
return 0;
}
TIPS
经过简单的修改,生成了一个四面体,原本有两个四面体,如果自己做验证的话会不清晰。
文件还算清晰
- 首先生成点
- 根据点的索引生成面
- 根据面的索引生成cell(小块)
image
ovm文件
OVM ASCII
Vertices
4
-1 0 0
0 0 1
1 0 0
0 1 0
Edges
6
0 1
1 3
3 0
1 2
2 3
2 0
Faces
4
3 0 2 4
3 6 8 3
3 0 6 10
3 5 9 10
Polyhedra
1
4 1 3 4 7
自问自答
QU: myMesh.halfface_handle(fx, 1) 第二个参数有的是1 有的是0 是什么意思??
AN:猜测使用右手螺旋定则,得到法向量,也就是面的朝向。
QU: ovm 文件生成的规则是什么?
AN: (*゜Д゜)σ凸←自爆按钮 还不知道呢? 网上也没有文件说明,除非看代码。本人又菜... 如果有人知道请告诉我
---------------------------我的天空里没有太阳,总是黑夜,但并不暗,因为有东西代替了太阳。虽然没有太阳那么明亮,但对我来说已经足够。凭借着这份光,我便能把黑夜当成白天。我从来就没有太阳,所以不怕失去。
--------《白夜行》