简体   繁体   English

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

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

I am starting to use OpenMesh to go through meshes which may have wholes and am wondering what is the good way to actually retrieve the vertices associated with each edge. 我开始使用OpenMesh遍历可能具有整体的网格,并且想知道什么是实际检索与每个边缘关联的顶点的好方法。

For half-edges, there are the methods opposite_he_opposite_vh and opposite_vh of the mesh, but these trigger an error if the opposite half-edge does not exist (we are currently on a boundary half-edge). 对于半边,有网格的opposite_he_opposite_vhopposite_vh _vh方法,但是如果不存在相反的半边(我们当前在边界半边上),它们会触发错误。

Given that I'll encounter these often, what's a better way to iterate over all edges (I actually don't specifically care about half-edge, I'm getting data for each edge, but the direction doesn't matter. What I need are the two vertices)? 考虑到我会经常遇到这些问题,有什么更好的方法可以遍历所有边缘(实际上我并不特别在意半边,我正在获取每个边的数据,但是方向并不重要。需要两个顶点)吗?

I think you can use: 我认为您可以使用:

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

Please confirm you can find these methods :-) 请确认您可以找到以下方法:-)

What you want might be this example: 您想要的可能是以下示例:

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)));
}

One of the other answers didn't work for me b/c iterators needed to be dereferenced. 其他答案之一对我不起作用b / c迭代器需要取消引用。 This is how I do it using OpenMesh 4.1 这就是我使用OpenMesh 4.1的方法
Best practices may have changed somewhat; 最佳做法可能有所改变; OpenMesh 6.2 is now out, but I haven't switched yet. 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