Orfeo Toolbox  3.16
itkConstNeighborhoodIterator.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkConstNeighborhoodIterator.h,v $
5  Language: C++
6  Date: $Date: 2008-10-07 12:04:17 $
7  Version: $Revision: 1.38 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkConstNeighborhoodIterator_h
18 #define __itkConstNeighborhoodIterator_h
19 
20 #include <vector>
21 #include <string.h>
22 #include <iostream>
23 #include "itkImage.h"
24 #include "itkIndex.h"
25 #include "itkOffset.h"
26 #include "itkSize.h"
27 #include "itkImageRegion.h"
28 #include "itkMacro.h"
29 #include "itkNeighborhood.h"
31 #include "itkExceptionObject.h"
33 
34 namespace itk {
35 
50 template<class TImage, class TBoundaryCondition
51  = ZeroFluxNeumannBoundaryCondition<TImage> >
53  : public Neighborhood<ITK_TYPENAME TImage::InternalPixelType *,
54  ::itk::GetImageDimension<TImage>::ImageDimension>
55 {
56 public:
58  typedef typename TImage::InternalPixelType InternalPixelType;
59  typedef typename TImage::PixelType PixelType;
60 
62  itkStaticConstMacro(Dimension, unsigned int, TImage::ImageDimension);
63 
66  typedef Neighborhood<InternalPixelType *,
67  itkGetStaticConstMacro(Dimension)> Superclass;
68 
73  typedef typename Superclass::SizeType SizeType;
75  typedef typename Superclass::Iterator Iterator;
77 
79  typedef TImage ImageType;
80  typedef typename TImage::RegionType RegionType;
85 
89  typedef typename ImageType::NeighborhoodAccessorFunctorType
91 
93  typedef TBoundaryCondition BoundaryConditionType;
94 
97  typedef ImageBoundaryCondition<ImageType> const *
99 
102 
105 
108 
112  const ImageType * ptr,
113  const RegionType &region)
114  {
115  this->Initialize(radius, ptr, region);
116  for (unsigned int i=0; i < Dimension; i++)
117  { m_InBounds[i] = false; }
118  this->ResetBoundaryCondition();
119  m_NeighborhoodAccessorFunctor = ptr->GetNeighborhoodAccessor();
120  m_NeighborhoodAccessorFunctor.SetBegin( ptr->GetBufferPointer() );
121  }
122 
124  Self &operator=(const Self& orig);
125 
127  virtual void PrintSelf(std::ostream &, Indent) const;
128 
131  OffsetType ComputeInternalIndex(unsigned int n) const;
132 
134  IndexType GetBound() const
135  { return m_Bound; }
136 
139  long GetBound(unsigned int n) const
140  { return m_Bound[n]; }
141 
143  const InternalPixelType *GetCenterPointer() const
144  { return (this->operator[]((this->Size())>>1)); }
145 
148  PixelType GetCenterPixel() const
149  {return m_NeighborhoodAccessorFunctor.Get( this->GetCenterPointer() );}
150 
152  const ImageType * GetImagePointer(void) const
153  { return m_ConstImage; }
154 
157  virtual IndexType GetIndex(void) const
158  { return m_Loop; }
159 
162  virtual NeighborhoodType GetNeighborhood() const;
163 
165  virtual PixelType GetPixel(const unsigned i) const
166  {
167  if( !m_NeedToUseBoundaryCondition )
168  {
169  return ( m_NeighborhoodAccessorFunctor.Get( this->operator[]( i ) ) );
170  }
171  bool inbounds;
172  return this->GetPixel( i, inbounds );
173  }
174 
180  virtual PixelType GetPixel(const unsigned i, bool& IsInBounds) const;
181 
184  virtual PixelType GetPixel(const OffsetType &o) const
185  {
186  bool inbounds;
187  return (this->GetPixel(this->GetNeighborhoodIndex(o), inbounds));
188  }
189 
195  virtual PixelType GetPixel(const OffsetType &o,
196  bool& IsInBounds) const
197  {return (this->GetPixel(this->GetNeighborhoodIndex(o), IsInBounds)); }
198 
202  virtual PixelType GetNext(const unsigned axis, const unsigned i) const
203  { return (this->GetPixel(this->GetCenterNeighborhoodIndex()
204  + (i * this->GetStride(axis)))); }
205 
209  virtual PixelType GetNext(const unsigned axis) const
210  { return (this->GetPixel(this->GetCenterNeighborhoodIndex()
211  + this->GetStride(axis))); }
212 
216  virtual PixelType GetPrevious(const unsigned axis, const unsigned i) const
217  { return (this->GetPixel(this->GetCenterNeighborhoodIndex()
218  - (i * this->GetStride(axis)))); }
219 
223  virtual PixelType GetPrevious(const unsigned axis) const
224  { return (this->GetPixel(this->GetCenterNeighborhoodIndex()
225  - this->GetStride(axis))); }
226 
229  virtual IndexType GetIndex(const OffsetType &o) const
230  { return (this->GetIndex() + o); }
231 
234  virtual IndexType GetIndex(const unsigned i) const
235  { return (this->GetIndex() + this->GetOffset(i)); }
236 
238  RegionType GetRegion() const
239  { return m_Region; }
240 
243  IndexType GetBeginIndex() const
244  { return m_BeginIndex; }
245 
248  RegionType GetBoundingBoxAsImageRegion() const;
249 
251  OffsetType GetWrapOffset() const
252  { return m_WrapOffset; }
253 
259  OffsetValueType GetWrapOffset(unsigned int n) const
260  { return m_WrapOffset[n]; }
261 
265  virtual void GoToBegin();
266 
269  virtual void GoToEnd();
270 
273  virtual void Initialize(const SizeType &radius, const ImageType *ptr,
274  const RegionType &region);
275 
278  virtual bool IsAtBegin() const
279  { return ( this->GetCenterPointer() == m_Begin ); }
280 
283  virtual bool IsAtEnd() const
284  {
285  if ( this->GetCenterPointer() > m_End )
286  {
287  ExceptionObject e(__FILE__, __LINE__);
288  OStringStream msg;
289  msg << "In method IsAtEnd, CenterPointer = " << this->GetCenterPointer()
290  << " is greater than End = " << m_End
291  << std::endl
292  << " " << *this;
293  e.SetDescription(msg.str().c_str());
294  throw e;
295  }
296  return ( this->GetCenterPointer() == m_End );
297  }
298 
303  Self &operator++();
304 
309  Self &operator--();
310 
314  bool operator==(const Self &it) const
315  { return it.GetCenterPointer() == this->GetCenterPointer(); }
316 
320  bool operator!=(const Self &it) const
321  { return it.GetCenterPointer() != this->GetCenterPointer(); }
322 
326  bool operator<(const Self &it) const
327  { return this->GetCenterPointer() < it.GetCenterPointer(); }
328 
332  bool operator<=(const Self &it) const
333  { return this->GetCenterPointer() <= it.GetCenterPointer(); }
334 
338  bool operator>(const Self &it) const
339  { return this->GetCenterPointer() > it.GetCenterPointer(); }
340 
344  bool operator>=(const Self &it) const
345  { return this->GetCenterPointer() >= it.GetCenterPointer(); }
346 
351  void SetLocation( const IndexType& position )
352  {
353  this->SetLoop(position);
354  this->SetPixelPointers(position);
355  }
356 
357 
361  Self &operator+=(const OffsetType &);
362 
366  Self &operator-=(const OffsetType &);
367 
370  { return m_Loop - b.m_Loop; }
371 
375  bool InBounds() const;
376 
382  virtual void OverrideBoundaryCondition(const
384  { m_BoundaryCondition = i; }
385 
388  virtual void ResetBoundaryCondition()
389  { m_BoundaryCondition = &m_InternalBoundaryCondition; }
390 
392  void SetBoundaryCondition( const TBoundaryCondition &c )
393  { m_InternalBoundaryCondition = c; }
394 
396  const BoundaryConditionType *GetBoundaryCondition() const
397  { return dynamic_cast<BoundaryConditionType *>(m_BoundaryCondition); }
398 
400  void NeedToUseBoundaryConditionOn()
401  {
402  this->SetNeedToUseBoundaryCondition(true);
403  }
404  void NeedToUseBoundaryConditionOff()
405  {
406  this->SetNeedToUseBoundaryCondition(false);
407  }
408  void SetNeedToUseBoundaryCondition(bool b)
409  {
410  m_NeedToUseBoundaryCondition = b;
411  }
412  bool GetNeedToUseBoundaryCondition() const
413  {
414  return m_NeedToUseBoundaryCondition;
415  }
416 
417 protected:
418 
421  virtual void SetLoop( const IndexType& p )
422  { m_Loop = p; m_IsInBoundsValid = false;}
423 
427  virtual void SetBound(const SizeType &);
428 
433  virtual void SetPixelPointers(const IndexType &);
434 
437  virtual void SetBeginIndex( const IndexType& start)
438  { m_BeginIndex = start; }
439 
442  virtual void SetEndIndex();
443 
447 
450 
452  const InternalPixelType *m_Begin;
453 
455  typename ImageType::ConstWeakPointer m_ConstImage;
456 
458  const InternalPixelType *m_End;
459 
463 
466 
468  RegionType m_Region;
469 
476 
482 
485  mutable bool m_InBounds[Dimension];
486 
488  mutable bool m_IsInBounds;
489 
493  mutable bool m_IsInBoundsValid;
494 
497 
500 
502  TBoundaryCondition m_InternalBoundaryCondition;
503 
506 
509 
510 };
511 
512 template<class TImage>
515  const typename ConstNeighborhoodIterator<TImage>
516  ::OffsetType &ind)
517 {
519  ret = it;
520  ret += ind;
521  return ret;
522 }
523 
524 template<class TImage>
525 inline ConstNeighborhoodIterator<TImage>
527  ::OffsetType &ind,
529 { return (it + ind); }
530 
531 template<class TImage>
532 inline ConstNeighborhoodIterator<TImage>
534  const typename ConstNeighborhoodIterator<TImage>
535  ::OffsetType &ind)
536 {
538  ret = it;
539  ret -= ind;
540  return ret;
541 }
542 
543 } // namespace itk
544 
545 // Define instantiation macro for this template.
546 #define ITK_TEMPLATE_ConstNeighborhoodIterator(_, EXPORT, x, y) namespace itk { \
547  _(2(class EXPORT ConstNeighborhoodIterator< ITK_TEMPLATE_2 x >)) \
548  namespace Templates { typedef ConstNeighborhoodIterator< ITK_TEMPLATE_2 x > \
549  ConstNeighborhoodIterator##y; } \
550  }
551 
552 #if ITK_TEMPLATE_EXPLICIT
553 # include "Templates/itkConstNeighborhoodIterator+-.h"
554 #endif
555 
556 #if ITK_TEMPLATE_TXX
558 #endif
559 
560 /*
561 #ifndef ITK_MANUAL_INSTANTIATION
562 #include "itkConstNeighborhoodIterator.txx"
563 #endif
564 */
565 #endif

Generated at Sat Feb 2 2013 23:33:22 for Orfeo Toolbox with doxygen 1.8.1.1