ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkImageConstIteratorWithIndex.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkImageConstIteratorWithIndex_h
00019 #define __itkImageConstIteratorWithIndex_h
00020 
00021 #include "itkIndex.h"
00022 #include "itkImage.h"
00023 #include <memory>
00024 
00025 namespace itk
00026 {
00091 template< typename TImage >
00092 class ITK_EXPORT ImageConstIteratorWithIndex
00093 {
00094 public:
00096   typedef ImageConstIteratorWithIndex Self;
00097 
00102   itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension);
00103 
00105   typedef typename TImage::IndexType         IndexType;
00106   typedef typename IndexType::IndexValueType IndexValueType;
00107 
00109   typedef typename TImage::SizeType        SizeType;
00110   typedef typename SizeType::SizeValueType SizeValueType;
00111 
00113   typedef typename TImage::RegionType RegionType;
00114 
00116   typedef TImage ImageType;
00117 
00121   typedef typename TImage::PixelContainer  PixelContainer;
00122   typedef typename PixelContainer::Pointer PixelContainerPointer;
00123 
00125   typedef typename TImage::InternalPixelType InternalPixelType;
00126 
00128   typedef typename TImage::PixelType PixelType;
00129 
00132   typedef typename TImage::AccessorType        AccessorType;
00133   typedef typename TImage::AccessorFunctorType AccessorFunctorType;
00134 
00136   typedef typename TImage::OffsetType          OffsetType;
00137   typedef typename OffsetType::OffsetValueType OffsetValueType;
00138 
00141   ImageConstIteratorWithIndex();
00142 
00145   ImageConstIteratorWithIndex(const Self & it);
00146 
00149   ImageConstIteratorWithIndex(const TImage *ptr,
00150                               const RegionType & region);
00151 
00153   virtual ~ImageConstIteratorWithIndex() {};
00154 
00157   Self & operator=(const Self & it);
00158 
00160   static unsigned int GetImageDimension()
00161   {
00162     return ImageDimension;
00163   }
00164 
00167   bool
00168   operator!=(const Self & it) const
00169   {
00170     // two iterators are the same if they "point to" the same memory location
00171     return ( m_Position ) != ( it.m_Position );
00172   }
00173 
00176   bool
00177   operator==(const Self & it) const
00178   {
00179     // two iterators are the same if they "point to" the same memory location
00180     return ( m_Position ) == ( it.m_Position );
00181   }
00182 
00185   bool
00186   operator<=(const Self & it) const
00187   {
00188     // an iterator is "less than" another if it "points to" a lower
00189     // memory location
00190     return ( m_Position ) <= ( it.m_Position );
00191   }
00192 
00195   bool
00196   operator<(const Self & it) const
00197   {
00198     // an iterator is "less than" another if it "points to" a lower
00199     // memory location
00200     return ( m_Position ) < ( it.m_Position );
00201   }
00202 
00205   bool
00206   operator>=(const Self & it) const
00207   {
00208     // an iterator is "greater than" another if it "points to" a higher
00209     // memory location
00210     return ( m_Position ) >= ( it.m_Position );
00211   }
00212 
00215   bool
00216   operator>(const Self & it) const
00217   {
00218     // an iterator is "greater than" another if it "points to" a higher
00219     // memory location
00220     return ( m_Position ) > ( it.m_Position );
00221   }
00222 
00225   const IndexType & GetIndex() const
00226   {
00227     return m_PositionIndex;
00228   }
00229 
00232   const RegionType & GetRegion() const
00233   {
00234     return m_Region;
00235   }
00236 
00239   void SetIndex(const IndexType & ind)
00240   {
00241     m_Position = m_Image->GetBufferPointer() + m_Image->ComputeOffset(ind);
00242     m_PositionIndex = ind;
00243   }
00245 
00247   PixelType Get(void) const
00248   {
00249     return m_PixelAccessorFunctor.Get(*m_Position);
00250   }
00251 
00255   const PixelType & Value(void) const
00256   {
00257     return *m_Position;
00258   }
00259 
00262   Self Begin(void) const;
00263 
00265   void GoToBegin(void);
00266 
00269   Self End(void) const;
00270 
00272   void GoToReverseBegin(void);
00273 
00275   bool IsAtReverseEnd(void) const
00276   {
00277     return !m_Remaining;
00278   }
00279 
00281   bool IsAtEnd(void) const
00282   {
00283     return !m_Remaining;
00284   }
00285 
00287   bool Remaining()
00288   {
00289     return m_Remaining;
00290   }
00291 
00292 protected: //made protected so other iterators can access
00293   typename TImage::ConstWeakPointer m_Image;
00294 
00295   IndexType m_PositionIndex;        // Index where we currently are
00296   IndexType m_BeginIndex;           // Index to start iterating over
00297   IndexType m_EndIndex;             // Index to finish iterating:
00298                                     // one pixel past the end of each
00299                                     // row, col, slice, etc....
00300 
00301   RegionType m_Region;              // region to iterate over
00302 
00303   OffsetValueType m_OffsetTable[ImageDimension + 1];
00304 
00305   const InternalPixelType *m_Position;
00306   const InternalPixelType *m_Begin;
00307   const InternalPixelType *m_End;
00308 
00309   bool m_Remaining;
00310 
00311   AccessorType        m_PixelAccessor;
00312   AccessorFunctorType m_PixelAccessorFunctor;
00313 };
00314 } // end namespace itk
00315 
00316 // Define instantiation macro for this template.
00317 #define ITK_TEMPLATE_ImageConstIteratorWithIndex(_, EXPORT, TypeX, TypeY)                           \
00318   namespace itk                                                                                     \
00319   {                                                                                                 \
00320   _( 1 ( class EXPORT ImageConstIteratorWithIndex< ITK_TEMPLATE_1 TypeX > ) )                       \
00321   namespace Templates                                                                               \
00322   {                                                                                                 \
00323   typedef ImageConstIteratorWithIndex< ITK_TEMPLATE_1 TypeX > ImageConstIteratorWithIndex##TypeY; \
00324   }                                                                                                 \
00325   }
00326 
00327 #if ITK_TEMPLATE_EXPLICIT
00328 //template<typename TImage> const unsigned int itk::ImageConstIteratorWithIndex<
00329 // TImage>::ImageDimension;
00330 #include "Templates/itkImageConstIteratorWithIndex+-.h"
00331 #endif
00332 
00333 #if ITK_TEMPLATE_TXX
00334 #include "itkImageConstIteratorWithIndex.hxx"
00335 #endif
00336 
00337 #endif
00338