ITK  4.2.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 public:
106 // Object creation methods.
108  int op = OperatorOnext,
109  bool start = true):
110  m_StartEdge(e), m_Iterator(e),
111  m_OpType(op), m_Start(start) {}
112 
114 
115  Self & operator=(const Self & r)
116  {
117  m_StartEdge = r.m_StartEdge;
118  m_Iterator = r.m_Iterator;
119  m_OpType = r.m_OpType;
120  m_Start = r.m_Start;
121  return ( *this );
122  }
123 
124  QuadEdgeType * GetStartEdge() const { return ( m_StartEdge ); }
125  QuadEdgeType * GetIterator() const { return ( m_Iterator ); }
126  int GetOpType() const { return ( m_OpType ); }
127  bool GetStart() const { return ( m_Start ); }
128 
130  bool operator==(Self & r)
131  {
132  return ( ( m_StartEdge == r.m_StartEdge )
133  && ( m_Iterator == r.m_Iterator )
134  && ( m_OpType == r.m_OpType )
135  && ( m_Start == r.m_Start ) );
136  }
137 
138  bool operator==(const Self & r) const
139  {
140  return ( ( m_StartEdge == r.m_StartEdge )
141  && ( m_Iterator == r.m_Iterator )
142  && ( m_OpType == r.m_OpType )
143  && ( m_Start == r.m_Start ) );
144  }
145 
146  bool operator!=(Self & r)
147  {
148  return ( !( this->operator==(r) ) );
149  }
150 
151  bool operator!=(const Self & r) const
152  {
153  return ( !( this->operator==(r) ) );
154  }
155 
156  Self & operator++()
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 & operator++(int)
168  {
169  if ( m_Start )
170  {
171  this->GoToNext();
172  m_Start = !( m_Iterator == m_StartEdge );
173  }
174  return ( *this );
175  }
176 
177 protected:
179  virtual void GoToNext()
180  {
181  switch ( m_OpType )
182  {
183  case OperatorOnext:
184  m_Iterator = m_Iterator->GetOnext();
185  break;
186  case OperatorSym:
187  m_Iterator = m_Iterator->GetSym();
188  break;
189  case OperatorLnext:
190  m_Iterator = m_Iterator->GetLnext();
191  break;
192  case OperatorRnext:
193  m_Iterator = m_Iterator->GetRnext();
194  break;
195  case OperatorDnext:
196  m_Iterator = m_Iterator->GetDnext();
197  break;
198  case OperatorOprev:
199  m_Iterator = m_Iterator->GetOprev();
200  break;
201  case OperatorLprev:
202  m_Iterator = m_Iterator->GetLprev();
203  break;
204  case OperatorRprev:
205  m_Iterator = m_Iterator->GetRprev();
206  break;
207  case OperatorDprev:
208  m_Iterator = m_Iterator->GetDprev();
209  break;
210  case OperatorInvOnext:
211  m_Iterator = m_Iterator->GetInvOnext();
212  break;
213  case OperatorInvLnext:
214  m_Iterator = m_Iterator->GetInvLnext();
215  break;
216  case OperatorInvRnext:
217  m_Iterator = m_Iterator->GetInvRnext();
218  break;
219  case OperatorInvDnext:
220  m_Iterator = m_Iterator->GetInvDnext();
221  break;
222  default:
223  break;
224  }
225  }
227 
228 protected:
236 };
237 
244 template< typename TQuadEdge >
245 class ITK_EXPORT QuadEdgeMeshIterator:
246  public QuadEdgeMeshBaseIterator< TQuadEdge >
247 {
248 public:
249 
253  typedef TQuadEdge QuadEdgeType;
254 public:
255 
258  int op = Superclass::OperatorOnext,
259  bool start = true):
260  Superclass(e, op, start) {}
261 
263 
264  QuadEdgeType * Value() { return ( this->m_Iterator ); }
265  const QuadEdgeType * Value() const { return ( this->m_Iterator ); }
266 };
267 
274 template< typename TGeometricalQuadEdge >
275 class ITK_EXPORT QuadEdgeMeshIteratorGeom:
276  public QuadEdgeMeshIterator< TGeometricalQuadEdge >
277 {
278 public:
279 
282  typedef TGeometricalQuadEdge QuadEdgeType;
283 
285  typedef typename QuadEdgeType::OriginRefType OriginRefType;
286 public:
288  int op = Superclass::OperatorOnext,
289  bool start = true):
290  Superclass(e, op, start) {}
291  OriginRefType operator*() { return ( this->m_Iterator->GetOrigin() ); }
292 };
294 
301 template< typename TQuadEdge >
302 class ITK_EXPORT QuadEdgeMeshConstIterator:
303  public QuadEdgeMeshBaseIterator< TQuadEdge >
304 {
305 public:
306 
311  typedef TQuadEdge QuadEdgeType;
312 public:
313 
316  int op = Superclass::OperatorOnext,
317  bool start = true):
318  Superclass(const_cast< QuadEdgeType * >( e ), op, start) {}
319 
321 
322  Self & operator=(const NoConstType & r)
323  {
324  this->m_StartEdge = r.GetStartEdge();
325  this->m_Iterator = r.GetIterator();
326  this->m_OpType = r.GetOpType();
327  this->m_Start = r.GetStart();
328  return ( *this );
329  }
330 
331  const QuadEdgeType * Value() const { return ( this->m_Iterator ); }
332 };
333 
340 template< typename TGeometricalQuadEdge >
342  public QuadEdgeMeshConstIterator< TGeometricalQuadEdge >
343 {
344 public:
345 
350  typedef TGeometricalQuadEdge QuadEdgeType;
351 
353  typedef typename QuadEdgeType::OriginRefType OriginRefType;
354 public:
356  int op = Superclass::OperatorOnext,
357  bool start = true):
358  Superclass(e, op, start) {}
359 
361 
362  Self & operator=(const NoConstType & r)
363  {
364  this->m_StartEdge = r.GetStartEdge();
365  this->m_Iterator = r.GetIterator();
366  this->m_OpType = r.GetOpType();
367  this->m_Start = r.GetStart();
368  return ( *this );
369  }
370 
371  const OriginRefType operator*() const
372  {
373  return ( this->m_Iterator->GetOrigin() );
374  }
375 };
376 }
377 
378 #endif
379