ITK  6.0.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 * https://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 = nullptr) { return (FrontIterator(this, true, seed)); } \
36 \
37 virtual ConstFrontIterator BeginFront(QEPrimalType * seed) const { return (ConstFrontIterator(this, true, seed)); } \
38 \
39 virtual FrontIterator EndFront() { return (FrontIterator(this, false)); } \
40 \
41 virtual ConstFrontIterator EndFront() const { return (ConstFrontIterator(this, false)); } \
42 \
43 virtual FrontDualIterator BeginDualFront(QEDualType * seed = (QEDualType *)0) \
44 { \
45 return (FrontDualIterator(this, true, seed)); \
46 } \
47 \
48 virtual ConstFrontDualIterator BeginDualFront(QEDualType * seed) const \
49 { \
50 return (ConstFrontDualIterator(this, true, seed)); \
51 } \
52 \
53 virtual FrontDualIterator EndDualFront() { return (FrontDualIterator(this, false)); } \
54 \
55 virtual ConstFrontDualIterator EndDualFront() const { return (ConstFrontDualIterator(this, false)); } \
56 \
57 ITK_MACROEND_NOOP_STATEMENT
58
59namespace itk
60{
74template <typename TMesh, typename TQE>
75class ITK_TEMPLATE_EXPORT QuadEdgeMeshFrontBaseIterator
76{
77public:
78 // Hierarchy type alias & values.
80
81 // Template types
82 using MeshType = TMesh;
83 using QEType = TQE;
84
85protected:
86 // Mesh types
87 using CoordRepType = typename MeshType::CoordRepType;
88 // QE types
89 using QEOriginType = typename QEType::OriginRefType;
90
101 {
102 public:
103 FrontAtom(QEType * e = (QEType *)0, const CoordRepType c = 0)
104 : m_Edge(e)
105 , m_Cost(c)
106 {}
107 virtual ~FrontAtom() = default;
108 FrontAtom &
110 {
111 m_Edge = r.m_Edge;
112 m_Cost = r.m_Cost;
113 return *this;
114 }
115 bool
116 operator==(const FrontAtom & r) const
117 {
118 return (m_Edge == r.m_Edge);
119 }
123
124 bool
125 operator<(const FrontAtom & r) const
126 {
127 return (m_Cost < r.m_Cost);
128 }
129
130 public:
133 };
134
138 using FrontType = std::list<FrontAtom>;
139 using FrontTypeIterator = typename FrontType::iterator;
141
147
148public:
150 QuadEdgeMeshFrontBaseIterator(MeshType * mesh = nullptr, bool start = true, QEType * seed = nullptr);
154 Self &
155 operator=(const Self & r)
156 {
157 if (this != &r)
158 {
159 m_Mesh = r.m_Mesh;
160 m_Start = r.m_Start;
161 m_Seed = r.m_Seed;
162 m_Front = r.m_Front;
163 m_IsPointVisited = r.m_IsPointVisited;
164 m_CurrentEdge = r.m_CurrentEdge;
165 }
166 return (*this);
167 }
168
169 // Iteration methods.
170 bool
171 operator==(const Self & r) const
172 {
173 return (m_Start == r.m_Start);
174 }
175
177
178 Self &
180
181 Self &
183 {
184 return (this->operator++());
185 }
186
187 MeshType *
188 GetMesh() const
189 {
190 return this->m_Mesh;
191 }
192
193protected:
197 QEType *
199
203 virtual CoordRepType
204 GetCost(QEType * itkNotUsed(edge))
205 {
206 return (1);
207 }
208
209protected:
211 MeshType * m_Mesh{};
212
214 QEType * m_Seed{};
215
217 bool m_Start{};
218
221
223 IsVisitedPointerType m_IsPointVisited{};
224
226 QEType * m_CurrentEdge{};
227};
228
235template <typename TMesh, typename TQE>
236class ITK_TEMPLATE_EXPORT QuadEdgeMeshFrontIterator : public QuadEdgeMeshFrontBaseIterator<TMesh, TQE>
237{
238public:
239
243 using typename Superclass::MeshType;
244 using typename Superclass::QEType;
245
246public:
248 QuadEdgeMeshFrontIterator(MeshType * mesh = (MeshType *)0, bool start = true, QEType * seed = nullptr)
249 : Superclass(mesh, start, seed)
250 {}
251 ~QuadEdgeMeshFrontIterator() override = default;
252 QEType *
254 {
255 return (this->m_CurrentEdge);
256 }
257};
266template <typename TMesh, typename TQE = typename TMesh::QEType>
267class ITK_TEMPLATE_EXPORT QuadEdgeMeshConstFrontIterator : public QuadEdgeMeshFrontBaseIterator<TMesh, TQE>
268{
269public:
270
274 using typename Superclass::QEType;
275 using typename Superclass::MeshType;
277
278public:
280 QuadEdgeMeshConstFrontIterator(const MeshType * itkNotUsed(mesh) = (MeshType *)0,
281 bool itkNotUsed(start) = true,
282 QEType * itkNotUsed(seed) = (QEType *)nullptr)
283 {}
284
287 Self &
289 {
290 this->m_Mesh = r.GetMesh();
291 return (*this);
292 }
295 const QEType *
296 Value() const
297 {
298 return (this->m_CurrentEdge);
299 }
300};
301} // namespace itk
302
303#include "itkQuadEdgeMeshFrontIterator.hxx"
304
305#endif
A wrapper of the STL "map" container.
Const quad edge mesh front iterator.
~QuadEdgeMeshConstFrontIterator() override=default
QuadEdgeMeshConstFrontIterator(const MeshType *=(MeshType *) 0, bool=true, QEType *=(QEType *) nullptr)
Atomic information associated to each edge of the front.
FrontAtom(QEType *e=(QEType *) 0, const CoordRepType c=0)
typename FrontType::iterator FrontTypeIterator
typename MeshType::CoordRepType CoordRepType
typename IsVisitedContainerType::Pointer IsVisitedPointerType
typename QEType::OriginRefType QEOriginType
QuadEdgeMeshFrontBaseIterator(MeshType *mesh=nullptr, bool start=true, QEType *seed=nullptr)
Non const quad edge front iterator.
QuadEdgeMeshFrontIterator(MeshType *mesh=(MeshType *) 0, bool start=true, QEType *seed=nullptr)
~QuadEdgeMeshFrontIterator() override=default
SmartPointer< Self > Pointer
static constexpr double e
Definition: itkMath.h:56
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
bool operator<(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:557