ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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 [[nodiscard]] 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
88
90 : m_Pointer(p)
91 {}
92
93protected:
94 TNodeType * m_Pointer;
95};
96
101template <typename TNodeType>
102class ITK_TEMPLATE_EXPORT SparseFieldLayerIterator : public ConstSparseFieldLayerIterator<TNodeType>
103{
104public:
106
110
112 : Superclass(p)
113 {}
114
115 TNodeType &
117 {
118 return *this->m_Pointer;
119 }
120
121 TNodeType *
123 {
124 return this->m_Pointer;
125 }
126
127 TNodeType *
129 {
130 return this->m_Pointer;
131 }
132
135 {
136 this->m_Pointer = this->m_Pointer->Next;
137 return *this;
138 }
139
142 {
143 this->m_Pointer = this->m_Pointer->Previous;
144 return *this;
145 }
146
149 {
150 this->m_Pointer = const_cast<TNodeType *>(sc.GetPointer());
151 return *this;
152 }
153};
154
177template <typename TNodeType>
178class ITK_TEMPLATE_EXPORT SparseFieldLayer : public Object
179{
180public:
181 ITK_DISALLOW_COPY_AND_MOVE(SparseFieldLayer);
182
188
190 itkNewMacro(Self);
191
193 itkOverrideGetNameOfClassMacro(SparseFieldLayer);
194
196 using NodeType = TNodeType;
197
201
204
207
210 {
212 ConstIterator last; // this is one past the actual last element
213 };
214
215 using RegionListType = std::vector<RegionType>;
216
219 NodeType *
221 {
222 return m_HeadNode->Next;
223 }
224
226 const NodeType *
227 Front() const
228 {
229 return m_HeadNode->Next;
230 }
231
233 void
235 {
236 m_HeadNode->Next = m_HeadNode->Next->Next;
237 m_HeadNode->Next->Previous = m_HeadNode.get();
238 m_Size -= 1;
239 }
240
242 void
244 {
245 n->Next = m_HeadNode->Next;
246 n->Previous = m_HeadNode.get();
247 m_HeadNode->Next->Previous = n;
248 m_HeadNode->Next = n;
249 m_Size += 1;
250 }
251
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:51
Implements transparent reference counting.
The non-const version of the ConstSparseFieldLayerIterator.
SparseFieldLayerIterator & operator--()
ConstSparseFieldLayerIterator< TNodeType > Superclass
SparseFieldLayerIterator & operator=(Superclass &sc)
SparseFieldLayerIterator & operator++()
~SparseFieldLayer() override=default
void PushFront(NodeType *n)
SmartPointer< const Self > ConstPointer
const NodeType * Front() const
const std::unique_ptr< NodeType > m_HeadNode
SmartPointer< Self > Pointer
RegionListType SplitRegions(int num) const
ConstIterator End() const
SparseFieldLayerIterator< NodeType > Iterator
void PrintSelf(std::ostream &os, Indent indent) const override
ConstIterator Begin() const
ConstSparseFieldLayerIterator< NodeType > ConstIterator
std::vector< RegionType > RegionListType
unsigned int Size() const
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....