ITK  6.0.0
Insight Toolkit
itkSparseFieldLayer.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 itkSparseFieldLayer_h
19#define itkSparseFieldLayer_h
20
21#include "itkObjectFactory.h"
22#include "itkObject.h"
23#include <vector>
24#include <memory> // For unique_ptr.
25
26namespace itk
27{
36template <typename TNodeType>
37class ITK_TEMPLATE_EXPORT ConstSparseFieldLayerIterator
38{
39public:
40 const TNodeType &
41 operator*() const
42 {
43 return *m_Pointer;
44 }
45
46 const TNodeType *
47 operator->() const
48 {
49 return m_Pointer;
50 }
51
52 const TNodeType *
53 GetPointer() const
54 {
55 return m_Pointer;
56 }
57
58 bool
60 {
61 if (m_Pointer == o.m_Pointer)
62 {
63 return true;
64 }
65
66 return false;
67 }
68
70
73 {
74 m_Pointer = m_Pointer->Next;
75 return *this;
76 }
77
80 {
81 m_Pointer = m_Pointer->Previous;
82 return *this;
83 }
84
85 ConstSparseFieldLayerIterator() { m_Pointer = nullptr; }
86
87 ConstSparseFieldLayerIterator(TNodeType * p) { m_Pointer = p; }
88
90
91protected:
92 TNodeType * m_Pointer;
93};
94
99template <typename TNodeType>
100class ITK_TEMPLATE_EXPORT SparseFieldLayerIterator : public ConstSparseFieldLayerIterator<TNodeType>
101{
102public:
104
106 : Superclass()
107 {}
108
110 : Superclass(p)
111 {}
112
113 TNodeType &
115 {
116 return *this->m_Pointer;
117 }
118
119 TNodeType *
121 {
122 return this->m_Pointer;
123 }
124
125 TNodeType *
127 {
128 return this->m_Pointer;
129 }
130
133 {
134 this->m_Pointer = this->m_Pointer->Next;
135 return *this;
136 }
137
140 {
141 this->m_Pointer = this->m_Pointer->Previous;
142 return *this;
143 }
144
147 {
148 this->m_Pointer = const_cast<TNodeType *>(sc.GetPointer());
149 return *this;
150 }
151};
152
175template <typename TNodeType>
176class ITK_TEMPLATE_EXPORT SparseFieldLayer : public Object
177{
178public:
179 ITK_DISALLOW_COPY_AND_MOVE(SparseFieldLayer);
180
186
188 itkNewMacro(Self);
189
191 itkOverrideGetNameOfClassMacro(SparseFieldLayer);
192
194 using NodeType = TNodeType;
195
199
202
205
208 {
210 ConstIterator last; // this is one past the actual last element
211 };
212
213 using RegionListType = std::vector<RegionType>;
214
217 NodeType *
219 {
220 return m_HeadNode->Next;
221 }
222
224 const NodeType *
225 Front() const
226 {
227 return m_HeadNode->Next;
228 }
229
231 void
233 {
234 m_HeadNode->Next = m_HeadNode->Next->Next;
235 m_HeadNode->Next->Previous = m_HeadNode.get();
236 m_Size -= 1;
237 }
241 void
243 {
244 n->Next = m_HeadNode->Next;
245 n->Previous = m_HeadNode.get();
246 m_HeadNode->Next->Previous = n;
247 m_HeadNode->Next = n;
248 m_Size += 1;
249 }
253 void
255 {
256 n->Previous->Next = n->Next;
257 n->Next->Previous = n->Previous;
258 m_Size -= 1;
259 }
260
262 Iterator
264 {
265 return Iterator(m_HeadNode->Next);
266 }
267
270 ConstIterator
271 Begin() const
272 {
273 return ConstIterator(m_HeadNode->Next);
274 }
275
277 Iterator
279 {
280 return Iterator(m_HeadNode.get());
281 }
282
284 ConstIterator
285 End() const
286 {
287 return ConstIterator(m_HeadNode.get());
288 }
289
292 bool
293 Empty() const
294 {
295 if (m_HeadNode->Next == m_HeadNode.get())
296 {
297 return true;
298 }
299
300 return false;
301 }
302
305 unsigned int
306 Size() const;
307
311 SplitRegions(int num) const;
312
313protected:
315 ~SparseFieldLayer() override = default;
316 void
317 PrintSelf(std::ostream & os, Indent indent) const override;
318
319private:
322 const std::unique_ptr<NodeType> m_HeadNode{ std::make_unique<NodeType>() };
323 unsigned int m_Size{};
324};
325} // end namespace itk
326
327#ifndef ITK_MANUAL_INSTANTIATION
328# include "itkSparseFieldLayer.hxx"
329#endif
330
331#endif
Used to iterate through an itkSparseFieldLayer.
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(ConstSparseFieldLayerIterator)
ConstSparseFieldLayerIterator & operator++()
const TNodeType * operator->() const
const TNodeType & operator*() const
const TNodeType * GetPointer() const
bool operator==(const ConstSparseFieldLayerIterator o) const
ConstSparseFieldLayerIterator & operator--()
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
Base class for most ITK classes.
Definition: itkObject.h:62
The non-const version of the ConstSparseFieldLayerIterator.
SparseFieldLayerIterator & operator--()
SparseFieldLayerIterator & operator=(Superclass &sc)
SparseFieldLayerIterator & operator++()
A very simple linked list that is used to manage nodes in a layer of a sparse field level-set solver.
void Unlink(NodeType *n)
~SparseFieldLayer() override=default
void PushFront(NodeType *n)
const NodeType * Front() const
RegionListType SplitRegions(int num) const
ConstIterator End() const
void PrintSelf(std::ostream &os, Indent indent) const override
ConstIterator Begin() const
std::vector< RegionType > RegionListType
unsigned int Size() const
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....