这一节中你将学到一些OpenMesh中早已提供的基础操作。
内容包括三角形网格边的翻转以及通过连接邻接的顶点边缘折叠。
简单的代码例子:
内容包括三角形网格边的翻转以及通过连接邻接的顶点边缘折叠。
三角形网格的翻转(Flipping edges)
考虑到两个邻接面的三角形网格中存在两种不同内部边缘设置。调用函数OpenMesh::TriConnectivity::flip(EdgeHandle _eh)将翻转特定的边到其相反的方向,如下图所述。
TriMesh mesh;
// Add some vertices
TriMesh::VertexHandle vhandle[4];
vhandle[0] = mesh.add_vertex(MyMesh::Point(0, 0, 0));
vhandle[1] = mesh.add_vertex(MyMesh::Point(0, 1, 0));
vhandle[2] = mesh.add_vertex(MyMesh::Point(1, 1, 0));
vhandle[3] = mesh.add_vertex(MyMesh::Point(1, 0, 0));
// Add two faces
std::vector<TriMesh::VertexHandle> face_vhandles;
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[0]);
mesh.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[3]);
mesh.add_face(face_vhandles);
// Now the edge adjacent to the two faces connects
// vertex vhandle[0] and vhandle[2].
// Find this edge and then flip it
for(TriMesh::EdgeIter it = mesh.edges_begin(); it != mesh.edges_end(); ++it) {
if(!mesh.is_boundary(it.handle())) {
// Flip edge
mesh.flip(it.handle());
}
}
// The edge now connects vertex vhandle[1] and vhandle[3].
边缘折叠(Collapsing edges)
这一节中你将学到如何进行边缘折叠比如连接两个邻接顶点。OpenMesh提供函数OpenMesh::PolyConnectivity::collapse(HalfedgeHandle _heh)实现这一功能。这会折叠halfedge的起始顶点(halfedge直接指向的方向)到结束顶点,如下图所述。注意边缘折叠会导致网格拓扑不一致。你应该在边缘折叠之后验证一致性,通过调用OpenMesh::PolyConnectivity::is_collapse_ok()。
简单的代码例子:
PolyMesh mesh;
// Add some vertices as in the illustration above
PolyMesh::VertexHandle vhandle[7];
vhandle[0] = mesh.add_vertex(MyMesh::Point(-1, 1, 0));
vhandle[1] = mesh.add_vertex(MyMesh::Point(-1, 3, 0));
vhandle[2] = mesh.add_vertex(MyMesh::Point(0, 0, 0));
vhandle[3] = mesh.add_vertex(MyMesh::Point(0, 2, 0));
vhandle[4] = mesh.add_vertex(MyMesh::Point(0, 4, 0));
vhandle[5] = mesh.add_vertex(MyMesh::Point(1, 1, 0));
vhandle[6] = mesh.add_vertex(MyMesh::Point(1, 3, 0));
// Add three quad faces
std::vector<PolyMesh::VertexHandle> face_vhandles;
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[3]);
mesh.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[3]);
face_vhandles.push_back(vhandle[5]);
face_vhandles.push_back(vhandle[4]);
mesh.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[3]);
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[6]);
face_vhandles.push_back(vhandle[5]);
mesh.add_face(face_vhandles);
// Now find the edge between vertex vhandle[2]
// and vhandle[3]
for(PolyMesh::HalfedgeIter it = mesh.halfedges_begin(); it != mesh.halfedges_end(); ++it) {
if(to_vertex_handle(it.handle()) == vhandle[3] &&
from_vertex_handle(it.handle()) == vhandle[2]) {
// Collapse edge
mesh.collapse(it.handle());
break;
}
}
// Our mesh now looks like in the illustration above after the collapsing.