Orfeo Toolbox  4.0
itkConstNeighborhoodIterator.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 __itkConstNeighborhoodIterator_h
19 #define __itkConstNeighborhoodIterator_h
20 
21 #include <vector>
22 #include <cstring>
23 #include <iostream>
24 #include "itkImage.h"
25 #include "itkNeighborhood.h"
26 #include "itkMacro.h"
28 
29 namespace itk
30 {
49 template< typename TImage, typename TBoundaryCondition =
50  ZeroFluxNeumannBoundaryCondition< TImage > >
52  public Neighborhood< typename TImage::InternalPixelType *,
53  TImage::ImageDimension >
54 {
55 public:
57  typedef typename TImage::InternalPixelType InternalPixelType;
58  typedef typename TImage::PixelType PixelType;
59 
61  itkStaticConstMacro(Dimension, unsigned int, TImage::ImageDimension);
62 
64  typedef unsigned int DimensionValueType;
65 
69  itkGetStaticConstMacro(Dimension) > Superclass;
70 
74  typedef typename Superclass::SizeType SizeType;
75  typedef typename Superclass::Iterator Iterator;
77 
79  typedef TImage ImageType;
80  typedef typename TImage::RegionType RegionType;
84 
87 
91  typedef typename ImageType::NeighborhoodAccessorFunctorType
93 
95  typedef TBoundaryCondition BoundaryConditionType;
96 
101 
104 
107 
110 
114  const ImageType *ptr,
115  const RegionType & region)
116  {
117  this->Initialize(radius, ptr, region);
118  for ( unsigned int i = 0; i < Dimension; i++ )
119  { m_InBounds[i] = false; }
120  this->ResetBoundaryCondition();
121  m_NeighborhoodAccessorFunctor = ptr->GetNeighborhoodAccessor();
122  m_NeighborhoodAccessorFunctor.SetBegin( ptr->GetBufferPointer() );
123  }
124 
126  Self & operator=(const Self & orig);
127 
129  virtual void PrintSelf(std::ostream &, Indent) const;
130 
134 
137  { return m_Bound; }
138 
142  { return m_Bound[n]; }
143 
146  { return ( this->operator[]( ( this->Size() ) >> 1 ) ); }
147 
151  { return m_NeighborhoodAccessorFunctor.Get( this->GetCenterPointer() ); }
152 
154  const ImageType * GetImagePointer(void) const
155  { return m_ConstImage; }
156 
159  virtual IndexType GetIndex(void) const
160  { return m_Loop; }
161 
164  virtual NeighborhoodType GetNeighborhood() const;
165 
168  {
170  {
171  return ( m_NeighborhoodAccessorFunctor.Get( this->operator[](i) ) );
172  }
173  bool inbounds;
174  return this->GetPixel(i, inbounds);
175  }
176 
182  virtual PixelType GetPixel(NeighborIndexType i, bool & IsInBounds) const;
183 
186  virtual PixelType GetPixel(const OffsetType & o) const
187  {
188  bool inbounds;
189 
190  return ( this->GetPixel(this->GetNeighborhoodIndex(o), inbounds) );
191  }
192 
198  virtual PixelType GetPixel(const OffsetType & o,
199  bool & IsInBounds) const
200  { return ( this->GetPixel(this->GetNeighborhoodIndex(o), IsInBounds) ); }
201 
205  virtual PixelType GetNext(const unsigned axis, NeighborIndexType i) const
206  {
207  return ( this->GetPixel( this->GetCenterNeighborhoodIndex()
208  + ( i * this->GetStride(axis) ) ) );
209  }
210 
214  virtual PixelType GetNext(const unsigned axis) const
215  {
216  return ( this->GetPixel( this->GetCenterNeighborhoodIndex()
217  + this->GetStride(axis) ) );
218  }
219 
223  virtual PixelType GetPrevious(const unsigned axis, NeighborIndexType i) const
224  {
225  return ( this->GetPixel( this->GetCenterNeighborhoodIndex()
226  - ( i * this->GetStride(axis) ) ) );
227  }
228 
232  virtual PixelType GetPrevious(const unsigned axis) const
233  {
234  return ( this->GetPixel( this->GetCenterNeighborhoodIndex()
235  - this->GetStride(axis) ) );
236  }
237 
240  virtual IndexType GetIndex(const OffsetType & o) const
241  { return ( this->GetIndex() + o ); }
242 
246  { return ( this->GetIndex() + this->GetOffset(i) ); }
247 
250  { return m_Region; }
251 
255  { return m_BeginIndex; }
256 
260 
263  { return m_WrapOffset; }
264 
271  { return m_WrapOffset[n]; }
272 
276  virtual void GoToBegin();
277 
280  virtual void GoToEnd();
281 
284  virtual void Initialize(const SizeType & radius, const ImageType *ptr,
285  const RegionType & region);
286 
289  virtual bool IsAtBegin() const
290  { return ( this->GetCenterPointer() == m_Begin ); }
291 
294  virtual bool IsAtEnd() const
295  {
296  if ( this->GetCenterPointer() > m_End )
297  {
298  ExceptionObject e(__FILE__, __LINE__);
299  std::ostringstream msg;
300  msg << "In method IsAtEnd, CenterPointer = " << this->GetCenterPointer()
301  << " is greater than End = " << m_End
302  << std::endl
303  << " " << *this;
304  e.SetDescription( msg.str().c_str() );
305  throw e;
306  }
307  return ( this->GetCenterPointer() == m_End );
308  }
309 
314  Self & operator++();
315 
320  Self & operator--();
321 
325  bool operator==(const Self & it) const
326  { return it.GetCenterPointer() == this->GetCenterPointer(); }
327 
331  bool operator!=(const Self & it) const
332  { return it.GetCenterPointer() != this->GetCenterPointer(); }
333 
337  bool operator<(const Self & it) const
338  { return this->GetCenterPointer() < it.GetCenterPointer(); }
339 
343  bool operator<=(const Self & it) const
344  { return this->GetCenterPointer() <= it.GetCenterPointer(); }
345 
349  bool operator>(const Self & it) const
350  { return this->GetCenterPointer() > it.GetCenterPointer(); }
351 
355  bool operator>=(const Self & it) const
356  { return this->GetCenterPointer() >= it.GetCenterPointer(); }
357 
362  void SetLocation(const IndexType & position)
363  {
364  this->SetLoop(position);
365  this->SetPixelPointers(position);
366  }
367 
371  Self & operator+=(const OffsetType &);
372 
376  Self & operator-=(const OffsetType &);
377 
380  { return m_Loop - b.m_Loop; }
381 
385  bool InBounds() const;
386 
398  bool IndexInBounds(NeighborIndexType n, OffsetType & internalIndex, OffsetType & offset ) const;
399 
405  virtual void OverrideBoundaryCondition(const
407  { m_BoundaryCondition = i; }
408 
411  virtual void ResetBoundaryCondition()
413 
415  void SetBoundaryCondition(const TBoundaryCondition & c)
417 
420  { return m_BoundaryCondition; }
421 
424  {
425  this->SetNeedToUseBoundaryCondition(true);
426  }
427 
429  {
430  this->SetNeedToUseBoundaryCondition(false);
431  }
432 
434  {
436  }
437 
439  {
441  }
442 
444  virtual void SetRegion(const RegionType & region);
445 
446 protected:
447 
450  virtual void SetLoop(const IndexType & p)
451  { m_Loop = p; m_IsInBoundsValid = false; }
452 
456  virtual void SetBound(const SizeType &);
457 
462  virtual void SetPixelPointers(const IndexType &);
463 
466  virtual void SetBeginIndex(const IndexType & start)
467  { m_BeginIndex = start; }
468 
471  virtual void SetEndIndex();
472 
476 
479 
482 
484  typename ImageType::ConstWeakPointer m_ConstImage;
485 
488 
492 
495 
498 
505 
511 
514  mutable bool m_InBounds[Dimension];
515 
517  mutable bool m_IsInBounds;
518 
522  mutable bool m_IsInBoundsValid;
523 
526 
529 
531  TBoundaryCondition m_InternalBoundaryCondition;
532 
535 
538 };
539 
540 template< typename TImage >
544  ::OffsetType & ind)
545 {
547  ret = it;
548  ret += ind;
549  return ret;
550 }
551 
552 template< typename TImage >
553 inline ConstNeighborhoodIterator< TImage >
555  ::OffsetType & ind,
557 { return ( it + ind ); }
558 
559 template< typename TImage >
560 inline ConstNeighborhoodIterator< TImage >
563  ::OffsetType & ind)
564 {
566  ret = it;
567  ret -= ind;
568  return ret;
569 }
570 } // namespace itk
571 
572 #ifndef ITK_MANUAL_INSTANTIATION
574 #endif
575 
576 #endif

Generated at Sat Mar 8 2014 14:29:15 for Orfeo Toolbox with doxygen 1.8.3.1