ITK  4.2.0
Insight Segmentation and Registration Toolkit
itkQuadEdgeMeshFrontIterator.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 __itkQuadEdgeMeshFrontIterator_h
19 #define __itkQuadEdgeMeshFrontIterator_h
20 
21 #include "itkMapContainer.h"
22 
23 // -------------------------------------------------------------------------
24 #define itkQEDefineFrontIteratorMethodsMacro(MeshTypeArg) \
25  /* Dual definition placed before others because of .NET that cannot */ \
26  /* cope with definition of FrontIterator (that further hides the */ \
27  /* definition of the template). */ \
28  typedef typename MeshTypeArg::QEDual QEDualType; \
29  typedef typename MeshTypeArg::QEPrimal QEPrimalType; \
30  typedef QuadEdgeMeshFrontIterator< MeshTypeArg, \
31  QEDualType > FrontDualIterator; \
32  typedef QuadEdgeMeshConstFrontIterator< MeshTypeArg, \
33  QEDualType > \
34  ConstFrontDualIterator; \
35  typedef QuadEdgeMeshFrontIterator< MeshTypeArg, \
36  QEPrimalType > FrontIterator; \
37  typedef QuadEdgeMeshConstFrontIterator< MeshTypeArg, \
38  QEPrimalType > \
39  ConstFrontIterator; \
40  \
41  virtual FrontIterator BeginFront(QEPrimalType * seed = (QEPrimalType *)0) \
42  { \
43  return ( FrontIterator(this, true, seed) ); \
44  } \
45  \
46  virtual ConstFrontIterator BeginFront(QEPrimalType * seed) const \
47  { return ( ConstFrontIterator(this, true, seed) ); } \
48  \
49  virtual FrontIterator EndFront() \
50  { \
51  return ( FrontIterator(this, false) ); \
52  } \
53  \
54  virtual ConstFrontIterator EndFront() const \
55  { return ( ConstFrontIterator(this, false) ); } \
56  \
57  virtual FrontDualIterator BeginDualFront(QEDualType * seed = (QEDualType *)0) \
58  { \
59  return ( FrontDualIterator(this, true, seed) ); \
60  } \
61  \
62  virtual ConstFrontDualIterator BeginDualFront(QEDualType * seed) const \
63  { return ( ConstFrontDualIterator(this, true, seed) ); } \
64  \
65  virtual FrontDualIterator EndDualFront() \
66  { \
67  return ( FrontDualIterator(this, false) ); \
68  } \
69  \
70  virtual ConstFrontDualIterator EndDualFront() const \
71  { return ( ConstFrontDualIterator(this, false) ); }
72 
73 namespace itk
74 {
88 template< typename TMesh, typename TQE >
90 {
91 public:
92  // Hierarchy typedefs & values.
94 
95  // Template types
96  typedef TMesh MeshType;
97  typedef TQE QEType;
98 protected:
99  // Mesh types
100  typedef typename MeshType::CoordRepType CoordRepType;
101  // QE types
102  typedef typename QEType::OriginRefType QEOriginType;
103 
113  class FrontAtom
114  {
115 public:
116  FrontAtom(QEType *e = (QEType *)0, const CoordRepType c = 0):
117  m_Edge(e), m_Cost(c)
118  {}
119  virtual ~FrontAtom() {}
120  FrontAtom & operator=(const FrontAtom & r)
121  { m_Edge = r.m_Edge; m_Cost = r.m_Cost; return *this; }
122  bool operator==(const FrontAtom & r) const
123  { return ( m_Edge == r.m_Edge ); }
124  bool operator!=(const FrontAtom & r) const
125  { return ( m_Edge != r.m_Edge ); }
126  bool operator<(const FrontAtom & r) const
127  { return ( m_Cost < r.m_Cost ); }
128 public:
131  };
133 
137  typedef std::list< FrontAtom > FrontType;
138  typedef typename FrontType::iterator FrontTypeIterator;
140 
146 public:
147 
150  bool start = true,
151  QEType *seed = (QEType *)0);
154 
155  Self & operator=(const Self & r)
156  {
157  m_Mesh = r.m_Mesh;
158  m_Start = r.m_Start;
159  m_Seed = r.m_Seed;
160  m_Front = r.m_Front;
161  m_IsPointVisited = r.m_IsPointVisited;
162  m_CurrentEdge = r.m_CurrentEdge;
163  return ( *this );
164  }
165 
166  // Iteration methods.
167  bool operator==(Self & r)
168  {
169  return ( m_Start == r.m_Start );
170  }
171 
172  bool operator==(const Self & r) const
173  {
174  return ( m_Start == r.m_Start );
175  }
176 
177  bool operator!=(Self & r)
178  {
179  return ( !( this->operator==(r) ) );
180  }
181 
182  bool operator!=(const Self & r) const
183  {
184  return ( !( this->operator==(r) ) );
185  }
186 
187  Self & operator++();
188 
189  Self & operator++(int) { return ( this->operator++() ); }
190 
191  MeshType * GetMesh() const { return this->m_Mesh; }
192 protected:
196  QEType * FindDefaultSeed();
197 
201  virtual CoordRepType GetCost(QEType *edge){ (void)edge; return ( 1 ); }
202 protected:
203 
206 
209 
211  bool m_Start;
212 
215 
218 
221 };
222 
229 template< typename TMesh, typename TQE >
230 class ITK_EXPORT QuadEdgeMeshFrontIterator:
231  public QuadEdgeMeshFrontBaseIterator< TMesh, TQE >
232 {
233 public:
234 
238  typedef typename Superclass::MeshType MeshType;
239  typedef typename Superclass::QEType QEType;
240 public:
241 
244  bool start = true,
245  QEType *seed = (QEType *)0):
246  Superclass(mesh, start, seed) {}
248  QEType * Value() { return ( this->m_CurrentEdge ); }
249 };
251 
258 template< class TMesh, class TQE = typename TMesh::QEType >
260  public QuadEdgeMeshFrontBaseIterator< TMesh, TQE >
261 {
262 public:
263 
267  typedef typename Superclass::QEType QEType;
268  typedef typename Superclass::MeshType MeshType;
270 public:
271 
274  bool start = true,
275  QEType *seed = (QEType *)0)
276  {
277  (void)mesh;
278  (void)start;
279  (void)seed;
280  }
282 
285  Self & operator=(const NoConstType & r)
286  {
287  this->m_Mesh = r.GetMesh();
288  return ( *this );
289  }
291 
292  const QEType * Value() const { return ( this->m_CurrentEdge ); }
293 };
294 }
295 
296 #include "itkQuadEdgeMeshFrontIterator.hxx"
297 
298 #endif
299