ITK  5.3.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  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(ConstSparseFieldLayerIterator);
63 
66  {
67  m_Pointer = m_Pointer->Next;
68  return *this;
69  }
70 
73  {
74  m_Pointer = m_Pointer->Previous;
75  return *this;
76  }
77 
78  ConstSparseFieldLayerIterator() { m_Pointer = nullptr; }
79 
80  ConstSparseFieldLayerIterator(TNodeType * p) { m_Pointer = p; }
81 
82  ~ConstSparseFieldLayerIterator() = default;
83 
84 protected:
85  TNodeType * m_Pointer;
86 };
87 
92 template <typename TNodeType>
93 class ITK_TEMPLATE_EXPORT SparseFieldLayerIterator : public ConstSparseFieldLayerIterator<TNodeType>
94 {
95 public:
97 
99  : Superclass()
100  {}
101 
103  : Superclass(p)
104  {}
105 
106  TNodeType & operator*() { return *this->m_Pointer; }
107 
108  TNodeType * operator->() { return this->m_Pointer; }
109 
110  TNodeType *
112  {
113  return this->m_Pointer;
114  }
115 
118  {
119  this->m_Pointer = this->m_Pointer->Next;
120  return *this;
121  }
122 
125  {
126  this->m_Pointer = this->m_Pointer->Previous;
127  return *this;
128  }
129 
132  {
133  this->m_Pointer = const_cast<TNodeType *>(sc.GetPointer());
134  return *this;
135  }
136 };
137 
160 template <typename TNodeType>
161 class ITK_TEMPLATE_EXPORT SparseFieldLayer : public Object
162 {
163 public:
164  ITK_DISALLOW_COPY_AND_MOVE(SparseFieldLayer);
165 
171 
173  itkNewMacro(Self);
174 
176  itkTypeMacro(SparseFieldLayer, Object);
177 
179  using NodeType = TNodeType;
180 
184 
187 
190 
192  struct RegionType
193  {
195  ConstIterator last; // this is one past the actual last element
196  };
197 
198  using RegionListType = std::vector<RegionType>;
199 
202  NodeType *
204  {
205  return m_HeadNode->Next;
206  }
207 
209  const NodeType *
210  Front() const
211  {
212  return m_HeadNode->Next;
213  }
214 
216  void
218  {
219  m_HeadNode->Next = m_HeadNode->Next->Next;
220  m_HeadNode->Next->Previous = m_HeadNode;
221  m_Size -= 1;
222  }
223 
225  void
227  {
228  n->Next = m_HeadNode->Next;
229  n->Previous = m_HeadNode;
230  m_HeadNode->Next->Previous = n;
231  m_HeadNode->Next = n;
232  m_Size += 1;
233  }
234 
236  void
238  {
239  n->Previous->Next = n->Next;
240  n->Next->Previous = n->Previous;
241  m_Size -= 1;
242  }
243 
245  Iterator
247  {
248  return Iterator(m_HeadNode->Next);
249  }
250 
253  ConstIterator
254  Begin() const
255  {
256  return ConstIterator(m_HeadNode->Next);
257  }
258 
260  Iterator
261  End()
262  {
263  return Iterator(m_HeadNode);
264  }
265 
267  ConstIterator
268  End() const
269  {
270  return ConstIterator(m_HeadNode);
271  }
272 
275  bool
276  Empty() const
277  {
278  if (m_HeadNode->Next == m_HeadNode)
279  {
280  return true;
281  }
282  else
283  {
284  return false;
285  }
286  }
288 
291  unsigned int
292  Size() const;
293 
296  RegionListType
297  SplitRegions(int num) const;
298 
299 protected:
301  ~SparseFieldLayer() override;
302  void
303  PrintSelf(std::ostream & os, Indent indent) const override;
304 
305 private:
309  unsigned int m_Size;
310 };
311 } // end namespace itk
312 
313 #ifndef ITK_MANUAL_INSTANTIATION
314 # include "itkSparseFieldLayer.hxx"
315 #endif
316 
317 #endif
itk::SparseFieldLayerIterator::SparseFieldLayerIterator
SparseFieldLayerIterator()
Definition: itkSparseFieldLayer.h:98
itkObjectFactory.h
itk::SparseFieldLayer::RegionListType
std::vector< RegionType > RegionListType
Definition: itkSparseFieldLayer.h:198
itk::ConstSparseFieldLayerIterator::operator++
ConstSparseFieldLayerIterator & operator++()
Definition: itkSparseFieldLayer.h:65
itk::SparseFieldLayer::m_HeadNode
NodeType * m_HeadNode
Definition: itkSparseFieldLayer.h:308
itk::SparseFieldLayer::End
Iterator End()
Definition: itkSparseFieldLayer.h:261
itk::SparseFieldLayer::RegionType
Definition: itkSparseFieldLayer.h:192
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:237
itk::SparseFieldLayerIterator::SparseFieldLayerIterator
SparseFieldLayerIterator(TNodeType *p)
Definition: itkSparseFieldLayer.h:102
itk::SparseFieldLayerIterator::GetPointer
TNodeType * GetPointer()
Definition: itkSparseFieldLayer.h:111
itk::SparseFieldLayerIterator::operator++
SparseFieldLayerIterator & operator++()
Definition: itkSparseFieldLayer.h:117
itk::ConstSparseFieldLayerIterator::ConstSparseFieldLayerIterator
ConstSparseFieldLayerIterator(TNodeType *p)
Definition: itkSparseFieldLayer.h:80
itk::SparseFieldLayerIterator::operator*
TNodeType & operator*()
Definition: itkSparseFieldLayer.h:106
itk::SparseFieldLayerIterator::operator->
TNodeType * operator->()
Definition: itkSparseFieldLayer.h:108
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:131
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:161
itk::SparseFieldLayer::Empty
bool Empty() const
Definition: itkSparseFieldLayer.h:276
itk::SparseFieldLayer::m_Size
unsigned int m_Size
Definition: itkSparseFieldLayer.h:309
itk::SparseFieldLayer::NodeType
TNodeType NodeType
Definition: itkSparseFieldLayer.h:179
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::SparseFieldLayer::Front
const NodeType * Front() const
Definition: itkSparseFieldLayer.h:210
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:93
itk::ConstSparseFieldLayerIterator::operator->
const TNodeType * operator->() const
Definition: itkSparseFieldLayer.h:41
itkObject.h
itk::ConstSparseFieldLayerIterator::m_Pointer
TNodeType * m_Pointer
Definition: itkSparseFieldLayer.h:85
itk::ConstSparseFieldLayerIterator::ConstSparseFieldLayerIterator
ConstSparseFieldLayerIterator()
Definition: itkSparseFieldLayer.h:78
itk::SparseFieldLayer::RegionType::first
ConstIterator first
Definition: itkSparseFieldLayer.h:194
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:254
itk::SparseFieldLayer::ValueType
NodeType ValueType
Definition: itkSparseFieldLayer.h:183
itk::SparseFieldLayer::Begin
Iterator Begin()
Definition: itkSparseFieldLayer.h:246
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itk::ConstSparseFieldLayerIterator::operator--
ConstSparseFieldLayerIterator & operator--()
Definition: itkSparseFieldLayer.h:72
itk::SparseFieldLayer::Front
NodeType * Front()
Definition: itkSparseFieldLayer.h:203
itk::SparseFieldLayer::End
ConstIterator End() const
Definition: itkSparseFieldLayer.h:268
itk::SparseFieldLayer::PushFront
void PushFront(NodeType *n)
Definition: itkSparseFieldLayer.h:226
itk::SparseFieldLayerIterator::operator--
SparseFieldLayerIterator & operator--()
Definition: itkSparseFieldLayer.h:124
itk::SparseFieldLayer::PopFront
void PopFront()
Definition: itkSparseFieldLayer.h:217
itk::SparseFieldLayer::RegionType::last
ConstIterator last
Definition: itkSparseFieldLayer.h:195