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 & 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 
63  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(ConstSparseFieldLayerIterator);
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 
83  ~ConstSparseFieldLayerIterator() = default;
84 
85 protected:
86  TNodeType * m_Pointer;
87 };
88 
93 template <typename TNodeType>
94 class ITK_TEMPLATE_EXPORT SparseFieldLayerIterator : public ConstSparseFieldLayerIterator<TNodeType>
95 {
96 public:
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 
161 template <typename TNodeType>
162 class ITK_TEMPLATE_EXPORT SparseFieldLayer : public Object
163 {
164 public:
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 
193  struct RegionType
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
264  End()
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 
299  RegionListType
300  SplitRegions(int num) const;
301 
302 protected:
304  ~SparseFieldLayer() override = default;
305  void
306  PrintSelf(std::ostream & os, Indent indent) const override;
307 
308 private:
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
itk::SparseFieldLayerIterator::SparseFieldLayerIterator
SparseFieldLayerIterator()
Definition: itkSparseFieldLayer.h:99
itkObjectFactory.h
itk::SparseFieldLayer::RegionListType
std::vector< RegionType > RegionListType
Definition: itkSparseFieldLayer.h:199
itk::ConstSparseFieldLayerIterator::operator++
ConstSparseFieldLayerIterator & operator++()
Definition: itkSparseFieldLayer.h:66
itk::SparseFieldLayer::End
Iterator End()
Definition: itkSparseFieldLayer.h:264
itk::SparseFieldLayer::RegionType
Definition: itkSparseFieldLayer.h:193
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:240
itk::SparseFieldLayerIterator::SparseFieldLayerIterator
SparseFieldLayerIterator(TNodeType *p)
Definition: itkSparseFieldLayer.h:103
itk::SparseFieldLayerIterator::GetPointer
TNodeType * GetPointer()
Definition: itkSparseFieldLayer.h:112
itk::SparseFieldLayerIterator::operator++
SparseFieldLayerIterator & operator++()
Definition: itkSparseFieldLayer.h:118
itk::ConstSparseFieldLayerIterator::ConstSparseFieldLayerIterator
ConstSparseFieldLayerIterator(TNodeType *p)
Definition: itkSparseFieldLayer.h:81
itk::SparseFieldLayerIterator::operator*
TNodeType & operator*()
Definition: itkSparseFieldLayer.h:107
itk::SparseFieldLayerIterator::operator->
TNodeType * operator->()
Definition: itkSparseFieldLayer.h:109
itk::SmartPointer< Self >
itk::ConstSparseFieldLayerIterator::operator*
const TNodeType & operator*() const
Definition: itkSparseFieldLayer.h:40
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:132
itk::ConstSparseFieldLayerIterator::GetPointer
const TNodeType * GetPointer() const
Definition: itkSparseFieldLayer.h:45
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:162
itk::SparseFieldLayer::Empty
bool Empty() const
Definition: itkSparseFieldLayer.h:279
itk::SparseFieldLayer::NodeType
TNodeType NodeType
Definition: itkSparseFieldLayer.h:180
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::SparseFieldLayer::Front
const NodeType * Front() const
Definition: itkSparseFieldLayer.h:211
itk::ConstSparseFieldLayerIterator::operator==
bool operator==(const ConstSparseFieldLayerIterator o) const
Definition: itkSparseFieldLayer.h:51
itk::SparseFieldLayerIterator
The non-const version of the ConstSparseFieldLayerIterator.
Definition: itkSparseFieldLayer.h:94
itk::ConstSparseFieldLayerIterator::operator->
const TNodeType * operator->() const
Definition: itkSparseFieldLayer.h:42
itkObject.h
itk::ConstSparseFieldLayerIterator::m_Pointer
TNodeType * m_Pointer
Definition: itkSparseFieldLayer.h:86
itk::ConstSparseFieldLayerIterator::ConstSparseFieldLayerIterator
ConstSparseFieldLayerIterator()
Definition: itkSparseFieldLayer.h:79
itk::SparseFieldLayer::RegionType::first
ConstIterator first
Definition: itkSparseFieldLayer.h:195
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:257
itk::SparseFieldLayer::ValueType
NodeType ValueType
Definition: itkSparseFieldLayer.h:184
itk::SparseFieldLayer::Begin
Iterator Begin()
Definition: itkSparseFieldLayer.h:249
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:61
itk::ConstSparseFieldLayerIterator::operator--
ConstSparseFieldLayerIterator & operator--()
Definition: itkSparseFieldLayer.h:73
itk::SparseFieldLayer::Front
NodeType * Front()
Definition: itkSparseFieldLayer.h:204
itk::SparseFieldLayer::End
ConstIterator End() const
Definition: itkSparseFieldLayer.h:271
itk::SparseFieldLayer::PushFront
void PushFront(NodeType *n)
Definition: itkSparseFieldLayer.h:228
itk::SparseFieldLayerIterator::operator--
SparseFieldLayerIterator & operator--()
Definition: itkSparseFieldLayer.h:125
itk::SparseFieldLayer::PopFront
void PopFront()
Definition: itkSparseFieldLayer.h:218
itk::SparseFieldLayer::RegionType::last
ConstIterator last
Definition: itkSparseFieldLayer.h:196