OpenMesh

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IteratorsT.hh
1 /*===========================================================================*\
2 * *
3 * OpenMesh *
4 * Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
5 * www.openmesh.org *
6 * *
7 *---------------------------------------------------------------------------*
8 * This file is part of OpenMesh. *
9 * *
10 * OpenMesh 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 * OpenMesh 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 OpenMesh. If not, *
31 * see <http://www.gnu.org/licenses/>. *
32 * *
33 \*===========================================================================*/
34
35 /*===========================================================================*\
36 * *
37 * $Revision: 838 $ *
38 * $Date: 2013-06-12 15:41:43 +0200 (Mi, 12. Jun 2013) $ *
39 * *
40 \*===========================================================================*/
41
42 #ifndef OPENMESH_ITERATORS_HH
43 #define OPENMESH_ITERATORS_HH
44
45 //=============================================================================
46 //
47 // Iterators for PolyMesh/TriMesh
48 //
49 //=============================================================================
50
51
52
53 //== INCLUDES =================================================================
54
55 #include <OpenMesh/Core/System/config.h>
56 #include <OpenMesh/Core/Mesh/Status.hh>
57 #include <cassert>
58 #include <cstddef>
59
60
61 //== NAMESPACES ===============================================================
62
63 namespace OpenMesh {
64 namespace Iterators {
65
66
67 //== FORWARD DECLARATIONS =====================================================
68
69
70 template <class Mesh> class ConstVertexIterT;
71 template <class Mesh> class VertexIterT;
72 template <class Mesh> class ConstHalfedgeIterT;
73 template <class Mesh> class HalfedgeIterT;
74 template <class Mesh> class ConstEdgeIterT;
75 template <class Mesh> class EdgeIterT;
76 template <class Mesh> class ConstFaceIterT;
77 template <class Mesh> class FaceIterT;
78
79
80 template <class Mesh, class ValueHandle, class MemberOwner, bool (MemberOwner::*PrimitiveStatusMember)() const, size_t (MemberOwner::*PrimitiveCountMember)() const>
81 class GenericIteratorT {
82 public:
83 //--- Typedefs ---
84
85 typedef ValueHandle value_handle;
86 typedef value_handle value_type;
87 typedef std::bidirectional_iterator_tag iterator_category;
88 typedef std::ptrdiff_t difference_type;
89 typedef const value_type& reference;
90 typedef const value_type* pointer;
91 typedef const Mesh* mesh_ptr;
92 typedef const Mesh& mesh_ref;
93
95 GenericIteratorT()
96 : mesh_(0), skip_bits_(0)
97 {}
98
100 GenericIteratorT(mesh_ref _mesh, value_handle _hnd, bool _skip=false)
101 : mesh_(&_mesh), hnd_(_hnd), skip_bits_(0)
102 {
103 if (_skip) enable_skipping();
104
105 // Set vertex handle invalid if the mesh contains no vertex
106 if((mesh_->*PrimitiveCountMember)() == 0) hnd_ = value_handle(-1);
107 }
108
110 reference operator*() const {
111 return hnd_;
112 }
113
115 pointer operator->() const {
116 return &hnd_;
117 }
118
120 value_handle handle() const {
121 return hnd_;
122 }
123
125 operator value_handle() const {
126 return hnd_;
127 }
128
130 bool operator==(const GenericIteratorT& _rhs) const {
131 return ((mesh_ == _rhs.mesh_) && (hnd_ == _rhs.hnd_));
132 }
133
135 bool operator!=(const GenericIteratorT& _rhs) const {
136 return !operator==(_rhs);
137 }
138
140 GenericIteratorT& operator++() {
141 hnd_.__increment();
142 if (skip_bits_)
143 skip_fwd();
144 return *this;
145 }
146
148 GenericIteratorT& operator--() {
149 hnd_.__decrement();
150 if (skip_bits_)
151 skip_bwd();
152 return *this;
153 }
154
156 void enable_skipping() {
157 if (mesh_ && (mesh_->*PrimitiveStatusMember)()) {
158 Attributes::StatusInfo status;
159 status.set_deleted(true);
160 status.set_hidden(true);
161 skip_bits_ = status.bits();
162 skip_fwd();
163 } else
164 skip_bits_ = 0;
165 }
166
168 void disable_skipping() {
169 skip_bits_ = 0;
170 }
171
172 private:
173
174 void skip_fwd() {
175 assert(mesh_ && skip_bits_);
176 while ((hnd_.idx() < (signed) (mesh_->*PrimitiveCountMember)())
177 && (mesh_->status(hnd_).bits() & skip_bits_))
178 hnd_.__increment();
179 }
180
181 void skip_bwd() {
182 assert(mesh_ && skip_bits_);
183 while ((hnd_.idx() >= 0) && (mesh_->status(hnd_).bits() & skip_bits_))
184 hnd_.__decrement();
185 }
186
187 protected:
188 mesh_ptr mesh_;
189 value_handle hnd_;
190 unsigned int skip_bits_;
191 };
192
193 //=============================================================================
194 } // namespace Iterators
195 } // namespace OpenMesh
196 //=============================================================================
197 #endif
198 //=============================================================================