ITK  4.2.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< class TNodeType >
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 = 0; }
74 
76  { m_Pointer = p; }
77 
79 protected:
80  TNodeType *m_Pointer;
81 };
82 
87 template< class TNodeType >
89  public ConstSparseFieldLayerIterator< TNodeType >
90 {
91 public:
93 
95  {}
96 
98  {}
99 
100  TNodeType & operator*()
101  { return *this->m_Pointer; }
102 
103  TNodeType * operator->()
104  { return this->m_Pointer; }
105 
106  TNodeType * GetPointer()
107  { return this->m_Pointer; }
108 
110  {
111  this->m_Pointer = this->m_Pointer->Next;
112  return *this;
113  }
114 
116  {
117  this->m_Pointer = this->m_Pointer->Previous;
118  return *this;
119  }
120 
122  {
123  this->m_Pointer = const_cast< TNodeType * >( sc.GetPointer() );
124  return *this;
125  }
126 };
127 
150 template< class TNodeType >
151 class ITK_EXPORT SparseFieldLayer:
152  public Object
153 {
154 public:
160 
162  itkNewMacro(Self);
163 
165  itkTypeMacro(SparseFieldLayer, Object);
166 
168  typedef TNodeType NodeType;
169 
173 
176 
179 
181  struct RegionType {
183  ConstIterator last; // this is one past the actual last element
184  };
185 
186  typedef std::vector< RegionType > RegionListType;
187 
190  NodeType * Front()
191  { return m_HeadNode->Next; }
192 
194  const NodeType * Front() const
195  { return m_HeadNode->Next; }
196 
198  void PopFront()
199  {
200  m_HeadNode->Next = m_HeadNode->Next->Next;
201  m_HeadNode->Next->Previous = m_HeadNode;
202  m_Size -= 1;
203  }
204 
206  void PushFront(NodeType *n)
207  {
208  n->Next = m_HeadNode->Next;
209  n->Previous = m_HeadNode;
210  m_HeadNode->Next->Previous = n;
211  m_HeadNode->Next = n;
212  m_Size += 1;
213  }
214 
216  void Unlink(NodeType *n)
217  {
218  n->Previous->Next = n->Next;
219  n->Next->Previous = n->Previous;
220  m_Size -= 1;
221  }
222 
224  Iterator Begin()
225  { return Iterator(m_HeadNode->Next); }
226 
229  ConstIterator Begin() const
230  { return ConstIterator(m_HeadNode->Next); }
231 
233  Iterator End()
234  { return Iterator(m_HeadNode); }
235 
237  ConstIterator End() const
238  { return ConstIterator(m_HeadNode); }
239 
242  bool Empty() const
243  {
244  if ( m_HeadNode->Next == m_HeadNode ) { return true; }
245  else { return false; }
246  }
248 
251  unsigned int Size() const;
252 
255  RegionListType SplitRegions(int num) const;
256 
257 protected:
259  ~SparseFieldLayer();
260  virtual void PrintSelf(std::ostream & os, Indent indent) const;
261 
262 private:
263  SparseFieldLayer(const Self &); //purposely not implemented
264  void operator=(const Self &); //purposely not implemented
265 
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
278