OpenMesh find edge connecting two vertices

920 views Asked by At

Is there a readily available function in OpenMesh that returns the edge handle connecting two vertices? For half edges there is the find_halfedge(vertex1, vertex2) function, but I could not find a corresponding find_edge(vertex1, vertex2) function. Currently I'm using my own, but I was wondering if there is any better way than this. Essentially I'm iterating over the surrounding edges of the two vertices and check where their halfedges point to:

MyMesh::EdgeHandle find_edge(MyMesh & mesh, MyMesh::VertexHandle & v1, MyMesh::VertexHandle & v2 ){
  for (MyMesh::VertexEdgeIter edge =  mesh.ve_iter(v1); edge.is_valid(); ++edge){
    if( (mesh.from_vertex_handle((*edge).h0())==v1) && (mesh.to_vertex_handle((*edge).h0())==v2)){
        return *edge;     
    }
    if( (mesh.from_vertex_handle((*edge).h0())==v2) && (mesh.to_vertex_handle((*edge).h0())==v1)){
        return *edge;     
    }
  }
  std::cout<<"No common edge between v1 and v2"<<std::endl;
  MyMesh::EdgeHandle edge_null;
  return edge_null;
}
1

There are 1 answers

0
jsb On BEST ANSWER

There is no built-in find_edge method, but you can readily construct one from find_halfedge, as halfedges know which edge they belong to:

MyMesh::EdgeHandle find_edge(const MyMesh& m, MyMesh::VertexHandle v1, MyMesh::VertexHandle v2)
{
    MyMesh::HalfedgeHandle heh = m.find_halfedge(v1, v2);
    if (heh.is_valid()) {
        return m.edge_handle(heh);
    }
    else {
        return MyMesh::InvalidEdgeHandle;
    }
}