ITK  4.2.0
Insight Segmentation and Registration Toolkit
itkConstShapedNeighborhoodIterator.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 __itkConstShapedNeighborhoodIterator_h
19 #define __itkConstShapedNeighborhoodIterator_h
20 
21 #include <vector>
22 #include <list>
24 
25 namespace itk
26 {
70 template< class TImage, class TBoundaryCondition =
71  ZeroFluxNeumannBoundaryCondition< TImage > >
73  private NeighborhoodIterator< TImage, TBoundaryCondition >
74 {
75 public:
76 
78  typedef typename TImage::InternalPixelType InternalPixelType;
79  typedef typename TImage::PixelType PixelType;
80 
82  itkStaticConstMacro(Dimension, unsigned int, TImage::ImageDimension);
83 
87 
91  typedef typename Superclass::RadiusType RadiusType;
92  typedef typename Superclass::SizeType SizeType;
94 
96  typedef TImage ImageType;
97  typedef typename TImage::RegionType RegionType;
103 
105 
108  typedef std::list< NeighborIndexType > IndexListType;
109 
110  typedef typename IndexListType::iterator IndexListIterator;
111  typedef typename IndexListType::const_iterator IndexListConstIterator;
112 
114  typedef TBoundaryCondition BoundaryConditionType;
115 
118 
120  struct ConstIterator {
121  ConstIterator() { m_NeighborhoodIterator = 0; }
123  {
124  m_NeighborhoodIterator = s;
125  this->GoToBegin();
126  }
128 
129  virtual ~ConstIterator() {}
130  const ConstIterator & operator=(const ConstIterator & o)
131  {
132  m_NeighborhoodIterator = o.m_NeighborhoodIterator;
133  m_ListIterator = o.m_ListIterator;
134  return *this;
135  }
136 
138  {
139  m_NeighborhoodIterator = o.m_NeighborhoodIterator;
140  m_ListIterator = o.m_ListIterator;
141  }
142 
143  void operator++(int)
144  { m_ListIterator++; }
145 
146  void operator--(int)
147  { m_ListIterator--; }
148 
149  const ConstIterator & operator++()
150  {
151  m_ListIterator++;
152  return *this;
153  }
154 
155  const ConstIterator & operator--()
156  {
157  m_ListIterator--;
158  return *this;
159  }
160 
161  bool operator!=(const ConstIterator & o) const
162  { return m_ListIterator != o.m_ListIterator; }
163  bool operator==(const ConstIterator & o) const
164  { return m_ListIterator == o.m_ListIterator; }
165 
166  bool IsAtEnd() const
167  {
168  if ( m_ListIterator == m_NeighborhoodIterator->GetActiveIndexList().end() )
169  {
170  return true;
171  }
172  else
173  {
174  return false;
175  }
176  }
177 
178  void GoToBegin()
179  {
180  m_ListIterator = m_NeighborhoodIterator->GetActiveIndexList().begin();
181  }
182 
183  void GoToEnd()
184  {
185  m_ListIterator = m_NeighborhoodIterator->GetActiveIndexList().end();
186  }
187 
188  PixelType Get() const
189  { return m_NeighborhoodIterator->GetPixel(*m_ListIterator); }
190 
191  OffsetType GetNeighborhoodOffset() const
192  { return m_NeighborhoodIterator->GetOffset(*m_ListIterator); }
193 
194  typename IndexListType::value_type GetNeighborhoodIndex() const
195  { return *m_ListIterator; }
196 protected:
197 
199 
200  typename IndexListType::const_iterator m_ListIterator;
201 
202  void ProtectedSet(const PixelType & v) const
203  { m_NeighborhoodIterator->SetPixel(*m_ListIterator, v); }
204  };
205 
208  const ConstIterator & Begin() const
209  { return m_ConstBeginIterator; }
210 
213  const ConstIterator & End() const
214  { return m_ConstEndIterator; }
215 
218  {
219  m_ConstBeginIterator = ConstIterator(this);
220  m_ConstEndIterator = ConstIterator(this);
221  m_ConstEndIterator.GoToEnd();
222  m_CenterIsActive = false;
223  }
225 
228 
232  const ImageType *ptr,
233  const RegionType & region):
234  Superclass (radius, const_cast< ImageType * >( ptr ), region)
235  {
236  m_ConstBeginIterator = ConstIterator(this);
237  m_ConstEndIterator = ConstIterator(this);
238  m_ConstEndIterator.GoToEnd();
239  m_CenterIsActive = false;
240  }
242 
243  // Expose the following methods from the superclass. This is a
244  // restricted subset of the methods available for
245  // ConstNeighborhoodIterator.
246  using Superclass::GetImagePointer;
247  using Superclass::GetRadius;
248  using Superclass::GetIndex;
249  using Superclass::GetNeighborhoodIndex;
250  using Superclass::GetCenterNeighborhoodIndex;
251  using Superclass::GetRegion;
252  using Superclass::GetBeginIndex;
253  using Superclass::GoToBegin;
254  using Superclass::GoToEnd;
255  using Superclass::IsAtBegin;
256  using Superclass::IsAtEnd;
257  using Superclass::GetOffset;
258  using Superclass::operator==;
259  using Superclass::operator!=;
260  using Superclass::operator<;
261  using Superclass::operator>;
262  using Superclass::operator>=;
263  using Superclass::operator<=;
264  using Superclass::operator[];
265  using Superclass::GetElement;
266  using Superclass::SetLocation;
267  using Superclass::GetCenterPointer;
268  using Superclass::GetCenterPixel;
269  using Superclass::OverrideBoundaryCondition;
270  using Superclass::ResetBoundaryCondition;
271  using Superclass::GetBoundaryCondition;
272  using Superclass::GetNeedToUseBoundaryCondition;
273  using Superclass::SetNeedToUseBoundaryCondition;
274  using Superclass::NeedToUseBoundaryConditionOn;
275  using Superclass::NeedToUseBoundaryConditionOff;
276  using Superclass::Print;
277  using Superclass::operator-;
278  using Superclass::GetPixel;
279 
281  Self & operator=(const Self & orig)
282  {
283  Superclass::operator=(orig);
284  m_ActiveIndexList = orig.m_ActiveIndexList;
285  m_CenterIsActive = orig.m_CenterIsActive;
287 
288  // Reset begin and end pointers
289  m_ConstBeginIterator.GoToBegin();
290  m_ConstEndIterator.GoToBegin();
291  return *this;
292  }
293 
295  virtual void PrintSelf(std::ostream &, Indent) const;
296 
300  virtual void ActivateOffset(const OffsetType & off)
301  { this->ActivateIndex( Superclass::GetNeighborhoodIndex(off) ); }
302  virtual void DeactivateOffset(const OffsetType & off)
303  { this->DeactivateIndex( Superclass::GetNeighborhoodIndex(off) ); }
305 
307  virtual void ClearActiveList()
308  {
309  m_ActiveIndexList.clear();
310  m_ConstBeginIterator.GoToBegin();
311  m_ConstEndIterator.GoToEnd();
312  m_CenterIsActive = false;
313  }
315 
317  const IndexListType & GetActiveIndexList() const
318  { return m_ActiveIndexList; }
319 
321  typename IndexListType::size_type GetActiveIndexListSize() const
322  { return m_ActiveIndexList.size(); }
323 
327  void CreateActiveListFromNeighborhood(const NeighborhoodType &);
328 
331  Self & operator++();
332 
335  Self & operator--();
336 
340  Self & operator+=(const OffsetType &);
341 
345  Self & operator-=(const OffsetType &);
346 
347 protected:
348  using Superclass::SetPixel;
349  using Superclass::SetCenterPixel;
352  // purposely not implemented
353 
354  friend struct ConstIterator;
355 
358  // Superclass::SetPixel;
359  // Superclass::SetCenterPixel;
360 
366  virtual void ActivateIndex( NeighborIndexType );
367 
368  virtual void DeactivateIndex( NeighborIndexType );
369 
374 };
375 } // namespace itk
376 
377 #ifndef ITK_MANUAL_INSTANTIATION
378 #include "itkConstShapedNeighborhoodIterator.hxx"
379 #endif
380 
381 #endif
382