ITK  5.2.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  * http://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 
25 namespace itk
26 {
35 template <typename TNodeType>
36 class ITK_TEMPLATE_EXPORT ConstSparseFieldLayerIterator
37 {
38 public:
39  const TNodeType & operator*() const { return *m_Pointer; }
40 
41  const TNodeType * operator->() const { return m_Pointer; }
42 
43  const TNodeType *
44  GetPointer() const
45  {
46  return m_Pointer;
47  }
48 
49  bool
51  {
52  if (m_Pointer == o.m_Pointer)
53  {
54  return true;
55  }
56  else
57  {
58  return false;
59  }
60  }
61 
62  bool
64  {
65  if (m_Pointer != o.m_Pointer)
66  {
67  return true;
68  }
69  else
70  {
71  return false;
72  }
73  }
74 
77  {
78  m_Pointer = m_Pointer->Next;
79  return *this;
80  }
81 
84  {
85  m_Pointer = m_Pointer->Previous;
86  return *this;
87  }
88 
89  ConstSparseFieldLayerIterator() { m_Pointer = nullptr; }
90 
91  ConstSparseFieldLayerIterator(TNodeType * p) { m_Pointer = p; }
92 
93  ~ConstSparseFieldLayerIterator() = default;
94 
95 protected:
96  TNodeType * m_Pointer;
97 };
98 
103 template <typename TNodeType>
104 class ITK_TEMPLATE_EXPORT SparseFieldLayerIterator : public ConstSparseFieldLayerIterator<TNodeType>
105 {
106 public:
108 
110  : Superclass()
111  {}
112 
114  : Superclass(p)
115  {}
116 
117  TNodeType & operator*() { return *this->m_Pointer; }
118 
119  TNodeType * operator->() { return this->m_Pointer; }
120 
121  TNodeType *
123  {
124  return this->m_Pointer;
125  }
126 
129  {
130  this->m_Pointer = this->m_Pointer->Next;
131  return *this;
132  }
133 
136  {
137  this->m_Pointer = this->m_Pointer->Previous;
138  return *this;
139  }
140 
143  {
144  this->m_Pointer = const_cast<TNodeType *>(sc.GetPointer());
145  return *this;
146  }
147 };
148 
171 template <typename TNodeType>
172 class ITK_TEMPLATE_EXPORT SparseFieldLayer : public Object
173 {
174 public:
175  ITK_DISALLOW_COPY_AND_MOVE(SparseFieldLayer);
176 
182 
184  itkNewMacro(Self);
185 
187  itkTypeMacro(SparseFieldLayer, Object);
188 
190  using NodeType = TNodeType;
191 
195 
198 
201 
203  struct RegionType
204  {
206  ConstIterator last; // this is one past the actual last element
207  };
208 
209  using RegionListType = std::vector<RegionType>;
210 
213  NodeType *
215  {
216  return m_HeadNode->Next;
217  }
218 
220  const NodeType *
221  Front() const
222  {
223  return m_HeadNode->Next;
224  }
225 
227  void
229  {
230  m_HeadNode->Next = m_HeadNode->Next->Next;
231  m_HeadNode->Next->Previous = m_HeadNode;
232  m_Size -= 1;
233  }
234 
236  void
238  {
239  n->Next = m_HeadNode->Next;
240  n->Previous = m_HeadNode;
241  m_HeadNode->Next->Previous = n;
242  m_HeadNode->Next = n;
243  m_Size += 1;
244  }
245 
247  void
249  {
250  n->Previous->Next = n->Next;
251  n->Next->Previous = n->Previous;
252  m_Size -= 1;
253  }
254 
256  Iterator
258  {
259  return Iterator(m_HeadNode->Next);
260  }
261 
264  ConstIterator
265  Begin() const
266  {
267  return ConstIterator(m_HeadNode->Next);
268  }
269 
271  Iterator
272  End()
273  {
274  return Iterator(m_HeadNode);
275  }
276 
278  ConstIterator
279  End() const
280  {
281  return ConstIterator(m_HeadNode);
282  }
283 
286  bool
287  Empty() const
288  {
289  if (m_HeadNode->Next == m_HeadNode)
290  {
291  return true;
292  }
293  else
294  {
295  return false;
296  }
297  }
299 
302  unsigned int
303  Size() const;
304 
307  RegionListType
308  SplitRegions(int num) const;
309 
310 protected:
312  ~SparseFieldLayer() override;
313  void
314  PrintSelf(std::ostream & os, Indent indent) const override;
315 
316 private:
320  unsigned int m_Size;
321 };
322 } // end namespace itk
323 
324 #ifndef ITK_MANUAL_INSTANTIATION
325 # include "itkSparseFieldLayer.hxx"
326 #endif
327 
328 #endif
itk::SparseFieldLayerIterator::SparseFieldLayerIterator
SparseFieldLayerIterator()
Definition: itkSparseFieldLayer.h:109
itkObjectFactory.h
itk::SparseFieldLayer::RegionListType
std::vector< RegionType > RegionListType
Definition: itkSparseFieldLayer.h:209
itk::ConstSparseFieldLayerIterator::operator++
ConstSparseFieldLayerIterator & operator++()
Definition: itkSparseFieldLayer.h:76
itk::SparseFieldLayer::m_HeadNode
NodeType * m_HeadNode
Definition: itkSparseFieldLayer.h:319
itk::SparseFieldLayer::End
Iterator End()
Definition: itkSparseFieldLayer.h:272
itk::SparseFieldLayer::RegionType
Definition: itkSparseFieldLayer.h:203
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:248
itk::SparseFieldLayerIterator::SparseFieldLayerIterator
SparseFieldLayerIterator(TNodeType *p)
Definition: itkSparseFieldLayer.h:113
itk::SparseFieldLayerIterator::GetPointer
TNodeType * GetPointer()
Definition: itkSparseFieldLayer.h:122
itk::SparseFieldLayerIterator::operator++
SparseFieldLayerIterator & operator++()
Definition: itkSparseFieldLayer.h:128
itk::ConstSparseFieldLayerIterator::ConstSparseFieldLayerIterator
ConstSparseFieldLayerIterator(TNodeType *p)
Definition: itkSparseFieldLayer.h:91
itk::SparseFieldLayerIterator::operator*
TNodeType & operator*()
Definition: itkSparseFieldLayer.h:117
itk::SparseFieldLayerIterator::operator->
TNodeType * operator->()
Definition: itkSparseFieldLayer.h:119
itk::ConstSparseFieldLayerIterator::operator!=
bool operator!=(const ConstSparseFieldLayerIterator o) const
Definition: itkSparseFieldLayer.h:63
itk::SmartPointer< Self >
itk::ConstSparseFieldLayerIterator::operator*
const TNodeType & operator*() const
Definition: itkSparseFieldLayer.h:39
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ConstSparseFieldLayerIterator
Used to iterate through an itkSparseFieldLayer.
Definition: itkSparseFieldLayer.h:36
itk::SparseFieldLayerIterator::operator=
SparseFieldLayerIterator & operator=(Superclass &sc)
Definition: itkSparseFieldLayer.h:142
itk::ConstSparseFieldLayerIterator::GetPointer
const TNodeType * GetPointer() const
Definition: itkSparseFieldLayer.h:44
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:172
itk::SparseFieldLayer::Empty
bool Empty() const
Definition: itkSparseFieldLayer.h:287
itk::SparseFieldLayer::m_Size
unsigned int m_Size
Definition: itkSparseFieldLayer.h:320
itk::SparseFieldLayer::NodeType
TNodeType NodeType
Definition: itkSparseFieldLayer.h:190
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::SparseFieldLayer::Front
const NodeType * Front() const
Definition: itkSparseFieldLayer.h:221
itk::ConstSparseFieldLayerIterator::operator==
bool operator==(const ConstSparseFieldLayerIterator o) const
Definition: itkSparseFieldLayer.h:50
itk::SparseFieldLayerIterator
The non-const version of the ConstSparseFieldLayerIterator.
Definition: itkSparseFieldLayer.h:104
itk::ConstSparseFieldLayerIterator::operator->
const TNodeType * operator->() const
Definition: itkSparseFieldLayer.h:41
itkObject.h
itk::ConstSparseFieldLayerIterator::m_Pointer
TNodeType * m_Pointer
Definition: itkSparseFieldLayer.h:96
itk::ConstSparseFieldLayerIterator::ConstSparseFieldLayerIterator
ConstSparseFieldLayerIterator()
Definition: itkSparseFieldLayer.h:89
itk::SparseFieldLayer::RegionType::first
ConstIterator first
Definition: itkSparseFieldLayer.h:205
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::SparseFieldLayer::Begin
ConstIterator Begin() const
Definition: itkSparseFieldLayer.h:265
itk::SparseFieldLayer::ValueType
NodeType ValueType
Definition: itkSparseFieldLayer.h:194
itk::SparseFieldLayer::Begin
Iterator Begin()
Definition: itkSparseFieldLayer.h:257
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itk::ConstSparseFieldLayerIterator::operator--
ConstSparseFieldLayerIterator & operator--()
Definition: itkSparseFieldLayer.h:83
itk::SparseFieldLayer::Front
NodeType * Front()
Definition: itkSparseFieldLayer.h:214
itk::SparseFieldLayer::End
ConstIterator End() const
Definition: itkSparseFieldLayer.h:279
itk::SparseFieldLayer::PushFront
void PushFront(NodeType *n)
Definition: itkSparseFieldLayer.h:237
itk::SparseFieldLayerIterator::operator--
SparseFieldLayerIterator & operator--()
Definition: itkSparseFieldLayer.h:135
itk::SparseFieldLayer::PopFront
void PopFront()
Definition: itkSparseFieldLayer.h:228
itk::SparseFieldLayer::RegionType::last
ConstIterator last
Definition: itkSparseFieldLayer.h:206