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