tutorial_02.docu 3.39 KB
 Mike Kremer committed Jan 09, 2012 1 2 /**  Mike Kremer committed Jan 09, 2012 3 \page tutorial_02 Tutorial 02: Using Iterators  Mike Kremer committed Jan 09, 2012 4   Mike Kremer committed Jan 17, 2012 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  Mike Kremer committed Feb 24, 2012 15 16 // Instantiate e.g. a geometric hexahedral mesh OpenVolumeMesh::GeometricHexahedralMeshV3d myMesh;  Mike Kremer committed Jan 17, 2012 17 18 19 20 21  // Fill mesh with geometry ... // Iterate over all half-edges  Mike Kremer committed Feb 24, 2012 22 for(OpenVolumeMesh::HalfEdgeIter he_it = myMesh.halfedges_begin();  Mike Kremer committed Jan 17, 2012 23  he_it != myMesh.halfedges_end(); ++he_it) {  Mike Kremer committed Jan 17, 2012 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  Mike Kremer committed Feb 24, 2012 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 committed Jan 17, 2012 33 for information on the bottom-up adjacencies.  Mike Kremer committed Jan 17, 2012 34 35 36  \code // Instantiate a polyhedral mesh  Mike Kremer committed Feb 24, 2012 37 OpenVolumeMesh::GeometricPolyhedralMeshV3f myMesh;  Mike Kremer committed Jan 17, 2012 38 39 40 41  // Fill mesh with geometry ...  Mike Kremer committed Jan 17, 2012 42 43 44 // Compute bottom-up adjacencies myMesh.update_adjacencies();  Mike Kremer committed Feb 24, 2012 45 typedef OpenVolumeMesh::VertexHandle VertexHandle;  Mike Kremer committed Jan 17, 2012 46 47 48 49 50  // Get first vertex in mesh VertexHandle vh = *(myMesh.vertices_begin()); // Iterate over all outgoing half-edges of vertex vh  Mike Kremer committed Feb 24, 2012 51 for(OpenVolumeMesh::VertexOHalfEdgeIter voh_it = myMesh.voh_iter(vh);  Mike Kremer committed Jan 17, 2012 52  voh_it.valid(); ++voh_it) {  Mike Kremer committed Jan 17, 2012 53 54 55 56 57 58  // Now dereferencing voh_it returns a half-edge handle ... } \endcode  Mike Kremer committed Jan 17, 2012 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 committed Jan 17, 2012 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 committed Jan 17, 2012 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  Mike Kremer committed Feb 24, 2012 77 OpenVolumeMesh::GeometricHexahedralMeshV3d myMesh;  Mike Kremer committed Jan 17, 2012 78 79 80 81  // Fill mesh with geometry ...  Mike Kremer committed Jan 17, 2012 82 83 84 // Compute bottom-up adjacencies myMesh.update_adjacencies();  Mike Kremer committed Jan 17, 2012 85 // Get handle of first cell  Mike Kremer committed Feb 24, 2012 86 OpenVolumeMesh::CellHandle ch = *(myMesh.cells_begin());  Mike Kremer committed Jan 17, 2012 87 88 89  // Iterate over the hexahedra in the same sheet that are adjacent // to the reference hexahedron (cell handle ch)  Mike Kremer committed Feb 24, 2012 90 for(OpenVolumeMesh::CellSheetCellIter csc_it = myMesh.csc_iter(ch);  Mike Kremer committed Jan 17, 2012 91  csc_it.valid(); ++csc_it) {  Mike Kremer committed Jan 17, 2012 92 93 94 95 96 97  // Now dereferencing csc_it returns a cell handle ... } \endcode  Mike Kremer committed Jan 09, 2012 98 **/