【OpenMesh】一些基本操作:翻转和折叠

这一节中你将学到一些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.

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值