ITK  4.3.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 >
82 class ITK_EXPORT QuadEdgeMeshBaseIterator
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 {
91  OperatorOnext = 0,
92  OperatorSym = 1,
93  OperatorLnext = 2,
94  OperatorRnext = 3,
95  OperatorDnext = 4,
96  OperatorOprev = 5,
97  OperatorLprev = 6,
98  OperatorRprev = 7,
99  OperatorDprev = 8,
100  OperatorInvOnext = 9,
101  OperatorInvLnext = 10,
102  OperatorInvRnext = 11,
103  OperatorInvDnext = 12
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  m_StartEdge = r.m_StartEdge;
119  m_Iterator = r.m_Iterator;
120  m_OpType = r.m_OpType;
121  m_Start = r.m_Start;
122  return ( *this );
123  }
124 
125  QuadEdgeType * GetStartEdge() const { return ( m_StartEdge ); }
126  QuadEdgeType * GetIterator() const { return ( m_Iterator ); }
127  int GetOpType() const { return ( m_OpType ); }
128  bool GetStart() const { return ( m_Start ); }
129 
131  bool operator==(Self & r)
132  {
133  return ( ( m_StartEdge == r.m_StartEdge )
134  && ( m_Iterator == r.m_Iterator )
135  && ( m_OpType == r.m_OpType )
136  && ( m_Start == r.m_Start ) );
137  }
138 
139  bool operator==(const Self & r) const
140  {
141  return ( ( m_StartEdge == r.m_StartEdge )
142  && ( m_Iterator == r.m_Iterator )
143  && ( m_OpType == r.m_OpType )
144  && ( m_Start == r.m_Start ) );
145  }
146 
147  bool operator!=(Self & r)
148  {
149  return ( !( this->operator==(r) ) );
150  }
151 
152  bool operator!=(const Self & r) const
153  {
154  return ( !( this->operator==(r) ) );
155  }
156 
157  Self & operator++()
158  {
159  if ( m_Start )
160  {
161  this->GoToNext();
162  m_Start = !( m_Iterator == m_StartEdge );
163  }
164 
165  return ( *this );
166  }
167 
168  Self & operator++(int)
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 GoToNext()
181  {
182  switch ( m_OpType )
183  {
184  case OperatorOnext:
185  m_Iterator = m_Iterator->GetOnext();
186  break;
187  case OperatorSym:
188  m_Iterator = m_Iterator->GetSym();
189  break;
190  case OperatorLnext:
191  m_Iterator = m_Iterator->GetLnext();
192  break;
193  case OperatorRnext:
194  m_Iterator = m_Iterator->GetRnext();
195  break;
196  case OperatorDnext:
197  m_Iterator = m_Iterator->GetDnext();
198  break;
199  case OperatorOprev:
200  m_Iterator = m_Iterator->GetOprev();
201  break;
202  case OperatorLprev:
203  m_Iterator = m_Iterator->GetLprev();
204  break;
205  case OperatorRprev:
206  m_Iterator = m_Iterator->GetRprev();
207  break;
208  case OperatorDprev:
209  m_Iterator = m_Iterator->GetDprev();
210  break;
211  case OperatorInvOnext:
212  m_Iterator = m_Iterator->GetInvOnext();
213  break;
214  case OperatorInvLnext:
215  m_Iterator = m_Iterator->GetInvLnext();
216  break;
217  case OperatorInvRnext:
218  m_Iterator = m_Iterator->GetInvRnext();
219  break;
220  case OperatorInvDnext:
221  m_Iterator = m_Iterator->GetInvDnext();
222  break;
223  default:
224  break;
225  }
226  }
228 
229 protected:
237 };
238 
245 template< typename TQuadEdge >
246 class ITK_EXPORT QuadEdgeMeshIterator:
247  public QuadEdgeMeshBaseIterator< TQuadEdge >
248 {
249 public:
250 
254  typedef TQuadEdge QuadEdgeType;
255 
256 public:
259  int op = Superclass::OperatorOnext,
260  bool start = true):
261  Superclass(e, op, start) {}
262 
264 
265  QuadEdgeType * Value() { return ( this->m_Iterator ); }
266  const QuadEdgeType * Value() const { return ( this->m_Iterator ); }
267 };
268 
275 template< typename TGeometricalQuadEdge >
276 class ITK_EXPORT QuadEdgeMeshIteratorGeom:
277  public QuadEdgeMeshIterator< TGeometricalQuadEdge >
278 {
279 public:
280 
283  typedef TGeometricalQuadEdge QuadEdgeType;
284 
286  typedef typename QuadEdgeType::OriginRefType OriginRefType;
287 
288 public:
290  int op = Superclass::OperatorOnext,
291  bool start = true):
292  Superclass(e, op, start) {}
293  OriginRefType operator*() { return ( this->m_Iterator->GetOrigin() ); }
294 };
295 
302 template< typename TQuadEdge >
303 class ITK_EXPORT QuadEdgeMeshConstIterator:
304  public QuadEdgeMeshBaseIterator< TQuadEdge >
305 {
306 public:
307 
312  typedef TQuadEdge QuadEdgeType;
313 
314 public:
317  int op = Superclass::OperatorOnext,
318  bool start = true):
319  Superclass(const_cast< QuadEdgeType * >( e ), op, start) {}
320 
322 
323  Self & operator=(const NoConstType & r)
324  {
325  this->m_StartEdge = r.GetStartEdge();
326  this->m_Iterator = r.GetIterator();
327  this->m_OpType = r.GetOpType();
328  this->m_Start = r.GetStart();
329  return ( *this );
330  }
331 
332  const QuadEdgeType * Value() const { return ( this->m_Iterator ); }
333 };
334 
341 template< typename TGeometricalQuadEdge >
343  public QuadEdgeMeshConstIterator< TGeometricalQuadEdge >
344 {
345 public:
346 
351  typedef TGeometricalQuadEdge QuadEdgeType;
352 
354  typedef typename QuadEdgeType::OriginRefType OriginRefType;
355 
356 public:
358  int op = Superclass::OperatorOnext,
359  bool start = true):
360  Superclass(e, op, start) {}
361 
363 
364  Self & operator=(const NoConstType & r)
365  {
366  this->m_StartEdge = r.GetStartEdge();
367  this->m_Iterator = r.GetIterator();
368  this->m_OpType = r.GetOpType();
369  this->m_Start = r.GetStart();
370  return ( *this );
371  }
372 
373  const OriginRefType operator*() const
374  {
375  return ( this->m_Iterator->GetOrigin() );
376  }
377 };
378 }
379 
380 #endif
381