Developer Documentation
TetrahedralMeshIterators.cc
1 /*===========================================================================*\
2  * *
3  * OpenVolumeMesh *
4  * Copyright (C) 2011 by Computer Graphics Group, RWTH Aachen *
5  * www.openvolumemesh.org *
6  * *
7  *---------------------------------------------------------------------------*
8  * This file is part of OpenVolumeMesh. *
9  * *
10  * OpenVolumeMesh is free software: you can redistribute it and/or modify *
11  * it under the terms of the GNU Lesser General Public License as *
12  * published by the Free Software Foundation, either version 3 of *
13  * the License, or (at your option) any later version with the *
14  * following exceptions: *
15  * *
16  * If other files instantiate templates or use macros *
17  * or inline functions from this file, or you compile this file and *
18  * link it with other files to produce an executable, this file does *
19  * not by itself cause the resulting executable to be covered by the *
20  * GNU Lesser General Public License. This exception does not however *
21  * invalidate any other reasons why the executable file might be *
22  * covered by the GNU Lesser General Public License. *
23  * *
24  * OpenVolumeMesh is distributed in the hope that it will be useful, *
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27  * GNU Lesser General Public License for more details. *
28  * *
29  * You should have received a copy of the GNU LesserGeneral Public *
30  * License along with OpenVolumeMesh. If not, *
31  * see <http://www.gnu.org/licenses/>. *
32  * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36  * *
37  * $Revision$ *
38  * $Date$ *
39  * $LastChangedBy$ *
40  * *
41 \*===========================================================================*/
42 
43 #include <set>
44 
45 #include "TetrahedralMeshIterators.hh"
46 #include "TetrahedralMeshTopologyKernel.hh"
47 #include "../Core/Iterators.hh"
48 
49 namespace OpenVolumeMesh {
50 
51 //================================================================================================
52 // TetVertexIter
53 //================================================================================================
54 
55 
56 TetVertexIter::TetVertexIter(const CellHandle& _ref_h,
57  const TetrahedralMeshTopologyKernel* _mesh, int _max_laps) :
58 BaseIter(_mesh, _ref_h, _max_laps) {
59 
60  assert(_ref_h.is_valid());
61  assert(_mesh->cell(_ref_h).halffaces().size() == 4);
62 
63  // Get first half-face
64  HalfFaceHandle curHF = *_mesh->cell(_ref_h).halffaces().begin();
65  assert(curHF.is_valid());
66 
67  // Get first half-edge
68  assert(_mesh->halfface(curHF).halfedges().size() == 3);
69  HalfEdgeHandle curHE = *_mesh->halfface(curHF).halfedges().begin();
70  assert(curHE.is_valid());
71 
72  vertices_.push_back(_mesh->halfedge(curHE).to_vertex());
73 
74  curHE = _mesh->next_halfedge_in_halfface(curHE, curHF);
75 
76  vertices_.push_back(_mesh->halfedge(curHE).to_vertex());
77 
78  curHE = _mesh->next_halfedge_in_halfface(curHE, curHF);
79 
80  vertices_.push_back(_mesh->halfedge(curHE).to_vertex());
81 
82  curHF = _mesh->adjacent_halfface_in_cell(curHF, curHE);
83  curHE = _mesh->opposite_halfedge_handle(curHE);
84  curHE = _mesh->next_halfedge_in_halfface(curHE, curHF);
85 
86  vertices_.push_back(_mesh->halfedge(curHE).to_vertex());
87 
88  cur_index_ = 0;
89  BaseIter::valid(vertices_.size() > 0);
90  if(BaseIter::valid()) {
91  BaseIter::cur_handle(vertices_[cur_index_]);
92  }
93 }
94 
95 
96 TetVertexIter& TetVertexIter::operator--() {
97 
98  if (cur_index_ == 0) {
99  cur_index_ = vertices_.size() - 1;
100  --lap_;
101  if (lap_ < 0)
102  BaseIter::valid(false);
103  } else {
104  --cur_index_;
105  }
106 
107  BaseIter::cur_handle(vertices_[cur_index_]);
108 
109  return *this;
110 }
111 
112 
113 TetVertexIter& TetVertexIter::operator++() {
114 
115  ++cur_index_;
116  if(cur_index_ == vertices_.size()) {
117  cur_index_ = 0;
118  ++lap_;
119  if (lap_ >= max_laps_)
120  BaseIter::valid(false);
121  }
122 
123  BaseIter::cur_handle(vertices_[cur_index_]);
124 
125  return *this;
126 }
127 
128 } // Namespace OpenVolumeMesh