OpenMesh 删除网格顶点

 

OpenMesh 提供了 delete_vertex() 函数来实现从网格中删除顶点,在删除掉顶点的同时,所有与该顶点相连的边也同时被删除。

OpenMesh 官方文档 中给的顶点删除函数声明如下:

void OpenMesh::PolyConnectivity::delete_vertex(VertexHandle _vh, bool _delete_isolated_vertices = true)

Mark vertex and all incident edges and faces deleted.

Items marked deleted will be removed by garbageCollection().

Attention: Needs the Attributes::Status attribute for vertices, edges and faces.

 

需要注意的是,在删除几何元素前,需要获取网格顶点、边和面的状态属性,并在删除结束后释放。所有正确的删除网格顶点的代码如下:

 

MyMesh mesh;
vector<MyMesh::VertexHandle>    delete_vh;     //删除顶点的集合
if (!mesh.has_vertex_status())  mesh.request_vertex_status();
if (!mesh.has_face_status())    mesh.request_face_status();
if (!mesh.has_edge_status())    mesh.request_edge_status();

for (auto vit=mesh.vertices_begin(); vit!=mesh.vertices_end(); vit++)
{
    if (find(delete_vh.begin(), delete_vh.end(), vit.handle()) ==delete_vh.end())
    {
        mesh.delete_vertex(vit.handle(), true);
    }
}
mesh.garbage_collection();

if (mesh.has_vertex_status())  mesh.release_vertex_status();
if (mesh.has_face_status())    mesh.release_face_status();
if (mesh.has_edge_status())    mesh.release_edge_status();

 

posted @ 2015-07-20 16:43  VVingerfly  阅读(2165)  评论(1编辑  收藏  举报