OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
IteratorsT.hh
1 /* ========================================================================= *
2  * *
3  * OpenMesh *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openmesh.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenMesh. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40  * ========================================================================= */
41 
42 /*===========================================================================*\
43  * *
44  * $Revision$ *
45  * $Date$ *
46  * *
47 \*===========================================================================*/
48 
49 #ifndef OPENMESH_ITERATORS_HH
50 #define OPENMESH_ITERATORS_HH
51 
52 //=============================================================================
53 //
54 // Iterators for PolyMesh/TriMesh
55 //
56 //=============================================================================
57 
58 
59 
60 //== INCLUDES =================================================================
61 
62 #include <OpenMesh/Core/System/config.h>
63 #include <OpenMesh/Core/Mesh/Status.hh>
64 #include <cassert>
65 #include <cstddef>
66 #include <iterator>
67 
68 
69 //== NAMESPACES ===============================================================
70 
71 namespace OpenMesh {
72 namespace Iterators {
73 
74 
75 //== FORWARD DECLARATIONS =====================================================
76 
77 
78 template <class Mesh> class ConstVertexIterT;
79 template <class Mesh> class VertexIterT;
80 template <class Mesh> class ConstHalfedgeIterT;
81 template <class Mesh> class HalfedgeIterT;
82 template <class Mesh> class ConstEdgeIterT;
83 template <class Mesh> class EdgeIterT;
84 template <class Mesh> class ConstFaceIterT;
85 template <class Mesh> class FaceIterT;
86 
87 
88 template <class Mesh, class ValueHandle, class MemberOwner, bool (MemberOwner::*PrimitiveStatusMember)() const, size_t (MemberOwner::*PrimitiveCountMember)() const>
90  public:
91  //--- Typedefs ---
92 
93  typedef ValueHandle value_handle;
94  typedef value_handle value_type;
95  typedef std::bidirectional_iterator_tag iterator_category;
96  typedef std::ptrdiff_t difference_type;
97  typedef const value_type& reference;
98  typedef const value_type* pointer;
99  typedef const Mesh* mesh_ptr;
100  typedef const Mesh& mesh_ref;
101 
104  : mesh_(0), skip_bits_(0)
105  {}
106 
108  GenericIteratorT(mesh_ref _mesh, value_handle _hnd, bool _skip=false)
109  : mesh_(&_mesh), hnd_(_hnd), skip_bits_(0)
110  {
111  if (_skip) enable_skipping();
112 
113  // Set vertex handle invalid if the mesh contains no vertex
114  if((mesh_->*PrimitiveCountMember)() == 0) hnd_ = value_handle(-1);
115  }
116 
118  reference operator*() const {
119  return hnd_;
120  }
121 
123  pointer operator->() const {
124  return &hnd_;
125  }
126 
132  DEPRECATED("This function clutters your code. Use dereferencing operators -> and * instead.")
133  value_handle handle() const {
134  return hnd_;
135  }
136 
143  DEPRECATED("Implicit casts of iterators are unsafe. Use dereferencing operators -> and * instead.")
144  operator value_handle() const {
145  return hnd_;
146  }
147 
149  bool operator==(const GenericIteratorT& _rhs) const {
150  return ((mesh_ == _rhs.mesh_) && (hnd_ == _rhs.hnd_));
151  }
152 
154  bool operator!=(const GenericIteratorT& _rhs) const {
155  return !operator==(_rhs);
156  }
157 
160  hnd_.__increment();
161  if (skip_bits_)
162  skip_fwd();
163  return *this;
164  }
165 
168  GenericIteratorT cpy(*this);
169  ++(*this);
170  return cpy;
171  }
172 
175  hnd_.__decrement();
176  if (skip_bits_)
177  skip_bwd();
178  return *this;
179  }
180 
183  GenericIteratorT cpy(*this);
184  --(*this);
185  return cpy;
186  }
187 
190  if (mesh_ && (mesh_->*PrimitiveStatusMember)()) {
191  Attributes::StatusInfo status;
192  status.set_deleted(true);
193  status.set_hidden(true);
194  skip_bits_ = status.bits();
195  skip_fwd();
196  } else
197  skip_bits_ = 0;
198  }
199 
202  skip_bits_ = 0;
203  }
204 
205  private:
206 
207  void skip_fwd() {
208  assert(mesh_ && skip_bits_);
209  while ((hnd_.idx() < (signed) (mesh_->*PrimitiveCountMember)())
210  && (mesh_->status(hnd_).bits() & skip_bits_))
211  hnd_.__increment();
212  }
213 
214  void skip_bwd() {
215  assert(mesh_ && skip_bits_);
216  while ((hnd_.idx() >= 0) && (mesh_->status(hnd_).bits() & skip_bits_))
217  hnd_.__decrement();
218  }
219 
220  protected:
221  mesh_ptr mesh_;
222  value_handle hnd_;
223  unsigned int skip_bits_;
224 };
225 
226 //=============================================================================
227 } // namespace Iterators
228 } // namespace OpenMesh
229 //=============================================================================
230 #endif
231 //=============================================================================
Definition: IteratorsT.hh:80
Definition: IteratorsT.hh:82
GenericIteratorT operator++(int)
Standard post-increment operator.
Definition: IteratorsT.hh:167
void enable_skipping()
Turn on skipping: automatically skip deleted/hidden elements.
Definition: IteratorsT.hh:189
GenericIteratorT()
Default constructor.
Definition: IteratorsT.hh:103
Definition: IteratorsT.hh:89
Definition: IteratorsT.hh:83
Definition: IteratorsT.hh:84
reference operator*() const
Standard dereferencing operator.
Definition: IteratorsT.hh:118
GenericIteratorT & operator--()
Standard pre-decrement operator.
Definition: IteratorsT.hh:174
GenericIteratorT operator--(int)
Standard post-decrement operator.
Definition: IteratorsT.hh:182
void set_hidden(bool _b)
set hidden
Definition: Status.hh:128
void disable_skipping()
Turn on skipping: automatically skip deleted/hidden elements.
Definition: IteratorsT.hh:201
Add status information to a base class.
Definition: Status.hh:99
value_handle handle() const
Get the handle of the item the iterator refers to.
Definition: IteratorsT.hh:133
GenericIteratorT(mesh_ref _mesh, value_handle _hnd, bool _skip=false)
Construct with mesh and a target handle.
Definition: IteratorsT.hh:108
pointer operator->() const
Standard pointer operator.
Definition: IteratorsT.hh:123
Definition: IteratorsT.hh:79
void set_deleted(bool _b)
set deleted
Definition: Status.hh:110
Definition: IteratorsT.hh:81
Definition: IteratorsT.hh:85
unsigned int bits() const
return whole status
Definition: Status.hh:156
bool operator!=(const GenericIteratorT &_rhs) const
Not equal?
Definition: IteratorsT.hh:154
Definition: IteratorsT.hh:78
bool operator==(const GenericIteratorT &_rhs) const
Are two iterators equal? Only valid if they refer to the same mesh!
Definition: IteratorsT.hh:149
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
GenericIteratorT & operator++()
Standard pre-increment operator.
Definition: IteratorsT.hh:159

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