ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkSparseFieldLayer.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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
40  { return *m_Pointer; }
41 
42  const TNodeType * operator->() const
43  { return m_Pointer; }
44 
45  const TNodeType * GetPointer() const
46  { return m_Pointer; }
47 
49  {
50  if ( m_Pointer == o.m_Pointer ) { return true; }
51  else { return false; }
52  }
53 
55  {
56  if ( m_Pointer != o.m_Pointer ) { return true; }
57  else { return false; }
58  }
59 
61  {
62  m_Pointer = m_Pointer->Next;
63  return *this;
64  }
65 
67  {
68  m_Pointer = m_Pointer->Previous;
69  return *this;
70  }
71 
73  { m_Pointer = nullptr; }
74 
76  { m_Pointer = p; }
77 
78  ~ConstSparseFieldLayerIterator() = default;
79 
80 protected:
81  TNodeType *m_Pointer;
82 };
83 
88 template< typename TNodeType >
89 class ITK_TEMPLATE_EXPORT SparseFieldLayerIterator:
90  public ConstSparseFieldLayerIterator< TNodeType >
91 {
92 public:
94 
96  {}
97 
99  {}
100 
101  TNodeType & operator*()
102  { return *this->m_Pointer; }
103 
104  TNodeType * operator->()
105  { return this->m_Pointer; }
106 
107  TNodeType * GetPointer()
108  { return this->m_Pointer; }
109 
111  {
112  this->m_Pointer = this->m_Pointer->Next;
113  return *this;
114  }
115 
117  {
118  this->m_Pointer = this->m_Pointer->Previous;
119  return *this;
120  }
121 
123  {
124  this->m_Pointer = const_cast< TNodeType * >( sc.GetPointer() );
125  return *this;
126  }
127 };
128 
151 template< typename TNodeType >
152 class ITK_TEMPLATE_EXPORT SparseFieldLayer:
153  public Object
154 {
155 public:
156  ITK_DISALLOW_COPY_AND_ASSIGN(SparseFieldLayer);
157 
163 
165  itkNewMacro(Self);
166 
168  itkTypeMacro(SparseFieldLayer, Object);
169 
171  using NodeType = TNodeType;
172 
176 
179 
182 
184  struct RegionType {
186  ConstIterator last; // this is one past the actual last element
187  };
188 
189  using RegionListType = std::vector< RegionType >;
190 
194  { return m_HeadNode->Next; }
195 
197  const NodeType * Front() const
198  { return m_HeadNode->Next; }
199 
201  void PopFront()
202  {
203  m_HeadNode->Next = m_HeadNode->Next->Next;
204  m_HeadNode->Next->Previous = m_HeadNode;
205  m_Size -= 1;
206  }
207 
210  {
211  n->Next = m_HeadNode->Next;
212  n->Previous = m_HeadNode;
213  m_HeadNode->Next->Previous = n;
214  m_HeadNode->Next = n;
215  m_Size += 1;
216  }
217 
219  void Unlink(NodeType *n)
220  {
221  n->Previous->Next = n->Next;
222  n->Next->Previous = n->Previous;
223  m_Size -= 1;
224  }
225 
228  { return Iterator(m_HeadNode->Next); }
229 
233  { return ConstIterator(m_HeadNode->Next); }
234 
237  { return Iterator(m_HeadNode); }
238 
241  { return ConstIterator(m_HeadNode); }
242 
245  bool Empty() const
246  {
247  if ( m_HeadNode->Next == m_HeadNode ) { return true; }
248  else { return false; }
249  }
251 
254  unsigned int Size() const;
255 
258  RegionListType SplitRegions(int num) const;
259 
260 protected:
262  ~SparseFieldLayer() override;
263  void PrintSelf(std::ostream & os, Indent indent) const override;
264 
265 private:
269  unsigned int m_Size;
270 };
271 } // end namespace itk
272 
273 #ifndef ITK_MANUAL_INSTANTIATION
274 #include "itkSparseFieldLayer.hxx"
275 #endif
276 
277 #endif
SparseFieldLayerIterator & operator=(Superclass &sc)
Light weight base class for most itk classes.
SparseFieldLayerIterator & operator++()
std::vector< RegionType > RegionListType
void PushFront(NodeType *n)
bool operator!=(const ConstSparseFieldLayerIterator o) const
const TNodeType * GetPointer() const
ConstIterator Begin() const
const TNodeType * operator->() const
const TNodeType & operator*() const
The non-const version of the ConstSparseFieldLayerIterator.
void Unlink(NodeType *n)
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:68
Used to iterate through an itkSparseFieldLayer.
ConstSparseFieldLayerIterator & operator--()
Control indentation during Print() invocation.
Definition: itkIndent.h:49
ConstIterator End() const
const NodeType * Front() const
Base class for most ITK classes.
Definition: itkObject.h:60
A very simple linked list that is used to manage nodes in a layer of a sparse field level-set solver...
ConstSparseFieldLayerIterator & operator++()
SparseFieldLayerIterator & operator--()
bool operator==(const ConstSparseFieldLayerIterator o) const