• 【OpenMesh】Some basic operations: Flipping and collapsing edges


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


  • 相关阅读:
    hihoCoder #1176 : 欧拉路·一 (简单)
    228 Summary Ranges 汇总区间
    227 Basic Calculator II 基本计算器II
    226 Invert Binary Tree 翻转二叉树
    225 Implement Stack using Queues 队列实现栈
    224 Basic Calculator 基本计算器
    223 Rectangle Area 矩形面积
    222 Count Complete Tree Nodes 完全二叉树的节点个数
    221 Maximal Square 最大正方形
    220 Contains Duplicate III 存在重复 III
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3194177.html
Copyright © 2020-2023  润新知