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;
}
There is no built-in
find_edge
method, but you can readily construct one fromfind_halfedge
, as halfedges know which edge they belong to: