ITK  4.6.0
Insight Segmentation and Registration Toolkit
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 =
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  typedef unsigned int DimensionValueType;
62 
64  itkStaticConstMacro(Dimension, DimensionValueType, TImage::ImageDimension);
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;
85 
88 
92  typedef typename ImageType::NeighborhoodAccessorFunctorType
94 
96  typedef TBoundaryCondition BoundaryConditionType;
97 
102 
105 
108 
111 
115  const ImageType *ptr,
116  const RegionType & region)
117  {
118  this->Initialize(radius, ptr, region);
119  for ( DimensionValueType i = 0; i < Dimension; i++ )
120  { m_InBounds[i] = false; }
121  this->ResetBoundaryCondition();
122  m_NeighborhoodAccessorFunctor = ptr->GetNeighborhoodAccessor();
123  m_NeighborhoodAccessorFunctor.SetBegin( ptr->GetBufferPointer() );
124  }
126 
128  Self & operator=(const Self & orig);
129 
131  virtual void PrintSelf(std::ostream &, Indent) const;
132 
136 
139  { return m_Bound; }
140 
144  { return m_Bound[n]; }
145 
148  { return ( this->operator[]( ( this->Size() ) >> 1 ) ); }
149 
153  { return m_NeighborhoodAccessorFunctor.Get( this->GetCenterPointer() ); }
154 
156  const ImageType * GetImagePointer(void) const
157  { return m_ConstImage; }
158 
161  virtual IndexType GetIndex(void) const
162  { return m_Loop; }
163 
166  virtual NeighborhoodType GetNeighborhood() const;
167 
170  {
172  {
173  return ( m_NeighborhoodAccessorFunctor.Get( this->operator[](i) ) );
174  }
175  bool inbounds;
176  return this->GetPixel(i, inbounds);
177  }
179 
185  virtual PixelType GetPixel(NeighborIndexType i, bool & IsInBounds) const;
186 
189  virtual PixelType GetPixel(const OffsetType & o) const
190  {
191  bool inbounds;
192 
193  return ( this->GetPixel(this->GetNeighborhoodIndex(o), inbounds) );
194  }
195 
201  virtual PixelType GetPixel(const OffsetType & o,
202  bool & IsInBounds) const
203  { return ( this->GetPixel(this->GetNeighborhoodIndex(o), IsInBounds) ); }
204 
208  virtual PixelType GetNext(const unsigned axis, NeighborIndexType i) const
209  {
210  return ( this->GetPixel( this->GetCenterNeighborhoodIndex()
211  + ( i * this->GetStride(axis) ) ) );
212  }
213 
217  virtual PixelType GetNext(const unsigned axis) const
218  {
219  return ( this->GetPixel( this->GetCenterNeighborhoodIndex()
220  + this->GetStride(axis) ) );
221  }
222 
226  virtual PixelType GetPrevious(const unsigned axis, NeighborIndexType i) const
227  {
228  return ( this->GetPixel( this->GetCenterNeighborhoodIndex()
229  - ( i * this->GetStride(axis) ) ) );
230  }
231 
235  virtual PixelType GetPrevious(const unsigned axis) const
236  {
237  return ( this->GetPixel( this->GetCenterNeighborhoodIndex()
238  - this->GetStride(axis) ) );
239  }
240 
243  virtual IndexType GetIndex(const OffsetType & o) const
244  { return ( this->GetIndex() + o ); }
245 
249  { return ( this->GetIndex() + this->GetOffset(i) ); }
250 
253  { return m_Region; }
254 
258  { return m_BeginIndex; }
259 
263 
266  { return m_WrapOffset; }
267 
274  { return m_WrapOffset[n]; }
275 
279  virtual void GoToBegin();
280 
283  virtual void GoToEnd();
284 
287  virtual void Initialize(const SizeType & radius, const ImageType *ptr,
288  const RegionType & region);
289 
292  virtual bool IsAtBegin() const
293  { return ( this->GetCenterPointer() == m_Begin ); }
294 
297  virtual bool IsAtEnd() const
298  {
299  if ( this->GetCenterPointer() > m_End )
300  {
301  ExceptionObject e(__FILE__, __LINE__);
302  std::ostringstream msg;
303  msg << "In method IsAtEnd, CenterPointer = " << this->GetCenterPointer()
304  << " is greater than End = " << m_End
305  << std::endl
306  << " " << *this;
307  e.SetDescription( msg.str().c_str() );
308  throw e;
309  }
310  return ( this->GetCenterPointer() == m_End );
311  }
313 
318  Self & operator++();
319 
324  Self & operator--();
325 
329  bool operator==(const Self & it) const
330  { return it.GetCenterPointer() == this->GetCenterPointer(); }
331 
335  bool operator!=(const Self & it) const
336  { return it.GetCenterPointer() != this->GetCenterPointer(); }
337 
341  bool operator<(const Self & it) const
342  { return this->GetCenterPointer() < it.GetCenterPointer(); }
343 
347  bool operator<=(const Self & it) const
348  { return this->GetCenterPointer() <= it.GetCenterPointer(); }
349 
353  bool operator>(const Self & it) const
354  { return this->GetCenterPointer() > it.GetCenterPointer(); }
355 
359  bool operator>=(const Self & it) const
360  { return this->GetCenterPointer() >= it.GetCenterPointer(); }
361 
366  void SetLocation(const IndexType & position)
367  {
368  this->SetLoop(position);
369  this->SetPixelPointers(position);
370  }
372 
376  Self & operator+=(const OffsetType &);
377 
381  Self & operator-=(const OffsetType &);
382 
385  { return m_Loop - b.m_Loop; }
386 
390  bool InBounds() const;
391 
403  bool IndexInBounds(NeighborIndexType n, OffsetType & internalIndex, OffsetType & offset ) const;
404 
410  virtual void OverrideBoundaryCondition(const
412  { m_BoundaryCondition = i; }
413 
416  virtual void ResetBoundaryCondition()
418 
420  void SetBoundaryCondition(const TBoundaryCondition & c)
422 
425  { return m_BoundaryCondition; }
426 
429  {
430  this->SetNeedToUseBoundaryCondition(true);
431  }
432 
434  {
435  this->SetNeedToUseBoundaryCondition(false);
436  }
437 
439  {
441  }
442 
444  {
446  }
447 
449  virtual void SetRegion(const RegionType & region);
450 
451 protected:
452 
455  virtual void SetLoop(const IndexType & p)
456  { m_Loop = p; m_IsInBoundsValid = false; }
457 
461  virtual void SetBound(const SizeType &);
462 
467  virtual void SetPixelPointers(const IndexType &);
468 
471  virtual void SetBeginIndex(const IndexType & start)
472  { m_BeginIndex = start; }
473 
476  virtual void SetEndIndex();
477 
481 
484 
487 
489  typename ImageType::ConstWeakPointer m_ConstImage;
490 
493 
497 
500 
503 
510 
516 
519  mutable bool m_InBounds[Dimension];
520 
522  mutable bool m_IsInBounds;
523 
527  mutable bool m_IsInBoundsValid;
528 
531 
534 
536  TBoundaryCondition m_InternalBoundaryCondition;
537 
540 
543 };
544 
545 template< typename TImage >
549  ::OffsetType & ind)
550 {
552  ret = it;
553  ret += ind;
554  return ret;
555 }
556 
557 template< typename TImage >
560  ::OffsetType & ind,
562 { return ( it + ind ); }
563 
564 template< typename TImage >
568  ::OffsetType & ind)
569 {
571  ret = it;
572  ret -= ind;
573  return ret;
574 }
575 } // namespace itk
576 
577 #ifndef ITK_MANUAL_INSTANTIATION
578 #include "itkConstNeighborhoodIterator.hxx"
579 #endif
580 
581 #endif
virtual IndexType GetIndex(void) const
OffsetValueType GetWrapOffset(NeighborIndexType n) const
NeighborhoodAccessorFunctorType m_NeighborhoodAccessorFunctor
typedef::itk::Size< VDimension > RadiusType
ConstNeighborhoodIterator< TImage > operator-(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
virtual void SetDescription(const std::string &s)
Neighborhood< PixelType, itkGetStaticConstMacro(Dimension) > NeighborhoodType
virtual PixelType GetNext(const unsigned axis) const
signed long OffsetValueType
Definition: itkIntTypes.h:154
virtual PixelType GetPixel(NeighborIndexType i) const
virtual void OverrideBoundaryCondition(const ImageBoundaryConditionPointerType i)
A light-weight container object for storing an N-dimensional neighborhood of values.
signed long IndexValueType
Definition: itkIntTypes.h:150
virtual void PrintSelf(std::ostream &, Indent) const
NeighborhoodType::NeighborIndexType NeighborIndexType
virtual NeighborIndexType GetNeighborhoodIndex(const OffsetType &) const
static const double e
The base of the natural logarithm or Euler&#39;s number
Definition: itkMath.h:45
virtual PixelType GetPixel(const OffsetType &o, bool &IsInBounds) const
Const version of NeighborhoodIterator, defining iteration of a local N-dimensional neighborhood of pi...
virtual PixelType GetPrevious(const unsigned axis, NeighborIndexType i) const
ImageBoundaryCondition< ImageType > * ImageBoundaryConditionPointerType
IndexValueType GetBound(NeighborIndexType n) const
virtual PixelType GetNext(const unsigned axis, NeighborIndexType i) const
virtual void SetPixelPointers(const IndexType &)
ConstNeighborhoodIterator(const SizeType &radius, const ImageType *ptr, const RegionType &region)
ImageType::ConstWeakPointer m_ConstImage
Self & operator=(const Self &orig)
ImageBoundaryConditionPointerType m_BoundaryCondition
void SetLocation(const IndexType &position)
ConstNeighborhoodIterator< TImage > operator+(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
typedef::itk::Size< VDimension > SizeType
virtual IndexType GetIndex(const OffsetType &o) const
Standard exception handling object.
virtual void SetRegion(const RegionType &region)
Neighborhood< InternalPixelType *, itkGetStaticConstMacro(Dimension) > Superclass
virtual void SetLoop(const IndexType &p)
virtual void SetBeginIndex(const IndexType &start)
virtual PixelType GetPrevious(const unsigned axis) const
ImageType::NeighborhoodAccessorFunctorType NeighborhoodAccessorFunctorType
Self & operator+=(const OffsetType &)
const ImageType * GetImagePointer(void) const
Index< itkGetStaticConstMacro(Dimension) > IndexType
bool IndexInBounds(NeighborIndexType n, OffsetType &internalIndex, OffsetType &offset) const
Self & operator-=(const OffsetType &)
AllocatorType::iterator Iterator
ImageBoundaryCondition< ImageType > const * ImageBoundaryConditionConstPointerType
RegionType GetBoundingBoxAsImageRegion() const
const InternalPixelType * GetCenterPointer() const
Control indentation during Print() invocation.
Definition: itkIndent.h:49
virtual void SetBound(const SizeType &)
AllocatorType::const_iterator ConstIterator
OffsetType ComputeInternalIndex(const NeighborIndexType n) const
virtual NeighborhoodType GetNeighborhood() const
static const DimensionValueType Dimension
ImageBoundaryConditionPointerType GetBoundaryCondition() const
void SetBoundaryCondition(const TBoundaryCondition &c)
virtual IndexType GetIndex(NeighborIndexType i) const
virtual PixelType GetPixel(const OffsetType &o) const
TImage::InternalPixelType InternalPixelType
virtual void Initialize(const SizeType &radius, const ImageType *ptr, const RegionType &region)
SizeValueType NeighborIndexType