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
94
95protected:
96 TNodeType * m_Pointer;
97};
98
103template <typename TNodeType>
104class ITK_TEMPLATE_EXPORT SparseFieldLayerIterator : public ConstSparseFieldLayerIterator<TNodeType>
105{
106public:
108
112
114 : Superclass(p)
115 {}
116
117 TNodeType &
119 {
120 return *this->m_Pointer;
121 }
122
123 TNodeType *
125 {
126 return this->m_Pointer;
127 }
128
129 TNodeType *
131 {
132 return this->m_Pointer;
133 }
134
137 {
138 this->m_Pointer = this->m_Pointer->Next;
139 return *this;
140 }
141
144 {
145 this->m_Pointer = this->m_Pointer->Previous;
146 return *this;
147 }
148
151 {
152 this->m_Pointer = const_cast<TNodeType *>(sc.GetPointer());
153 return *this;
154 }
155};
156
179template <typename TNodeType>
180class ITK_TEMPLATE_EXPORT SparseFieldLayer : public Object
181{
182public:
183 ITK_DISALLOW_COPY_AND_MOVE(SparseFieldLayer);
184
190
192 itkNewMacro(Self);
193
195 itkOverrideGetNameOfClassMacro(SparseFieldLayer);
196
198 using NodeType = TNodeType;
199
203
206
209
212 {
214 ConstIterator last; // this is one past the actual last element
215 };
216
217 using RegionListType = std::vector<RegionType>;
218
221 NodeType *
223 {
224 return m_HeadNode->Next;
225 }
226
228 const NodeType *
229 Front() const
230 {
231 return m_HeadNode->Next;
232 }
233
235 void
237 {
238 m_HeadNode->Next = m_HeadNode->Next->Next;
239 m_HeadNode->Next->Previous = m_HeadNode.get();
240 m_Size -= 1;
241 }
242
244 void
246 {
247 n->Next = m_HeadNode->Next;
248 n->Previous = m_HeadNode.get();
249 m_HeadNode->Next->Previous = n;
250 m_HeadNode->Next = n;
251 m_Size += 1;
252 }
253
255 void
257 {
258 n->Previous->Next = n->Next;
259 n->Next->Previous = n->Previous;
260 m_Size -= 1;
261 }
262
264 Iterator
266 {
267 return Iterator(m_HeadNode->Next);
268 }
269
272 ConstIterator
273 Begin() const
274 {
275 return ConstIterator(m_HeadNode->Next);
276 }
277
279 Iterator
281 {
282 return Iterator(m_HeadNode.get());
283 }
284
286 ConstIterator
287 End() const
288 {
289 return ConstIterator(m_HeadNode.get());
290 }
291
294 bool
295 Empty() const
296 {
297 if (m_HeadNode->Next == m_HeadNode.get())
298 {
299 return true;
300 }
301
302 return false;
303 }
304
307 unsigned int
308 Size() const;
309
313 SplitRegions(int num) const;
314
315protected:
317 ~SparseFieldLayer() override = default;
318 void
319 PrintSelf(std::ostream & os, Indent indent) const override;
320
321private:
324 const std::unique_ptr<NodeType> m_HeadNode{ std::make_unique<NodeType>() };
325 unsigned int m_Size{};
326};
327} // end namespace itk
328
329#ifndef ITK_MANUAL_INSTANTIATION
330# include "itkSparseFieldLayer.hxx"
331#endif
332
333#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
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....