0

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.

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).

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)?

4

3 回答 3

2

我认为你可以使用:

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

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

于 2013-10-07T10:06:21.443 回答
1

你想要的可能是这个例子:

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)));
}
于 2015-01-20T01:29:37.767 回答
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;

}
于 2016-09-21T02:20:17.020 回答