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 
26 namespace itk
27 {
36 template <typename TNodeType>
37 class ITK_TEMPLATE_EXPORT ConstSparseFieldLayerIterator
38 {
39 public:
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 
69  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(ConstSparseFieldLayerIterator);
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 
89  ~ConstSparseFieldLayerIterator() = default;
90 
91 protected:
92  TNodeType * m_Pointer;
93 };
94 
99 template <typename TNodeType>
100 class ITK_TEMPLATE_EXPORT SparseFieldLayerIterator : public ConstSparseFieldLayerIterator<TNodeType>
101 {
102 public:
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 
175 template <typename TNodeType>
176 class ITK_TEMPLATE_EXPORT SparseFieldLayer : public Object
177 {
178 public:
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 
207  struct RegionType
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
278  End()
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 
310  RegionListType
311  SplitRegions(int num) const;
312 
313 protected:
315  ~SparseFieldLayer() override = default;
316  void
317  PrintSelf(std::ostream & os, Indent indent) const override;
318 
319 private:
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
itk::SparseFieldLayerIterator::SparseFieldLayerIterator
SparseFieldLayerIterator()
Definition: itkSparseFieldLayer.h:105
itkObjectFactory.h
itk::SparseFieldLayer::RegionListType
std::vector< RegionType > RegionListType
Definition: itkSparseFieldLayer.h:213
itk::ConstSparseFieldLayerIterator::operator++
ConstSparseFieldLayerIterator & operator++()
Definition: itkSparseFieldLayer.h:72
itk::SparseFieldLayer::End
Iterator End()
Definition: itkSparseFieldLayer.h:278
itk::SparseFieldLayer::RegionType
Definition: itkSparseFieldLayer.h:207
itk::Size
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:69
itk::SparseFieldLayer::Unlink
void Unlink(NodeType *n)
Definition: itkSparseFieldLayer.h:254
itk::SparseFieldLayerIterator::SparseFieldLayerIterator
SparseFieldLayerIterator(TNodeType *p)
Definition: itkSparseFieldLayer.h:109
itk::SparseFieldLayerIterator::GetPointer
TNodeType * GetPointer()
Definition: itkSparseFieldLayer.h:126
itk::SparseFieldLayerIterator::operator++
SparseFieldLayerIterator & operator++()
Definition: itkSparseFieldLayer.h:132
itk::ConstSparseFieldLayerIterator::ConstSparseFieldLayerIterator
ConstSparseFieldLayerIterator(TNodeType *p)
Definition: itkSparseFieldLayer.h:87
itk::SparseFieldLayerIterator::operator*
TNodeType & operator*()
Definition: itkSparseFieldLayer.h:114
itk::SparseFieldLayerIterator::operator->
TNodeType * operator->()
Definition: itkSparseFieldLayer.h:120
itk::SmartPointer< Self >
itk::ConstSparseFieldLayerIterator::operator*
const TNodeType & operator*() const
Definition: itkSparseFieldLayer.h:41
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ConstSparseFieldLayerIterator
Used to iterate through an itkSparseFieldLayer.
Definition: itkSparseFieldLayer.h:37
itk::SparseFieldLayerIterator::operator=
SparseFieldLayerIterator & operator=(Superclass &sc)
Definition: itkSparseFieldLayer.h:146
itk::ConstSparseFieldLayerIterator::GetPointer
const TNodeType * GetPointer() const
Definition: itkSparseFieldLayer.h:53
itk::SparseFieldLayer
A very simple linked list that is used to manage nodes in a layer of a sparse field level-set solver.
Definition: itkSparseFieldLayer.h:176
itk::SparseFieldLayer::Empty
bool Empty() const
Definition: itkSparseFieldLayer.h:293
itk::SparseFieldLayer::NodeType
TNodeType NodeType
Definition: itkSparseFieldLayer.h:194
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::SparseFieldLayer::Front
const NodeType * Front() const
Definition: itkSparseFieldLayer.h:225
itk::ConstSparseFieldLayerIterator::operator==
bool operator==(const ConstSparseFieldLayerIterator o) const
Definition: itkSparseFieldLayer.h:59
itk::SparseFieldLayerIterator
The non-const version of the ConstSparseFieldLayerIterator.
Definition: itkSparseFieldLayer.h:100
itk::ConstSparseFieldLayerIterator::operator->
const TNodeType * operator->() const
Definition: itkSparseFieldLayer.h:47
itkObject.h
itk::ConstSparseFieldLayerIterator::m_Pointer
TNodeType * m_Pointer
Definition: itkSparseFieldLayer.h:92
itk::ConstSparseFieldLayerIterator::ConstSparseFieldLayerIterator
ConstSparseFieldLayerIterator()
Definition: itkSparseFieldLayer.h:85
itk::SparseFieldLayer::RegionType::first
ConstIterator first
Definition: itkSparseFieldLayer.h:209
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::SparseFieldLayer::Begin
ConstIterator Begin() const
Definition: itkSparseFieldLayer.h:271
itk::SparseFieldLayer::ValueType
NodeType ValueType
Definition: itkSparseFieldLayer.h:198
itk::SparseFieldLayer::Begin
Iterator Begin()
Definition: itkSparseFieldLayer.h:263
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:61
itk::ConstSparseFieldLayerIterator::operator--
ConstSparseFieldLayerIterator & operator--()
Definition: itkSparseFieldLayer.h:79
itk::SparseFieldLayer::Front
NodeType * Front()
Definition: itkSparseFieldLayer.h:218
itk::SparseFieldLayer::End
ConstIterator End() const
Definition: itkSparseFieldLayer.h:285
itk::SparseFieldLayer::PushFront
void PushFront(NodeType *n)
Definition: itkSparseFieldLayer.h:242
itk::SparseFieldLayerIterator::operator--
SparseFieldLayerIterator & operator--()
Definition: itkSparseFieldLayer.h:139
itk::SparseFieldLayer::PopFront
void PopFront()
Definition: itkSparseFieldLayer.h:232
itk::SparseFieldLayer::RegionType::last
ConstIterator last
Definition: itkSparseFieldLayer.h:210