# Navigation and Iteration

### Collection Iterators

Use these routines to iterate over all of the elements in the mesh.

Note: Generally, modifying the mesh in the midst of iteration is not supported.

HalfedgeMesh::vertices()

Iterate over the vertices in a mesh.

for(Vertex v : mesh.vertices()) {
// do science here
}


HalfedgeMesh::halfedges()

Iterate over all of the halfedges in a mesh (both real and imaginary, if the mesh has boundary).

for(Halfedge he : mesh.halfedges()) {
// do science here
}


HalfedgeMesh::realHalfedges()

Iterate over the real halfedges in a mesh.

for(Halfedge he : mesh.realHalfedges()) {
// do science here
}

Note that on a boundary edge between vertices i <--> j, this set will only include a halfedge from i --> j, but not from j --> i (or vice versa).

HalfedgeMesh::imaginaryHalfedges()

Iterate over the imaginary halfedges in a mesh.

for(Halfedge he : mesh.imaginaryHalfedges()) {
// do science here
}

Note that on a boundary edge between vertices i <--> j, this set will only include a halfedge from i --> j, but not from j --> i (or vice versa).

HalfedgeMesh::edges()

Iterate over the edges in a mesh.

for(Edge e : mesh.edges()) {
// do science here
}


HalfedgeMesh::faces()

Iterate over the faces in a mesh.

for(Face f : mesh.faces()) {
// do science here
}


## Neighborhood Iterators

Use these routines to iterate over the neighbors of a mesh element.

Note: neighborhoods on $\Delta$-complexes

The iterators in this section may have unexpected behavior in the advanced case of a $\Delta$-complex, when there are (e.g.) self-edges, or multiple edges between a pair of vertices. Essentially, these iterators always naively traverse the local neighborhood, even if that neighborhood might include duplicate elements.

For instance, if a $\Delta$-complex has multiple edges connecting vertex va to vertex vb, then iterating va.adjacentVertices() will return vb multiple times.

Of course, for ordinary triangle mesh they will behave as expected. See the Delta complex section for more information.

### Around a vertex

Vertex::outgoingHalfedges()

Iterate over the halfedges which point outward from a vertex.

for(Halfedge he : vert.outgoingHalfedges()) {
assert(he.vertex() == vert); // true
// do science here
}


Vertex::incomingHalfedges()

Iterate over the halfedges which point inward at a vertex.

for(Halfedge he : vert.incomingHalfedges()) {
assert(he.twin().vertex() == vert); // true
// do science here
}


Vertex::adjacentVertices()

Iterate over the vertices edge-connected to this vertex.

for(Vertex v : vert.adjacentVertices()) {
// do science here
}


Vertex::adjacentEdges()

Iterate over the edges incident on this vertex.

for(Edge e : vert.adjacentEdges()) {
// do science here
}


Vertex::adjacentFaces()

Iterate over the faces incident on this vertex.

for(Face f : vert.adjacentFaces()) {
// do science here
}


### Around an edge

Edge::adjacentHalfedges()

Iterate over the two halfedges incident on this edge.

for(Halfedge he : edge.adjacentHalfedges()) {
// do science here
}


Edge::adjacentFaces()

Iterate over the (one or two) faces incident on this edge.

for(Face f : edge.adjacentFaces()) {
// do science here
}


### Around a face

Face::adjacentVertices()

Iterate over the vertices adjacent to a face.

for(Vertex v : face.adjacentVertices()) {
// do science here
}


Face::adjacentHalfedges()

Iterate over the halfedges incident on a face.

for(Halfedge he : face.adjacentHalfedges()) {
// do science here
}


Face::adjacentEdges()

Iterate over the edges on the boundary of a face.

for(Edge e : face.adjacentEdges()) {
// do science here
}


Face::adjacentFaces()

Iterate over the faces adjacent to a face, across each edge.

for(Face f : face.adjacentFaces()) {
// do science here
}


### Around a boundary loop

BoundaryLoop::adjacentVertices()

Iterate over the vertices adjacent to a boundary loop.

for(Vertex v : boundaryLoop.adjacentVertices()) {
// do science here
}


BoundaryLoop::adjacentHalfedges()

Iterate over the (exterior) halfedges incident on a boundary loop.

for(Halfedge he : boundaryLoop.adjacentHalfedges()) {
// do science here
}


BoundaryLoop::adjacentEdges()

Iterate over the edges on the boundary of a boundary loop.

for(Edge e : boundaryLoop.adjacentEdges()) {
// do science here
}


## Accessors

Use these routines to access elements of the mesh by their index.

Warning

The indexing routines in the section are only valid when the mesh is compressed.

Halfedge HalfedgeMesh::halfedge(size_t index)

Constructs a reference to the i’th halfedge in the mesh. 0 <= index < nHalfedges().

Vertex HalfedgeMesh::vertex(size_t index)

Constructs a reference to the i’th vertex in the mesh. 0 <= index < nVertices().

Face HalfedgeMesh::face(size_t index)

Constructs a reference to the i’th face in the mesh. 0 <= index < nFaces().

Edge HalfedgeMesh::edge(size_t index)

Constructs a reference to the i’th edge in the mesh. 0 <= index < nEdges().

Face HalfedgeMesh::face(size_t index)

Constructs a reference to the i’th face in the mesh. 0 <= index < nFaces().

Face HalfedgeMesh::boundaryLoop(size_t index)

Constructs a reference to the i’th boundary loop in the mesh. 0 <= index < nBoundaryLoops().