tutorial_02.docu 3.39 KB
Newer Older
1 2
/**

Mike Kremer's avatar
Mike Kremer committed
3
\page tutorial_02 Tutorial 02: Using Iterators
4

5 6 7 8 9 10 11 12 13 14
%OpenVolumeMesh is shipped with a set of useful iterators and circulators to
comfortably address the entities (local neighborhood of entities) in a polyhedral mesh.
See Section \ref iterators_and_circulators for a more detailed description of all
available iterators and circulators. In this tutorial, we examine how to use the iterators
that come along with %OpenVolumeMesh.

In the first example, we simply iterate over all half-edges of a mesh using
the OpenVolumeMesh::HalfEdgeIter iterator class:

\code
15 16
// Instantiate e.g. a geometric hexahedral mesh
OpenVolumeMesh::GeometricHexahedralMeshV3d myMesh;
17 18 19 20 21

// Fill mesh with geometry
...

// Iterate over all half-edges
22
for(OpenVolumeMesh::HalfEdgeIter he_it = myMesh.halfedges_begin();
23
        he_it != myMesh.halfedges_end(); ++he_it) {
24 25 26 27 28 29 30

    // Now dereferencing he_it returns a half-edge handle
    ...
}
\endcode

In the next example, we iterate over all incident outgoing half-edges of a given
31 32
vertex. Note that this iterator needs bottom-up adjacencies to be computed for
the mesh. Otherwise, the iterator would not be valid. See Section \ref bottom_up
Mike Kremer's avatar
Mike Kremer committed
33
for information on the bottom-up adjacencies.
34 35 36

\code
// Instantiate a polyhedral mesh
37
OpenVolumeMesh::GeometricPolyhedralMeshV3f myMesh;
38 39 40 41

// Fill mesh with geometry
...

Mike Kremer's avatar
Mike Kremer committed
42 43 44
// Compute bottom-up adjacencies
myMesh.update_adjacencies();

45
typedef OpenVolumeMesh::VertexHandle VertexHandle;
46 47 48 49 50

// Get first vertex in mesh
VertexHandle vh = *(myMesh.vertices_begin());

// Iterate over all outgoing half-edges of vertex vh
51
for(OpenVolumeMesh::VertexOHalfEdgeIter voh_it = myMesh.voh_iter(vh);
52
        voh_it.valid(); ++voh_it) {
53 54 55 56 57 58

    // Now dereferencing voh_it returns a half-edge handle
    ...
}
\endcode

Mike Kremer's avatar
Mike Kremer committed
59 60 61
In the last example, we create a hexahedral mesh and use its specialized OpenVolumeMesh::CellSheetCellIter
iterator class. This iterator expects a cell handle as parameter and iterates over all adjacent cells
in the same \e sheet. A sheet is, in the terms of the \e spatial \e twist \e continuum, short STC,
Mike Kremer's avatar
Mike Kremer committed
62 63
a "layer" of hexahedra as illustrated in the following figure. For rurther reading on STC,
refer to \cite MurdochSTC. The gray shaded hexahedra form
Mike Kremer's avatar
Mike Kremer committed
64 65 66 67 68 69 70 71 72 73 74 75 76
a sheet, all other cells (except the outlines of the boundary cells) are invisible in this illustration.

\image html sheet_illustration.png

Starting from a hexahedron, we determine its virtual axis that is \e orthogonal to the desired sheet
(note that there are always two opposing virtual axes that are orthogonal to such a sheet).
We create our sheet iterator by passing the reference cell's handle as well as an orthogonal
virtual axis with respect to that cell to the iterator's constructor. The iterators then
iterates over all directly adjacent cells in the same sheet (those hexahedra that share a common
face with the reference hexahedron). Consider the following code:

\code
// Instantiate a hexahedral mesh
77
OpenVolumeMesh::GeometricHexahedralMeshV3d myMesh;
Mike Kremer's avatar
Mike Kremer committed
78 79 80 81

// Fill mesh with geometry
...

Mike Kremer's avatar
Mike Kremer committed
82 83 84
// Compute bottom-up adjacencies
myMesh.update_adjacencies();

Mike Kremer's avatar
Mike Kremer committed
85
// Get handle of first cell
86
OpenVolumeMesh::CellHandle ch = *(myMesh.cells_begin());
Mike Kremer's avatar
Mike Kremer committed
87 88 89

// Iterate over the hexahedra in the same sheet that are adjacent
// to the reference hexahedron (cell handle ch)
90
for(OpenVolumeMesh::CellSheetCellIter csc_it = myMesh.csc_iter(ch);
91
        csc_it.valid(); ++csc_it) {
Mike Kremer's avatar
Mike Kremer committed
92 93 94 95 96 97

    // Now dereferencing csc_it returns a cell handle
    ...
}
\endcode

98
**/