OpenMesh
IteratorsT.hh
1 /*===========================================================================*\
2  * *
3  * OpenMesh *
4  * Copyright (C) 2001-2014 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: 990 $ *
38  * $Date: 2014-02-05 10:01:07 +0100 (Mi, 05 Feb 2014) $ *
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 #include <iterator>
60 
61 
62 //== NAMESPACES ===============================================================
63 
64 namespace OpenMesh {
65 namespace Iterators {
66 
67 
68 //== FORWARD DECLARATIONS =====================================================
69 
70 
71 template <class Mesh> class ConstVertexIterT;
72 template <class Mesh> class VertexIterT;
73 template <class Mesh> class ConstHalfedgeIterT;
74 template <class Mesh> class HalfedgeIterT;
75 template <class Mesh> class ConstEdgeIterT;
76 template <class Mesh> class EdgeIterT;
77 template <class Mesh> class ConstFaceIterT;
78 template <class Mesh> class FaceIterT;
79 
80 
81 template <class Mesh, class ValueHandle, class MemberOwner, bool (MemberOwner::*PrimitiveStatusMember)() const, size_t (MemberOwner::*PrimitiveCountMember)() const>
83  public:
84  //--- Typedefs ---
85 
86  typedef ValueHandle value_handle;
87  typedef value_handle value_type;
88  typedef std::bidirectional_iterator_tag iterator_category;
89  typedef std::ptrdiff_t difference_type;
90  typedef const value_type& reference;
91  typedef const value_type* pointer;
92  typedef const Mesh* mesh_ptr;
93  typedef const Mesh& mesh_ref;
94 
97  : mesh_(0), skip_bits_(0)
98  {}
99 
101  GenericIteratorT(mesh_ref _mesh, value_handle _hnd, bool _skip=false)
102  : mesh_(&_mesh), hnd_(_hnd), skip_bits_(0)
103  {
104  if (_skip) enable_skipping();
105 
106  // Set vertex handle invalid if the mesh contains no vertex
107  if((mesh_->*PrimitiveCountMember)() == 0) hnd_ = value_handle(-1);
108  }
109 
111  reference operator*() const {
112  return hnd_;
113  }
114 
116  pointer operator->() const {
117  return &hnd_;
118  }
119 
125  DEPRECATED("This function clutters your code. Use dereferencing operators -> and * instead.")
126  value_handle handle() const {
127  return hnd_;
128  }
129 
136  DEPRECATED("Implicit casts of iterators are unsafe. Use dereferencing operators -> and * instead.")
137  operator value_handle() const {
138  return hnd_;
139  }
140 
142  bool operator==(const GenericIteratorT& _rhs) const {
143  return ((mesh_ == _rhs.mesh_) && (hnd_ == _rhs.hnd_));
144  }
145 
147  bool operator!=(const GenericIteratorT& _rhs) const {
148  return !operator==(_rhs);
149  }
150 
153  hnd_.__increment();
154  if (skip_bits_)
155  skip_fwd();
156  return *this;
157  }
158 
161  GenericIteratorT cpy(*this);
162  ++(*this);
163  return cpy;
164  }
165 
168  hnd_.__decrement();
169  if (skip_bits_)
170  skip_bwd();
171  return *this;
172  }
173 
176  GenericIteratorT cpy(*this);
177  --(*this);
178  return cpy;
179  }
180 
183  if (mesh_ && (mesh_->*PrimitiveStatusMember)()) {
184  Attributes::StatusInfo status;
185  status.set_deleted(true);
186  status.set_hidden(true);
187  skip_bits_ = status.bits();
188  skip_fwd();
189  } else
190  skip_bits_ = 0;
191  }
192 
195  skip_bits_ = 0;
196  }
197 
198  private:
199 
200  void skip_fwd() {
201  assert(mesh_ && skip_bits_);
202  while ((hnd_.idx() < (signed) (mesh_->*PrimitiveCountMember)())
203  && (mesh_->status(hnd_).bits() & skip_bits_))
204  hnd_.__increment();
205  }
206 
207  void skip_bwd() {
208  assert(mesh_ && skip_bits_);
209  while ((hnd_.idx() >= 0) && (mesh_->status(hnd_).bits() & skip_bits_))
210  hnd_.__decrement();
211  }
212 
213  protected:
214  mesh_ptr mesh_;
215  value_handle hnd_;
216  unsigned int skip_bits_;
217 };
218 
219 //=============================================================================
220 } // namespace Iterators
221 } // namespace OpenMesh
222 //=============================================================================
223 #endif
224 //=============================================================================
bool operator==(const GenericIteratorT &_rhs) const
Are two iterators equal? Only valid if they refer to the same mesh!
Definition: IteratorsT.hh:142
Definition: IteratorsT.hh:72
Definition: IteratorsT.hh:74
Definition: IteratorsT.hh:76
GenericIteratorT & operator++()
Standard pre-increment operator.
Definition: IteratorsT.hh:152
Definition: IteratorsT.hh:75
pointer operator->() const
Standard pointer operator.
Definition: IteratorsT.hh:116
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:56
GenericIteratorT()
Default constructor.
Definition: IteratorsT.hh:96
void set_hidden(bool _b)
set hidden
Definition: Status.hh:121
Definition: IteratorsT.hh:71
Definition: IteratorsT.hh:78
GenericIteratorT operator--(int)
Standard post-decrement operator.
Definition: IteratorsT.hh:175
void set_deleted(bool _b)
set deleted
Definition: Status.hh:103
Definition: IteratorsT.hh:82
void enable_skipping()
Turn on skipping: automatically skip deleted/hidden elements.
Definition: IteratorsT.hh:182
Definition: IteratorsT.hh:73
reference operator*() const
Standard dereferencing operator.
Definition: IteratorsT.hh:111
bool operator!=(const GenericIteratorT &_rhs) const
Not equal?
Definition: IteratorsT.hh:147
value_handle handle() const
Get the handle of the item the iterator refers to.
Definition: IteratorsT.hh:126
Add status information to a base class.
Definition: Status.hh:92
void disable_skipping()
Turn on skipping: automatically skip deleted/hidden elements.
Definition: IteratorsT.hh:194
unsigned int bits() const
return whole status
Definition: Status.hh:149
GenericIteratorT(mesh_ref _mesh, value_handle _hnd, bool _skip=false)
Construct with mesh and a target handle.
Definition: IteratorsT.hh:101
GenericIteratorT operator++(int)
Standard post-increment operator.
Definition: IteratorsT.hh:160
Definition: IteratorsT.hh:77
GenericIteratorT & operator--()
Standard pre-decrement operator.
Definition: IteratorsT.hh:167

acg pic Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .