ITK  4.8.0
Insight Segmentation and Registration Toolkit
itkQuadEdgeMeshBaseIterator.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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() \
26  { \
27  return Iterator(this, Self::Iterator::Operator##Op, true); \
28  } \
29  \
30  virtual ConstIterator Begin##Op() const \
31  { \
32  return ConstIterator(this, Self::ConstIterator::Operator##Op, \
33  true); \
34  } \
35  \
36  virtual Iterator End##Op() \
37  { \
38  return Iterator(this, Self::Iterator::Operator##Op, false); \
39  } \
40  \
41  virtual ConstIterator End##Op() const \
42  { \
43  return ConstIterator(this, Self::ConstIterator::Operator##Op, \
44  false); \
45  }
46 
47 // -------------------------------------------------------------------------
48 #define itkQEDefineIteratorGeomMethodsMacro(Op) \
49  virtual IteratorGeom BeginGeom##Op() \
50  { \
51  return IteratorGeom(this, Self::IteratorGeom::Operator##Op, \
52  true); \
53  } \
54  \
55  virtual ConstIteratorGeom BeginGeom##Op() const \
56  { \
57  return ConstIteratorGeom(this, \
58  Self::ConstIteratorGeom::Operator##Op, true); \
59  } \
60  \
61  virtual IteratorGeom EndGeom##Op() \
62  { \
63  return IteratorGeom(this, Self::IteratorGeom::Operator##Op, \
64  false); \
65  } \
66  \
67  virtual ConstIteratorGeom EndGeom##Op() const \
68  { \
69  return ConstIteratorGeom(this, \
70  Self::ConstIteratorGeom::Operator##Op, false); \
71  }
72 
73 namespace itk
74 {
81 template< typename TQuadEdge >
83 {
84 public:
85  // Hierarchy typedefs & values.
87  typedef TQuadEdge QuadEdgeType;
88 
89  // Different types of iterators, one for each basic QE operation.
90  enum {
104  };
105 
106 public:
107 // Object creation methods.
109  int op = OperatorOnext,
110  bool start = true):
111  m_StartEdge(e), m_Iterator(e),
112  m_OpType(op), m_Start(start) {}
113 
115 
116  Self & operator=(const Self & r)
117  {
118  if(this != &r)
119  {
120  m_StartEdge = r.m_StartEdge;
121  m_Iterator = r.m_Iterator;
122  m_OpType = r.m_OpType;
123  m_Start = r.m_Start;
124  }
125  return ( *this );
126  }
127 
128  QuadEdgeType * GetStartEdge() const { return ( m_StartEdge ); }
129  QuadEdgeType * GetIterator() const { return ( m_Iterator ); }
130  int GetOpType() const { return ( m_OpType ); }
131  bool GetStart() const { return ( m_Start ); }
132 
134  bool operator==(Self & r)
135  {
136  return ( ( m_StartEdge == r.m_StartEdge )
137  && ( m_Iterator == r.m_Iterator )
138  && ( m_OpType == r.m_OpType )
139  && ( m_Start == r.m_Start ) );
140  }
141 
142  bool operator==(const Self & r) const
143  {
144  return ( ( m_StartEdge == r.m_StartEdge )
145  && ( m_Iterator == r.m_Iterator )
146  && ( m_OpType == r.m_OpType )
147  && ( m_Start == r.m_Start ) );
148  }
149 
150  bool operator!=(Self & r)
151  {
152  return ( !( this->operator==(r) ) );
153  }
154 
155  bool operator!=(const Self & r) const
156  {
157  return ( !( this->operator==(r) ) );
158  }
159 
161  {
162  if ( m_Start )
163  {
164  this->GoToNext();
165  m_Start = !( m_Iterator == m_StartEdge );
166  }
167 
168  return ( *this );
169  }
170 
172  {
173  if ( m_Start )
174  {
175  this->GoToNext();
176  m_Start = !( m_Iterator == m_StartEdge );
177  }
178  return ( *this );
179  }
180 
181 protected:
183  virtual void GoToNext()
184  {
185  switch ( m_OpType )
186  {
187  case OperatorOnext:
188  m_Iterator = m_Iterator->GetOnext();
189  break;
190  case OperatorSym:
191  m_Iterator = m_Iterator->GetSym();
192  break;
193  case OperatorLnext:
194  m_Iterator = m_Iterator->GetLnext();
195  break;
196  case OperatorRnext:
197  m_Iterator = m_Iterator->GetRnext();
198  break;
199  case OperatorDnext:
200  m_Iterator = m_Iterator->GetDnext();
201  break;
202  case OperatorOprev:
203  m_Iterator = m_Iterator->GetOprev();
204  break;
205  case OperatorLprev:
206  m_Iterator = m_Iterator->GetLprev();
207  break;
208  case OperatorRprev:
209  m_Iterator = m_Iterator->GetRprev();
210  break;
211  case OperatorDprev:
212  m_Iterator = m_Iterator->GetDprev();
213  break;
214  case OperatorInvOnext:
215  m_Iterator = m_Iterator->GetInvOnext();
216  break;
217  case OperatorInvLnext:
218  m_Iterator = m_Iterator->GetInvLnext();
219  break;
220  case OperatorInvRnext:
221  m_Iterator = m_Iterator->GetInvRnext();
222  break;
223  case OperatorInvDnext:
224  m_Iterator = m_Iterator->GetInvDnext();
225  break;
226  default:
227  break;
228  }
229  }
231 
232 protected:
240 };
241 
248 template< typename TQuadEdge >
250  public QuadEdgeMeshBaseIterator< TQuadEdge >
251 {
252 public:
253 
257  typedef TQuadEdge QuadEdgeType;
258 
259 public:
262  int op = Superclass::OperatorOnext,
263  bool start = true):
264  Superclass(e, op, start) {}
265 
267 
268  QuadEdgeType * Value() { return ( this->m_Iterator ); }
269  const QuadEdgeType * Value() const { return ( this->m_Iterator ); }
270 };
271 
278 template< typename TGeometricalQuadEdge >
280  public QuadEdgeMeshIterator< TGeometricalQuadEdge >
281 {
282 public:
283 
286  typedef TGeometricalQuadEdge QuadEdgeType;
287 
289  typedef typename QuadEdgeType::OriginRefType OriginRefType;
290 
291 public:
293  int op = Superclass::OperatorOnext,
294  bool start = true):
295  Superclass(e, op, start) {}
296  OriginRefType operator*() { return ( this->m_Iterator->GetOrigin() ); }
297 };
298 
305 template< typename TQuadEdge >
307  public QuadEdgeMeshBaseIterator< TQuadEdge >
308 {
309 public:
310 
315  typedef TQuadEdge QuadEdgeType;
316 
317 public:
320  int op = Superclass::OperatorOnext,
321  bool start = true):
322  Superclass(const_cast< QuadEdgeType * >( e ), op, start) {}
323 
325 
327  {
328  this->m_StartEdge = r.GetStartEdge();
329  this->m_Iterator = r.GetIterator();
330  this->m_OpType = r.GetOpType();
331  this->m_Start = r.GetStart();
332  return ( *this );
333  }
334 
335  const QuadEdgeType * Value() const { return ( this->m_Iterator ); }
336 };
337 
344 template< typename TGeometricalQuadEdge >
346  public QuadEdgeMeshConstIterator< TGeometricalQuadEdge >
347 {
348 public:
349 
354  typedef TGeometricalQuadEdge QuadEdgeType;
355 
357  typedef typename QuadEdgeType::OriginRefType OriginRefType;
358 
359 public:
361  int op = Superclass::OperatorOnext,
362  bool start = true):
363  Superclass(e, op, start) {}
364 
366 
368  {
369  this->m_StartEdge = r.GetStartEdge();
370  this->m_Iterator = r.GetIterator();
371  this->m_OpType = r.GetOpType();
372  this->m_Start = r.GetStart();
373  return ( *this );
374  }
375 
376  const OriginRefType operator*() const
377  {
378  return ( this->m_Iterator->GetOrigin() );
379  }
380 };
381 }
382 
383 #endif
const QuadEdgeType * Value() const
QuadEdgeMeshIteratorGeom(QuadEdgeType *e=(QuadEdgeType *) 0, int op=Superclass::OperatorOnext, bool start=true)
QuadEdgeMeshIterator< TQuadEdge > NoConstType
Base iterator class for QuadEdgeMesh.
QuadEdgeMeshConstIterator(const QuadEdgeType *e=(QuadEdgeType *) 0, int op=Superclass::OperatorOnext, bool start=true)
static const double e
The base of the natural logarithm or Euler&#39;s number
Definition: itkMath.h:45
QuadEdgeMeshBaseIterator(QuadEdgeType *e, int op=OperatorOnext, bool start=true)
Self & operator=(const NoConstType &r)
QuadEdgeMeshConstIterator< TGeometricalQuadEdge > Superclass
QuadEdgeMeshConstIteratorGeom(const QuadEdgeType *e=(QuadEdgeType *) 0, int op=Superclass::OperatorOnext, bool start=true)
Non const iterator for QuadMesh.
QuadEdgeType::OriginRefType OriginRefType
Const iterator for QuadEdgeMesh.
QuadEdgeMeshIterator(QuadEdgeType *e=(QuadEdgeType *) 0, int op=Superclass::OperatorOnext, bool start=true)
QuadEdgeMeshIteratorGeom< TGeometricalQuadEdge > NoConstType
QuadEdgeMeshIterator< TGeometricalQuadEdge > Superclass
QuadEdgeMeshBaseIterator< TQuadEdge > Superclass
const QuadEdgeType * Value() const
QuadEdgeMeshBaseIterator< TQuadEdge > Superclass
Non const geometrical iterator.