繁体   English   中英

使用OpenMesh遍历边缘并获得顶点

[英]Iterating over edges and getting their vertices with OpenMesh

我开始使用OpenMesh遍历可能具有整体的网格,并且想知道什么是实际检索与每个边缘关联的顶点的好方法。

对于半边,有网格的opposite_he_opposite_vhopposite_vh _vh方法,但是如果不存在相反的半边(我们当前在边界半边上),它们会触发错误。

考虑到我会经常遇到这些问题,有什么更好的方法可以遍历所有边缘(实际上我并不特别在意半边,我正在获取每个边的数据,但是方向并不重要。需要两个顶点)吗?

我认为您可以使用:

  1. MyMesh::to_vertex_handle(MyMesh::HalfedgeHandle)
  2. MyMesh::from_vertex_handle(MyMesh::HalfedgeHandle)

请确认您可以找到以下方法:-)

您想要的可能是以下示例:

for ( mesh_t::EdgeIter eit   = _m.edges_begin(); eit != edgesEnd; ++eit) {
  const MeshType::Point to   = _m.point(_m.to_vertex_handle(_m.halfedge_handle(eit,0)));
  const MeshType::Point from = _m.point(_m.from_vertex_handle(_m.halfedge_handle(eit,0)));
}

其他答案之一对我不起作用b / c迭代器需要取消引用。 这就是我使用OpenMesh 4.1的方法
最佳做法可能有所改变; OpenMesh 6.2现在已经发布,但是我还没有切换。

MyMesh mesh;    // create the mesh instance
...             // build your mesh

// use an edge iterator to iterate over all the edges
for (MyMesh::EdgeIter eit = mesh.edges_begin(); eit != mesh.edges_end(); ++eit) 
{       
    // check for boundary.  (one halfedge won't be valid if boundary)
    // note: you have to dereference the edge iterator
    if (!mesh.is_boundary(*eit))
    {
        // if you want vertex handles use:
        auto vh1 = mesh.to_vertex_handle(mesh.halfedge_handle(*eit, 0));
        auto vh2 = mesh.from_vertex_handle(mesh.halfedge_handle(*eit, 0));

        // if you want handles of faces adjacent to the edge use:
        auto fh1 = mesh.face_handle(mesh.halfedge_handle(*eit, 0));
        auto fh2 = mesh.opposite_face_handle(mesh.halfedge_handle(*eit, 0));

        // if you need normal vectors of those faces use:
        auto face1Norm = mesh.normal(fh1);
        auto face2Norm = mesh.normal(fh2);
    }
    else  // boundary.  One of the half edges won't be valid
        std::cout << "found a boundary edge.  skipping it" << std::endl;

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM