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 #include <set>
36 
37 #include "TetrahedralMeshIterators.hh"
38 #include "TetrahedralMeshTopologyKernel.hh"
39 #include "../Core/Iterators.hh"
40 
41 namespace OpenVolumeMesh {
42 
43 //================================================================================================
44 // TetVertexIter
45 //================================================================================================
46 
47 
48 TetVertexIter::TetVertexIter(const CellHandle& _ref_h,
49  const TetrahedralMeshTopologyKernel* _mesh, int _max_laps) :
50 BaseIter(_mesh, _ref_h, _max_laps) {
51 
52  assert(_ref_h.is_valid());
53 
54  TetrahedralMeshTopologyKernel::Cell cell = _mesh->cell(_ref_h);
55 
56  assert(cell.halffaces().size() == 4);
57 
58  // Get first half-face
59  HalfFaceHandle curHF = *cell.halffaces().begin();
60  assert(curHF.is_valid());
61 
62  // Get first half-edge
63  assert(_mesh->halfface(curHF).halfedges().size() == 3);
64  HalfEdgeHandle curHE = *_mesh->halfface(curHF).halfedges().begin();
65  assert(curHE.is_valid());
66 
67  vertices_.push_back(_mesh->halfedge(curHE).to_vertex());
68 
69  curHE = _mesh->next_halfedge_in_halfface(curHE, curHF);
70 
71  vertices_.push_back(_mesh->halfedge(curHE).to_vertex());
72 
73  curHE = _mesh->next_halfedge_in_halfface(curHE, curHF);
74 
75  vertices_.push_back(_mesh->halfedge(curHE).to_vertex());
76 
77  curHF = _mesh->adjacent_halfface_in_cell(curHF, curHE);
78  curHE = _mesh->opposite_halfedge_handle(curHE);
79  curHE = _mesh->next_halfedge_in_halfface(curHE, curHF);
80 
81  vertices_.push_back(_mesh->halfedge(curHE).to_vertex());
82 
83  cur_index_ = 0;
84  BaseIter::valid(vertices_.size() > 0);
85  if(BaseIter::valid()) {
86  BaseIter::cur_handle(vertices_[cur_index_]);
87  }
88 }
89 
90 
91 TetVertexIter& TetVertexIter::operator--() {
92 
93  if (cur_index_ == 0) {
94  cur_index_ = vertices_.size() - 1;
95  --lap_;
96  if (lap_ < 0)
97  BaseIter::valid(false);
98  } else {
99  --cur_index_;
100  }
101 
102  BaseIter::cur_handle(vertices_[cur_index_]);
103 
104  return *this;
105 }
106 
107 
108 TetVertexIter& TetVertexIter::operator++() {
109 
110  ++cur_index_;
111  if(cur_index_ == vertices_.size()) {
112  cur_index_ = 0;
113  ++lap_;
114  if (lap_ >= max_laps_)
115  BaseIter::valid(false);
116  }
117 
118  BaseIter::cur_handle(vertices_[cur_index_]);
119 
120  return *this;
121 }
122 
123 } // Namespace OpenVolumeMesh