In this tutorial you will learn how to navigate on a mesh using the OpenMesh library. In the previous chapter (see Mesh Iterators and Circulators) you have learned how to iterate over vertices, edges, halfedges and faces as well as circulate over certain structures such as 1-rings and many more. So in this tutorial we will focus on efficiently using the halfedge data structure and some very useful attributes such as the boundary flag. We assume that you already made yourself familiar with the halfedge structure which is used in OpenMesh. Further information on this topic can be found in The Halfedge Data Structure.
So let's start with navigating over halfedges of a mesh. Assume we have the following mesh topology:
We can now select an arbitrary halfedge of this mesh which then offers either one of two possible navigations:
In both cases the code would look something like the following example. Depending on whether the initial halfedge is adjacent to a face or not, we will either navigate on the boundary halfedges of our mesh or along the inner halfedges of a face:
As you have seen in the previous section, navigating along boundaries is very simple. In general OpenMesh also offers a boundary attribute for edges, vertices and faces. So testing i.e. whether a face is a boundary face is quite simple using OpenMesh::PolyConnectivity::is_boundary().
So for each type we can make use of one of the following functions:
OpenMesh offers quite a lot of iterators and circulators to easily iterate over the structures of a mesh. A very helpful iterator is the OpenMesh::PolyConnectivity::VertexIHalfedgeIter or the OpenMesh::PolyConnectivity::VertexOHalfedgeIter which are used to iterate over all incoming/outgoing halfedges of a vertex. So, sticking to the illustration below, a OpenMesh::PolyConnectivity:V:ertexIHalfedgeIter for the lower most vertex would iterate over all incoming halfedges (blue), whereas the OpenMesh::PolyConnectivity::OpenMesh::PolyConnectivity::VertexOHalfedgeIter would iterate over all outgoing halfedges (red):
A schematic code example of how to use the halfedge iterators as described above:
The halfedge structure splits every edge into two directional parts by creating two directed edges out of one undirected edge. So for every halfedge there exists its counterpart pointing in the opposite direction. OpenMesh allows to easily navigate through opposing halfedges via the function OpenMesh::Concepts::KernelT< FinalMeshItems >::opposite_halfedge_handle(). So in the illustration below
opposite_halfedge_handle() for the blue halfedge would return the red halfedge:
Use this function as described in the example below:
There are also a few more functions that offer easy access to opposing structures:
If you have an halfedge, you can get the to and the from handles of the adjacent vertices.