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  else
66  {
67  return false;
68  }
69  }
70 
71  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(ConstSparseFieldLayerIterator);
72 
75  {
76  m_Pointer = m_Pointer->Next;
77  return *this;
78  }
79 
82  {
83  m_Pointer = m_Pointer->Previous;
84  return *this;
85  }
86 
87  ConstSparseFieldLayerIterator() { m_Pointer = nullptr; }
88 
89  ConstSparseFieldLayerIterator(TNodeType * p) { m_Pointer = p; }
90 
91  ~ConstSparseFieldLayerIterator() = default;
92 
93 protected:
94  TNodeType * m_Pointer;
95 };
96 
101 template <typename TNodeType>
102 class ITK_TEMPLATE_EXPORT SparseFieldLayerIterator : public ConstSparseFieldLayerIterator<TNodeType>
103 {
104 public:
106 
108  : Superclass()
109  {}
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 
177 template <typename TNodeType>
178 class ITK_TEMPLATE_EXPORT SparseFieldLayer : public Object
179 {
180 public:
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 
209  struct RegionType
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  }
243  void
245  {
246  n->Next = m_HeadNode->Next;
247  n->Previous = m_HeadNode.get();
248  m_HeadNode->Next->Previous = n;
249  m_HeadNode->Next = n;
250  m_Size += 1;
251  }
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
280  End()
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  else
302  {
303  return false;
304  }
305  }
310  unsigned int
311  Size() const;
312 
315  RegionListType
316  SplitRegions(int num) const;
317 
318 protected:
320  ~SparseFieldLayer() override = default;
321  void
322  PrintSelf(std::ostream & os, Indent indent) const override;
323 
324 private:
327  const std::unique_ptr<NodeType> m_HeadNode{ std::make_unique<NodeType>() };
328  unsigned int m_Size{};
329 };
330 } // end namespace itk
331 
332 #ifndef ITK_MANUAL_INSTANTIATION
333 # include "itkSparseFieldLayer.hxx"
334 #endif
335 
336 #endif
itk::SparseFieldLayerIterator::SparseFieldLayerIterator
SparseFieldLayerIterator()
Definition: itkSparseFieldLayer.h:107
itkObjectFactory.h
itk::SparseFieldLayer::RegionListType
std::vector< RegionType > RegionListType
Definition: itkSparseFieldLayer.h:215
itk::ConstSparseFieldLayerIterator::operator++
ConstSparseFieldLayerIterator & operator++()
Definition: itkSparseFieldLayer.h:74
itk::SparseFieldLayer::End
Iterator End()
Definition: itkSparseFieldLayer.h:280
itk::SparseFieldLayer::RegionType
Definition: itkSparseFieldLayer.h:209
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:256
itk::SparseFieldLayerIterator::SparseFieldLayerIterator
SparseFieldLayerIterator(TNodeType *p)
Definition: itkSparseFieldLayer.h:111
itk::SparseFieldLayerIterator::GetPointer
TNodeType * GetPointer()
Definition: itkSparseFieldLayer.h:128
itk::SparseFieldLayerIterator::operator++
SparseFieldLayerIterator & operator++()
Definition: itkSparseFieldLayer.h:134
itk::ConstSparseFieldLayerIterator::ConstSparseFieldLayerIterator
ConstSparseFieldLayerIterator(TNodeType *p)
Definition: itkSparseFieldLayer.h:89
itk::SparseFieldLayerIterator::operator*
TNodeType & operator*()
Definition: itkSparseFieldLayer.h:116
itk::SparseFieldLayerIterator::operator->
TNodeType * operator->()
Definition: itkSparseFieldLayer.h:122
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:148
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:178
itk::SparseFieldLayer::Empty
bool Empty() const
Definition: itkSparseFieldLayer.h:295
itk::SparseFieldLayer::NodeType
TNodeType NodeType
Definition: itkSparseFieldLayer.h:196
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::SparseFieldLayer::Front
const NodeType * Front() const
Definition: itkSparseFieldLayer.h:227
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:102
itk::ConstSparseFieldLayerIterator::operator->
const TNodeType * operator->() const
Definition: itkSparseFieldLayer.h:47
itkObject.h
itk::ConstSparseFieldLayerIterator::m_Pointer
TNodeType * m_Pointer
Definition: itkSparseFieldLayer.h:94
itk::ConstSparseFieldLayerIterator::ConstSparseFieldLayerIterator
ConstSparseFieldLayerIterator()
Definition: itkSparseFieldLayer.h:87
itk::SparseFieldLayer::RegionType::first
ConstIterator first
Definition: itkSparseFieldLayer.h:211
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:273
itk::SparseFieldLayer::ValueType
NodeType ValueType
Definition: itkSparseFieldLayer.h:200
itk::SparseFieldLayer::Begin
Iterator Begin()
Definition: itkSparseFieldLayer.h:265
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:61
itk::ConstSparseFieldLayerIterator::operator--
ConstSparseFieldLayerIterator & operator--()
Definition: itkSparseFieldLayer.h:81
itk::SparseFieldLayer::Front
NodeType * Front()
Definition: itkSparseFieldLayer.h:220
itk::SparseFieldLayer::End
ConstIterator End() const
Definition: itkSparseFieldLayer.h:287
itk::SparseFieldLayer::PushFront
void PushFront(NodeType *n)
Definition: itkSparseFieldLayer.h:244
itk::SparseFieldLayerIterator::operator--
SparseFieldLayerIterator & operator--()
Definition: itkSparseFieldLayer.h:141
itk::SparseFieldLayer::PopFront
void PopFront()
Definition: itkSparseFieldLayer.h:234
itk::SparseFieldLayer::RegionType::last
ConstIterator last
Definition: itkSparseFieldLayer.h:212