ITK  5.2.0
Insight Toolkit
itkQuadEdgeMeshFrontIterator.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 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  using QEDualType = typename MeshTypeArg::QEDual; \
29  using QEPrimalType = typename MeshTypeArg::QEPrimal; \
30  using FrontDualIterator = QuadEdgeMeshFrontIterator<MeshTypeArg, QEDualType>; \
31  using ConstFrontDualIterator = QuadEdgeMeshConstFrontIterator<MeshTypeArg, QEDualType>; \
32  using FrontIterator = QuadEdgeMeshFrontIterator<MeshTypeArg, QEPrimalType>; \
33  using ConstFrontIterator = QuadEdgeMeshConstFrontIterator<MeshTypeArg, QEPrimalType>; \
34  \
35  virtual FrontIterator BeginFront(QEPrimalType * seed = (QEPrimalType *)0) \
36  { \
37  return (FrontIterator(this, true, seed)); \
38  } \
39  \
40  virtual ConstFrontIterator BeginFront(QEPrimalType * seed) const { return (ConstFrontIterator(this, true, seed)); } \
41  \
42  virtual FrontIterator EndFront() { return (FrontIterator(this, false)); } \
43  \
44  virtual ConstFrontIterator EndFront() const { return (ConstFrontIterator(this, false)); } \
45  \
46  virtual FrontDualIterator BeginDualFront(QEDualType * seed = (QEDualType *)0) \
47  { \
48  return (FrontDualIterator(this, true, seed)); \
49  } \
50  \
51  virtual ConstFrontDualIterator BeginDualFront(QEDualType * seed) const \
52  { \
53  return (ConstFrontDualIterator(this, true, seed)); \
54  } \
55  \
56  virtual FrontDualIterator EndDualFront() { return (FrontDualIterator(this, false)); } \
57  \
58  virtual ConstFrontDualIterator EndDualFront() const { return (ConstFrontDualIterator(this, false)); }
59 
60 namespace itk
61 {
75 template <typename TMesh, typename TQE>
76 class ITK_TEMPLATE_EXPORT QuadEdgeMeshFrontBaseIterator
77 {
78 public:
79  // Hierarchy type alias & values.
81 
82  // Template types
83  using MeshType = TMesh;
84  using QEType = TQE;
85 
86 protected:
87  // Mesh types
88  using CoordRepType = typename MeshType::CoordRepType;
89  // QE types
90  using QEOriginType = typename QEType::OriginRefType;
91 
101  class FrontAtom
102  {
103  public:
104  FrontAtom(QEType * e = (QEType *)0, const CoordRepType c = 0)
105  : m_Edge(e)
106  , m_Cost(c)
107  {}
108  virtual ~FrontAtom() = default;
109  FrontAtom &
110  operator=(const FrontAtom & r)
111  {
112  m_Edge = r.m_Edge;
113  m_Cost = r.m_Cost;
114  return *this;
115  }
116  bool
117  operator==(const FrontAtom & r) const
118  {
119  return (m_Edge == r.m_Edge);
120  }
121  bool
122  operator!=(const FrontAtom & r) const
123  {
124  return (m_Edge != r.m_Edge);
125  }
126  bool
127  operator<(const FrontAtom & r) const
128  {
129  return (m_Cost < r.m_Cost);
130  }
132 
133  public:
136  };
137 
141  using FrontType = std::list<FrontAtom>;
142  using FrontTypeIterator = typename FrontType::iterator;
144 
150 
151 public:
153  QuadEdgeMeshFrontBaseIterator(MeshType * mesh = (MeshType *)nullptr,
154  bool start = true,
155  QEType * seed = (QEType *)nullptr);
158 
159  Self &
160  operator=(const Self & r)
161  {
162  if (this != &r)
163  {
164  m_Mesh = r.m_Mesh;
165  m_Start = r.m_Start;
166  m_Seed = r.m_Seed;
167  m_Front = r.m_Front;
168  m_IsPointVisited = r.m_IsPointVisited;
169  m_CurrentEdge = r.m_CurrentEdge;
170  }
171  return (*this);
172  }
173 
174  // Iteration methods.
175  bool
177  {
178  return (m_Start == r.m_Start);
179  }
180 
181  bool
182  operator==(const Self & r) const
183  {
184  return (m_Start == r.m_Start);
185  }
186 
187  bool
189  {
190  return (!(this->operator==(r)));
191  }
192 
193  bool
194  operator!=(const Self & r) const
195  {
196  return (!(this->operator==(r)));
197  }
198 
199  Self &
200  operator++();
201 
202  Self &
204  {
205  return (this->operator++());
206  }
207 
208  MeshType *
209  GetMesh() const
210  {
211  return this->m_Mesh;
212  }
213 
214 protected:
218  QEType *
219  FindDefaultSeed();
220 
224  virtual CoordRepType
225  GetCost(QEType * edge)
226  {
227  (void)edge;
228  return (1);
229  }
231 
232 protected:
235 
238 
240  bool m_Start;
241 
244 
247 
250 };
251 
258 template <typename TMesh, typename TQE>
259 class ITK_TEMPLATE_EXPORT QuadEdgeMeshFrontIterator : public QuadEdgeMeshFrontBaseIterator<TMesh, TQE>
260 {
261 public:
262 
266  using MeshType = typename Superclass::MeshType;
267  using QEType = typename Superclass::QEType;
268 
269 public:
271  QuadEdgeMeshFrontIterator(MeshType * mesh = (MeshType *)0, bool start = true, QEType * seed = (QEType *)nullptr)
272  : Superclass(mesh, start, seed)
273  {}
274  ~QuadEdgeMeshFrontIterator() override = default;
275  QEType *
277  {
278  return (this->m_CurrentEdge);
279  }
280 };
282 
289 template <typename TMesh, typename TQE = typename TMesh::QEType>
290 class ITK_TEMPLATE_EXPORT QuadEdgeMeshConstFrontIterator : public QuadEdgeMeshFrontBaseIterator<TMesh, TQE>
291 {
292 public:
293 
297  using QEType = typename Superclass::QEType;
298  using MeshType = typename Superclass::MeshType;
300 
301 public:
304  bool start = true,
305  QEType * seed = (QEType *)nullptr)
306  {
307  (void)mesh;
308  (void)start;
309  (void)seed;
310  }
312 
314  ~QuadEdgeMeshConstFrontIterator() override = default;
315  Self &
317  {
318  this->m_Mesh = r.GetMesh();
319  return (*this);
320  }
322 
323  const QEType *
324  Value() const
325  {
326  return (this->m_CurrentEdge);
327  }
328 };
329 } // namespace itk
330 
331 #include "itkQuadEdgeMeshFrontIterator.hxx"
332 
333 #endif
itk::QuadEdgeMeshFrontBaseIterator::FrontTypePointer
FrontType * FrontTypePointer
Definition: itkQuadEdgeMeshFrontIterator.h:143
itk::QuadEdgeMeshFrontBaseIterator::operator==
bool operator==(const Self &r) const
Definition: itkQuadEdgeMeshFrontIterator.h:182
itk::QuadEdgeMeshFrontBaseIterator::m_IsPointVisited
IsVisitedPointerType m_IsPointVisited
Definition: itkQuadEdgeMeshFrontIterator.h:246
itk::QuadEdgeMeshFrontBaseIterator::FrontAtom::operator==
bool operator==(const FrontAtom &r) const
Definition: itkQuadEdgeMeshFrontIterator.h:117
itk::operator<
bool operator<(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:546
itk::QuadEdgeMeshFrontBaseIterator::m_Seed
QEType * m_Seed
Definition: itkQuadEdgeMeshFrontIterator.h:237
itk::QuadEdgeMeshFrontBaseIterator::FrontAtom
Atomic information associated to each edge of the front.
Definition: itkQuadEdgeMeshFrontIterator.h:101
itk::QuadEdgeMeshFrontBaseIterator::FrontAtom::m_Edge
QEType * m_Edge
Definition: itkQuadEdgeMeshFrontIterator.h:134
itk::QuadEdgeMeshFrontBaseIterator::MeshType
TMesh MeshType
Definition: itkQuadEdgeMeshFrontIterator.h:83
itk::QuadEdgeMeshFrontBaseIterator::m_Mesh
MeshType * m_Mesh
Definition: itkQuadEdgeMeshFrontIterator.h:234
itk::QuadEdgeMeshFrontBaseIterator::operator!=
bool operator!=(Self &r)
Definition: itkQuadEdgeMeshFrontIterator.h:188
itk::QuadEdgeMeshFrontBaseIterator::FrontType
std::list< FrontAtom > FrontType
Definition: itkQuadEdgeMeshFrontIterator.h:141
itk::QuadEdgeMeshFrontBaseIterator::FrontAtom::FrontAtom
FrontAtom(QEType *e=(QEType *) 0, const CoordRepType c=0)
Definition: itkQuadEdgeMeshFrontIterator.h:104
itk::SmartPointer< Self >
itk::QuadEdgeMeshFrontBaseIterator::GetMesh
MeshType * GetMesh() const
Definition: itkQuadEdgeMeshFrontIterator.h:209
itk::QuadEdgeMeshFrontBaseIterator::operator==
bool operator==(Self &r)
Definition: itkQuadEdgeMeshFrontIterator.h:176
itk::QuadEdgeMeshFrontBaseIterator::m_Front
FrontTypePointer m_Front
Definition: itkQuadEdgeMeshFrontIterator.h:243
itk::QuadEdgeMeshFrontIterator::QuadEdgeMeshFrontIterator
QuadEdgeMeshFrontIterator(MeshType *mesh=(MeshType *) 0, bool start=true, QEType *seed=(QEType *) nullptr)
Definition: itkQuadEdgeMeshFrontIterator.h:271
itk::MapContainer
A wrapper of the STL "map" container.
Definition: itkMapContainer.h:45
itk::QuadEdgeMeshFrontBaseIterator::CoordRepType
typename MeshType::CoordRepType CoordRepType
Definition: itkQuadEdgeMeshFrontIterator.h:88
itk::QuadEdgeMeshFrontBaseIterator::IsVisitedPointerType
typename IsVisitedContainerType::Pointer IsVisitedPointerType
Definition: itkQuadEdgeMeshFrontIterator.h:149
itk::QuadEdgeMeshFrontBaseIterator::GetCost
virtual CoordRepType GetCost(QEType *edge)
Definition: itkQuadEdgeMeshFrontIterator.h:225
itk::QuadEdgeMeshFrontBaseIterator
Front iterator on Mesh class.
Definition: itkQuadEdgeMeshFrontIterator.h:76
itk::QuadEdgeMeshFrontIterator
Non const quad edge front iterator.
Definition: itkQuadEdgeMeshFrontIterator.h:259
itk::QuadEdgeMeshFrontBaseIterator::FrontAtom::operator=
FrontAtom & operator=(const FrontAtom &r)
Definition: itkQuadEdgeMeshFrontIterator.h:110
itk::QuadEdgeMeshFrontBaseIterator::QEType
TQE QEType
Definition: itkQuadEdgeMeshFrontIterator.h:84
itk::QuadEdgeMeshFrontBaseIterator::operator!=
bool operator!=(const Self &r) const
Definition: itkQuadEdgeMeshFrontIterator.h:194
itk::QuadEdgeMeshFrontBaseIterator::FrontAtom::m_Cost
CoordRepType m_Cost
Definition: itkQuadEdgeMeshFrontIterator.h:135
itk::QuadEdgeMeshFrontBaseIterator::operator=
Self & operator=(const Self &r)
Definition: itkQuadEdgeMeshFrontIterator.h:160
itk::QuadEdgeMeshFrontBaseIterator::m_Start
bool m_Start
Definition: itkQuadEdgeMeshFrontIterator.h:240
itk::QuadEdgeMeshFrontBaseIterator::m_CurrentEdge
QEType * m_CurrentEdge
Definition: itkQuadEdgeMeshFrontIterator.h:249
itk::QuadEdgeMeshConstFrontIterator::Value
const QEType * Value() const
Definition: itkQuadEdgeMeshFrontIterator.h:324
itk::QuadEdgeMeshConstFrontIterator
Const quad edge mesh front iterator.
Definition: itkQuadEdgeMeshFrontIterator.h:290
itk::QuadEdgeMeshFrontBaseIterator::FrontTypeIterator
typename FrontType::iterator FrontTypeIterator
Definition: itkQuadEdgeMeshFrontIterator.h:142
itk::QuadEdgeMeshFrontBaseIterator::FrontAtom::operator!=
bool operator!=(const FrontAtom &r) const
Definition: itkQuadEdgeMeshFrontIterator.h:122
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::QuadEdgeMeshFrontBaseIterator::QEOriginType
typename QEType::OriginRefType QEOriginType
Definition: itkQuadEdgeMeshFrontIterator.h:90
itk::QuadEdgeMeshFrontIterator::Value
QEType * Value()
Definition: itkQuadEdgeMeshFrontIterator.h:276
itk::Math::e
static constexpr double e
Definition: itkMath.h:54
itkMapContainer.h
itk::QuadEdgeMeshFrontBaseIterator::operator++
Self & operator++(int)
Definition: itkQuadEdgeMeshFrontIterator.h:203
itk::QuadEdgeMeshConstFrontIterator::QuadEdgeMeshConstFrontIterator
QuadEdgeMeshConstFrontIterator(const MeshType *mesh=(MeshType *) 0, bool start=true, QEType *seed=(QEType *) nullptr)
Definition: itkQuadEdgeMeshFrontIterator.h:303
itk::QuadEdgeMeshConstFrontIterator::operator=
Self & operator=(const NoConstType &r)
Definition: itkQuadEdgeMeshFrontIterator.h:316