Question

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

Was it helpful?

Solution

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

OTHER TIPS

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. This is how I do it using OpenMesh 4.1
Best practices may have changed somewhat; OpenMesh 6.2 is now out, but I haven't switched yet.

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;

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top