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 & operator*() const { return *m_Pointer; }
41
42 const TNodeType * operator->() const { return m_Pointer; }
43
44 const TNodeType *
45 GetPointer() const
46 {
47 return m_Pointer;
48 }
49
50 bool
52 {
53 if (m_Pointer == o.m_Pointer)
54 {
55 return true;
56 }
57 else
58 {
59 return false;
60 }
61 }
62
64
67 {
68 m_Pointer = m_Pointer->Next;
69 return *this;
70 }
71
74 {
75 m_Pointer = m_Pointer->Previous;
76 return *this;
77 }
78
79 ConstSparseFieldLayerIterator() { m_Pointer = nullptr; }
80
81 ConstSparseFieldLayerIterator(TNodeType * p) { m_Pointer = p; }
82
84
85protected:
86 TNodeType * m_Pointer;
87};
88
93template <typename TNodeType>
94class ITK_TEMPLATE_EXPORT SparseFieldLayerIterator : public ConstSparseFieldLayerIterator<TNodeType>
95{
96public:
98
100 : Superclass()
101 {}
102
104 : Superclass(p)
105 {}
106
107 TNodeType & operator*() { return *this->m_Pointer; }
108
109 TNodeType * operator->() { return this->m_Pointer; }
110
111 TNodeType *
113 {
114 return this->m_Pointer;
115 }
116
119 {
120 this->m_Pointer = this->m_Pointer->Next;
121 return *this;
122 }
123
126 {
127 this->m_Pointer = this->m_Pointer->Previous;
128 return *this;
129 }
130
133 {
134 this->m_Pointer = const_cast<TNodeType *>(sc.GetPointer());
135 return *this;
136 }
137};
138
161template <typename TNodeType>
162class ITK_TEMPLATE_EXPORT SparseFieldLayer : public Object
163{
164public:
165 ITK_DISALLOW_COPY_AND_MOVE(SparseFieldLayer);
166
172
174 itkNewMacro(Self);
175
177 itkOverrideGetNameOfClassMacro(SparseFieldLayer);
178
180 using NodeType = TNodeType;
181
185
188
191
194 {
196 ConstIterator last; // this is one past the actual last element
197 };
198
199 using RegionListType = std::vector<RegionType>;
200
203 NodeType *
205 {
206 return m_HeadNode->Next;
207 }
208
210 const NodeType *
211 Front() const
212 {
213 return m_HeadNode->Next;
214 }
215
217 void
219 {
220 m_HeadNode->Next = m_HeadNode->Next->Next;
221 m_HeadNode->Next->Previous = m_HeadNode.get();
222 m_Size -= 1;
223 }
227 void
229 {
230 n->Next = m_HeadNode->Next;
231 n->Previous = m_HeadNode.get();
232 m_HeadNode->Next->Previous = n;
233 m_HeadNode->Next = n;
234 m_Size += 1;
235 }
239 void
241 {
242 n->Previous->Next = n->Next;
243 n->Next->Previous = n->Previous;
244 m_Size -= 1;
245 }
246
248 Iterator
250 {
251 return Iterator(m_HeadNode->Next);
252 }
253
256 ConstIterator
257 Begin() const
258 {
259 return ConstIterator(m_HeadNode->Next);
260 }
261
263 Iterator
265 {
266 return Iterator(m_HeadNode.get());
267 }
268
270 ConstIterator
271 End() const
272 {
273 return ConstIterator(m_HeadNode.get());
274 }
275
278 bool
279 Empty() const
280 {
281 if (m_HeadNode->Next == m_HeadNode.get())
282 {
283 return true;
284 }
285 else
286 {
287 return false;
288 }
289 }
294 unsigned int
295 Size() const;
296
300 SplitRegions(int num) const;
301
302protected:
304 ~SparseFieldLayer() override = default;
305 void
306 PrintSelf(std::ostream & os, Indent indent) const override;
307
308private:
311 const std::unique_ptr<NodeType> m_HeadNode{ std::make_unique<NodeType>() };
312 unsigned int m_Size{};
313};
314} // end namespace itk
315
316#ifndef ITK_MANUAL_INSTANTIATION
317# include "itkSparseFieldLayer.hxx"
318#endif
319
320#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....