ITK  4.13.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 = ITK_NULLPTR; }
74 
76  { m_Pointer = p; }
77 
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:
161 
163  itkNewMacro(Self);
164 
166  itkTypeMacro(SparseFieldLayer, Object);
167 
169  typedef TNodeType NodeType;
170 
174 
177 
180 
182  struct RegionType {
184  ConstIterator last; // this is one past the actual last element
185  };
186 
187  typedef std::vector< RegionType > RegionListType;
188 
192  { return m_HeadNode->Next; }
193 
195  const NodeType * Front() const
196  { return m_HeadNode->Next; }
197 
199  void PopFront()
200  {
201  m_HeadNode->Next = m_HeadNode->Next->Next;
202  m_HeadNode->Next->Previous = m_HeadNode;
203  m_Size -= 1;
204  }
205 
208  {
209  n->Next = m_HeadNode->Next;
210  n->Previous = m_HeadNode;
211  m_HeadNode->Next->Previous = n;
212  m_HeadNode->Next = n;
213  m_Size += 1;
214  }
215 
217  void Unlink(NodeType *n)
218  {
219  n->Previous->Next = n->Next;
220  n->Next->Previous = n->Previous;
221  m_Size -= 1;
222  }
223 
226  { return Iterator(m_HeadNode->Next); }
227 
231  { return ConstIterator(m_HeadNode->Next); }
232 
235  { return Iterator(m_HeadNode); }
236 
239  { return ConstIterator(m_HeadNode); }
240 
243  bool Empty() const
244  {
245  if ( m_HeadNode->Next == m_HeadNode ) { return true; }
246  else { return false; }
247  }
249 
252  unsigned int Size() const;
253 
256  RegionListType SplitRegions(int num) const;
257 
258 protected:
260  ~SparseFieldLayer() ITK_OVERRIDE;
261  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
262 
263 private:
264  ITK_DISALLOW_COPY_AND_ASSIGN(SparseFieldLayer);
265 
268  NodeType * m_HeadNode;
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++()
void PushFront(NodeType *n)
bool operator!=(const ConstSparseFieldLayerIterator o) const
Represent the size (bounds) of a n-dimensional image.
Definition: itkSize.h:52
const TNodeType * GetPointer() const
ConstIterator Begin() const
SparseFieldLayerIterator< NodeType > Iterator
const TNodeType * operator->() const
ConstSparseFieldLayerIterator< NodeType > ConstIterator
const TNodeType & operator*() const
The non-const version of the ConstSparseFieldLayerIterator.
void Unlink(NodeType *n)
ConstSparseFieldLayerIterator< TNodeType > Superclass
SmartPointer< const Self > ConstPointer
Used to iterate through an itkSparseFieldLayer.
SmartPointer< Self > Pointer
ConstSparseFieldLayerIterator & operator--()
std::vector< RegionType > RegionListType
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:59
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