ITK  5.2.0
Insight Toolkit
itkQuadEdgeMeshBaseIterator.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkQuadEdgeMeshBaseIterator_h
19 #define itkQuadEdgeMeshBaseIterator_h
20 
21 #include "itkMacro.h"
22 
23 // -------------------------------------------------------------------------
24 #define itkQEDefineIteratorMethodsMacro(Op) \
25  virtual Iterator Begin##Op() { return Iterator(this, Self::Iterator::Operator##Op, true); } \
26  \
27  virtual ConstIterator Begin##Op() const { return ConstIterator(this, Self::ConstIterator::Operator##Op, true); } \
28  \
29  virtual Iterator End##Op() { return Iterator(this, Self::Iterator::Operator##Op, false); } \
30  \
31  virtual ConstIterator End##Op() const { return ConstIterator(this, Self::ConstIterator::Operator##Op, false); }
32 
33 // -------------------------------------------------------------------------
34 #define itkQEDefineIteratorGeomMethodsMacro(Op) \
35  virtual IteratorGeom BeginGeom##Op() { return IteratorGeom(this, Self::IteratorGeom::Operator##Op, true); } \
36  \
37  virtual ConstIteratorGeom BeginGeom##Op() const \
38  { \
39  return ConstIteratorGeom(this, Self::ConstIteratorGeom::Operator##Op, true); \
40  } \
41  \
42  virtual IteratorGeom EndGeom##Op() { return IteratorGeom(this, Self::IteratorGeom::Operator##Op, false); } \
43  \
44  virtual ConstIteratorGeom EndGeom##Op() const \
45  { \
46  return ConstIteratorGeom(this, Self::ConstIteratorGeom::Operator##Op, false); \
47  }
48 
49 namespace itk
50 {
57 template <typename TQuadEdge>
59 {
60 public:
61  // Hierarchy type alias & values.
63  using QuadEdgeType = TQuadEdge;
64 
65  // Different types of iterators, one for each basic QE operation.
66  enum
67  {
81  };
82 
83 public:
84  // Object creation methods.
85  QuadEdgeMeshBaseIterator(QuadEdgeType * e, int op = OperatorOnext, bool start = true)
86  : m_StartEdge(e)
87  , m_Iterator(e)
88  , m_OpType(op)
89  , m_Start(start)
90  {}
91 
92  virtual ~QuadEdgeMeshBaseIterator() = default;
93 
94  Self &
95  operator=(const Self & r)
96  {
97  if (this != &r)
98  {
99  m_StartEdge = r.m_StartEdge;
100  m_Iterator = r.m_Iterator;
101  m_OpType = r.m_OpType;
102  m_Start = r.m_Start;
103  }
104  return (*this);
105  }
106 
107  QuadEdgeType *
108  GetStartEdge() const
109  {
110  return (m_StartEdge);
111  }
112  QuadEdgeType *
113  GetIterator() const
114  {
115  return (m_Iterator);
116  }
117  int
118  GetOpType() const
119  {
120  return (m_OpType);
121  }
122  bool
123  GetStart() const
124  {
125  return (m_Start);
126  }
127 
129  bool
131  {
132  return ((m_StartEdge == r.m_StartEdge) && (m_Iterator == r.m_Iterator) && (m_OpType == r.m_OpType) &&
133  (m_Start == r.m_Start));
134  }
135 
136  bool
137  operator==(const Self & r) const
138  {
139  return ((m_StartEdge == r.m_StartEdge) && (m_Iterator == r.m_Iterator) && (m_OpType == r.m_OpType) &&
140  (m_Start == r.m_Start));
141  }
142 
143  bool
145  {
146  return (!(this->operator==(r)));
147  }
148 
149  bool
150  operator!=(const Self & r) const
151  {
152  return (!(this->operator==(r)));
153  }
154 
155  Self &
157  {
158  if (m_Start)
159  {
160  this->GoToNext();
161  m_Start = !(m_Iterator == m_StartEdge);
162  }
163 
164  return (*this);
165  }
166 
167  Self &
169  {
170  if (m_Start)
171  {
172  this->GoToNext();
173  m_Start = !(m_Iterator == m_StartEdge);
174  }
175  return (*this);
176  }
177 
178 protected:
180  virtual void
182  {
183  switch (m_OpType)
184  {
185  case OperatorOnext:
186  m_Iterator = m_Iterator->GetOnext();
187  break;
188  case OperatorSym:
189  m_Iterator = m_Iterator->GetSym();
190  break;
191  case OperatorLnext:
192  m_Iterator = m_Iterator->GetLnext();
193  break;
194  case OperatorRnext:
195  m_Iterator = m_Iterator->GetRnext();
196  break;
197  case OperatorDnext:
198  m_Iterator = m_Iterator->GetDnext();
199  break;
200  case OperatorOprev:
201  m_Iterator = m_Iterator->GetOprev();
202  break;
203  case OperatorLprev:
204  m_Iterator = m_Iterator->GetLprev();
205  break;
206  case OperatorRprev:
207  m_Iterator = m_Iterator->GetRprev();
208  break;
209  case OperatorDprev:
210  m_Iterator = m_Iterator->GetDprev();
211  break;
212  case OperatorInvOnext:
213  m_Iterator = m_Iterator->GetInvOnext();
214  break;
215  case OperatorInvLnext:
216  m_Iterator = m_Iterator->GetInvLnext();
217  break;
218  case OperatorInvRnext:
219  m_Iterator = m_Iterator->GetInvRnext();
220  break;
221  case OperatorInvDnext:
222  m_Iterator = m_Iterator->GetInvDnext();
223  break;
224  default:
225  break;
226  }
227  }
229 
230 protected:
238 };
239 
246 template <typename TQuadEdge>
248 {
249 public:
250 
254  using QuadEdgeType = TQuadEdge;
255 
256 public:
259  : Superclass(e, op, start)
260  {}
261 
262  ~QuadEdgeMeshIterator() override = default;
263 
264  QuadEdgeType *
266  {
267  return (this->m_Iterator);
268  }
269  const QuadEdgeType *
270  Value() const
271  {
272  return (this->m_Iterator);
273  }
274 };
275 
282 template <typename TGeometricalQuadEdge>
283 class QuadEdgeMeshIteratorGeom : public QuadEdgeMeshIterator<TGeometricalQuadEdge>
284 {
285 public:
286 
289  using QuadEdgeType = TGeometricalQuadEdge;
290 
292  using OriginRefType = typename QuadEdgeType::OriginRefType;
293 
294 public:
296  int op = Superclass::OperatorOnext,
297  bool start = true)
298  : Superclass(e, op, start)
299  {}
300  OriginRefType operator*() { return (this->m_Iterator->GetOrigin()); }
301 };
302 
309 template <typename TQuadEdge>
311 {
312 public:
313 
318  using QuadEdgeType = TQuadEdge;
319 
320 public:
323  int op = Superclass::OperatorOnext,
324  bool start = true)
325  : Superclass(const_cast<QuadEdgeType *>(e), op, start)
326  {}
327 
328  ~QuadEdgeMeshConstIterator() override = default;
329 
330  Self &
332  {
333  this->m_StartEdge = r.GetStartEdge();
334  this->m_Iterator = r.GetIterator();
335  this->m_OpType = r.GetOpType();
336  this->m_Start = r.GetStart();
337  return (*this);
338  }
339 
340  const QuadEdgeType *
341  Value() const
342  {
343  return (this->m_Iterator);
344  }
345 };
346 
353 template <typename TGeometricalQuadEdge>
354 class QuadEdgeMeshConstIteratorGeom : public QuadEdgeMeshConstIterator<TGeometricalQuadEdge>
355 {
356 public:
357 
362  using QuadEdgeType = TGeometricalQuadEdge;
363 
365  using OriginRefType = typename QuadEdgeType::OriginRefType;
366 
367 public:
369  int op = Superclass::OperatorOnext,
370  bool start = true)
371  : Superclass(e, op, start)
372  {}
373 
374  ~QuadEdgeMeshConstIteratorGeom() override = default;
375 
376  Self &
378  {
379  this->m_StartEdge = r.GetStartEdge();
380  this->m_Iterator = r.GetIterator();
381  this->m_OpType = r.GetOpType();
382  this->m_Start = r.GetStart();
383  return (*this);
384  }
385 
386  const OriginRefType operator*() const { return (this->m_Iterator->GetOrigin()); }
387 };
388 } // namespace itk
389 
390 #endif
itk::QuadEdgeMeshBaseIterator::operator!=
bool operator!=(Self &r)
Definition: itkQuadEdgeMeshBaseIterator.h:144
itk::QuadEdgeMeshConstIterator::Self
QuadEdgeMeshConstIterator Self
Definition: itkQuadEdgeMeshBaseIterator.h:315
itk::QuadEdgeMeshBaseIterator::OperatorDprev
Definition: itkQuadEdgeMeshBaseIterator.h:76
itk::QuadEdgeMeshIterator::~QuadEdgeMeshIterator
~QuadEdgeMeshIterator() override=default
itk::QuadEdgeMeshBaseIterator::operator==
bool operator==(const Self &r) const
Definition: itkQuadEdgeMeshBaseIterator.h:137
itk::QuadEdgeMeshBaseIterator::GetOpType
int GetOpType() const
Definition: itkQuadEdgeMeshBaseIterator.h:118
itk::QuadEdgeMeshBaseIterator
Base iterator class for QuadEdgeMesh.
Definition: itkQuadEdgeMeshBaseIterator.h:58
itk::QuadEdgeMeshBaseIterator::operator=
Self & operator=(const Self &r)
Definition: itkQuadEdgeMeshBaseIterator.h:95
itk::QuadEdgeMeshBaseIterator::OperatorInvDnext
Definition: itkQuadEdgeMeshBaseIterator.h:80
itk::QuadEdgeMeshIteratorGeom::OriginRefType
typename QuadEdgeType::OriginRefType OriginRefType
Definition: itkQuadEdgeMeshBaseIterator.h:292
itk::QuadEdgeMeshBaseIterator::GetStart
bool GetStart() const
Definition: itkQuadEdgeMeshBaseIterator.h:123
itk::QuadEdgeMeshConstIteratorGeom::OriginRefType
typename QuadEdgeType::OriginRefType OriginRefType
Definition: itkQuadEdgeMeshBaseIterator.h:365
itk::QuadEdgeMeshConstIterator
Const iterator for QuadEdgeMesh.
Definition: itkQuadEdgeMeshBaseIterator.h:310
itk::QuadEdgeMeshBaseIterator::OperatorInvLnext
Definition: itkQuadEdgeMeshBaseIterator.h:78
itk::QuadEdgeMeshIterator::Value
const QuadEdgeType * Value() const
Definition: itkQuadEdgeMeshBaseIterator.h:270
itk::QuadEdgeMeshBaseIterator::OperatorLnext
Definition: itkQuadEdgeMeshBaseIterator.h:70
itk::QuadEdgeMeshIteratorGeom::operator*
OriginRefType operator*()
Definition: itkQuadEdgeMeshBaseIterator.h:300
itk::QuadEdgeMeshBaseIterator::OperatorOnext
Definition: itkQuadEdgeMeshBaseIterator.h:68
itk::QuadEdgeMeshBaseIterator::OperatorOprev
Definition: itkQuadEdgeMeshBaseIterator.h:73
itk::QuadEdgeMeshConstIteratorGeom::~QuadEdgeMeshConstIteratorGeom
~QuadEdgeMeshConstIteratorGeom() override=default
itk::QuadEdgeMeshConstIterator::~QuadEdgeMeshConstIterator
~QuadEdgeMeshConstIterator() override=default
itk::QuadEdgeMeshConstIteratorGeom::QuadEdgeMeshConstIteratorGeom
QuadEdgeMeshConstIteratorGeom(const QuadEdgeType *e=(QuadEdgeType *) 0, int op=Superclass::OperatorOnext, bool start=true)
Definition: itkQuadEdgeMeshBaseIterator.h:368
itk::QuadEdgeMeshBaseIterator::~QuadEdgeMeshBaseIterator
virtual ~QuadEdgeMeshBaseIterator()=default
itk::QuadEdgeMeshBaseIterator::OperatorRprev
Definition: itkQuadEdgeMeshBaseIterator.h:75
itk::QuadEdgeMeshBaseIterator::OperatorLprev
Definition: itkQuadEdgeMeshBaseIterator.h:74
itk::QuadEdgeMeshBaseIterator::OperatorRnext
Definition: itkQuadEdgeMeshBaseIterator.h:71
itk::QuadEdgeMeshConstIterator::Value
const QuadEdgeType * Value() const
Definition: itkQuadEdgeMeshBaseIterator.h:341
itk::QuadEdgeMeshBaseIterator::OperatorDnext
Definition: itkQuadEdgeMeshBaseIterator.h:72
itk::QuadEdgeMeshBaseIterator::OperatorSym
Definition: itkQuadEdgeMeshBaseIterator.h:69
itk::QuadEdgeMeshIterator::Value
QuadEdgeType * Value()
Definition: itkQuadEdgeMeshBaseIterator.h:265
itkMacro.h
itk::QuadEdgeMeshConstIteratorGeom::QuadEdgeType
TGeometricalQuadEdge QuadEdgeType
Definition: itkQuadEdgeMeshBaseIterator.h:362
itk::QuadEdgeMeshConstIteratorGeom::Self
QuadEdgeMeshConstIteratorGeom Self
Definition: itkQuadEdgeMeshBaseIterator.h:359
itk::QuadEdgeMeshBaseIterator::QuadEdgeMeshBaseIterator
QuadEdgeMeshBaseIterator(QuadEdgeType *e, int op=OperatorOnext, bool start=true)
Definition: itkQuadEdgeMeshBaseIterator.h:85
itk::QuadEdgeMeshBaseIterator::Self
QuadEdgeMeshBaseIterator Self
Definition: itkQuadEdgeMeshBaseIterator.h:62
itk::QuadEdgeMeshConstIterator::QuadEdgeMeshConstIterator
QuadEdgeMeshConstIterator(const QuadEdgeType *e=(QuadEdgeType *) 0, int op=Superclass::OperatorOnext, bool start=true)
Definition: itkQuadEdgeMeshBaseIterator.h:322
itk::QuadEdgeMeshBaseIterator::operator!=
bool operator!=(const Self &r) const
Definition: itkQuadEdgeMeshBaseIterator.h:150
itk::QuadEdgeMeshIteratorGeom
Non const geometrical iterator.
Definition: itkQuadEdgeMeshBaseIterator.h:283
itk::QuadEdgeMeshIterator::QuadEdgeMeshIterator
QuadEdgeMeshIterator(QuadEdgeType *e=(QuadEdgeType *) 0, int op=Superclass::OperatorOnext, bool start=true)
Definition: itkQuadEdgeMeshBaseIterator.h:258
itk::QuadEdgeMeshIterator::QuadEdgeType
TQuadEdge QuadEdgeType
Definition: itkQuadEdgeMeshBaseIterator.h:254
itk::QuadEdgeMeshBaseIterator::operator==
bool operator==(Self &r)
Definition: itkQuadEdgeMeshBaseIterator.h:130
itk::QuadEdgeMeshIteratorGeom::QuadEdgeType
TGeometricalQuadEdge QuadEdgeType
Definition: itkQuadEdgeMeshBaseIterator.h:289
itk::QuadEdgeMeshBaseIterator::operator++
Self & operator++()
Definition: itkQuadEdgeMeshBaseIterator.h:156
itk::QuadEdgeMeshBaseIterator::GetStartEdge
QuadEdgeType * GetStartEdge() const
Definition: itkQuadEdgeMeshBaseIterator.h:108
itk::QuadEdgeMeshConstIterator::QuadEdgeType
TQuadEdge QuadEdgeType
Definition: itkQuadEdgeMeshBaseIterator.h:318
itk::QuadEdgeMeshBaseIterator::GetIterator
QuadEdgeType * GetIterator() const
Definition: itkQuadEdgeMeshBaseIterator.h:113
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::QuadEdgeMeshBaseIterator::operator++
Self & operator++(int)
Definition: itkQuadEdgeMeshBaseIterator.h:168
itk::QuadEdgeMeshConstIteratorGeom
Const geometrical iterator.
Definition: itkQuadEdgeMeshBaseIterator.h:354
itk::QuadEdgeMeshConstIteratorGeom::operator*
const OriginRefType operator*() const
Definition: itkQuadEdgeMeshBaseIterator.h:386
itk::QuadEdgeMeshConstIteratorGeom::operator=
Self & operator=(const NoConstType &r)
Definition: itkQuadEdgeMeshBaseIterator.h:377
itk::QuadEdgeMeshBaseIterator::OperatorInvOnext
Definition: itkQuadEdgeMeshBaseIterator.h:77
itk::Math::e
static constexpr double e
Definition: itkMath.h:54
itk::QuadEdgeMeshBaseIterator::GoToNext
virtual void GoToNext()
Definition: itkQuadEdgeMeshBaseIterator.h:181
itk::QuadEdgeMeshIterator
Non const iterator for QuadMesh.
Definition: itkQuadEdgeMeshBaseIterator.h:247
itk::QuadEdgeMeshBaseIterator::OperatorInvRnext
Definition: itkQuadEdgeMeshBaseIterator.h:79
itk::QuadEdgeMeshConstIterator::operator=
Self & operator=(const NoConstType &r)
Definition: itkQuadEdgeMeshBaseIterator.h:331
itk::QuadEdgeMeshBaseIterator< TGeometricalQuadEdge >::QuadEdgeType
TGeometricalQuadEdge QuadEdgeType
Definition: itkQuadEdgeMeshBaseIterator.h:63
itk::QuadEdgeMeshIteratorGeom::QuadEdgeMeshIteratorGeom
QuadEdgeMeshIteratorGeom(QuadEdgeType *e=(QuadEdgeType *) nullptr, int op=Superclass::OperatorOnext, bool start=true)
Definition: itkQuadEdgeMeshBaseIterator.h:295