ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkLineConstIterator.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 __itkLineConstIterator_h
00019 #define __itkLineConstIterator_h
00020 
00021 #include "itkIndex.h"
00022 #include "itkImage.h"
00023 
00024 namespace itk
00025 {
00055 template< class TImage >
00056 class ITK_EXPORT LineConstIterator
00057 {
00058 public:
00059 
00061   typedef LineConstIterator Self;
00062 
00067   itkStaticConstMacro(ImageIteratorDimension, unsigned int,
00068                       TImage::ImageDimension);
00069 
00071   typedef typename TImage::IndexType      IndexType;
00072 
00074   typedef typename TImage::OffsetType      OffsetType;
00075 
00077   typedef typename TImage::SizeType      SizeType;
00078 
00080   typedef typename TImage::RegionType RegionType;
00081 
00083   typedef typename TImage::SpacingType SpacingType;
00084 
00086   typedef typename TImage::PointType PointType;
00087 
00089   typedef TImage ImageType;
00090 
00094   typedef typename TImage::PixelContainer  PixelContainer;
00095   typedef typename PixelContainer::Pointer PixelContainerPointer;
00096 
00098   typedef typename TImage::InternalPixelType InternalPixelType;
00099 
00101   typedef typename TImage::PixelType PixelType;
00102 
00105   typedef typename TImage::AccessorType AccessorType;
00106 
00108   itkTypeMacro(LineConstIterator, None);
00109 
00111   static unsigned int GetImageIteratorDimension()
00112   {
00113     return TImage::ImageDimension;
00114   }
00115 
00117   const IndexType GetIndex()
00118   {
00119     return m_CurrentImageIndex;
00120   }
00121 
00123   const PixelType & Get(void) const
00124   {
00125     return m_Image->GetPixel(m_CurrentImageIndex);
00126   }
00127 
00129   bool IsAtEnd()
00130   {
00131     return m_IsAtEnd;
00132   }
00133 
00135   void GoToBegin();
00136 
00138   void operator++();
00139 
00142   Self & operator=(const Self & it);
00143 
00145   LineConstIterator(const ImageType *imagePtr, const IndexType & firstIndex, const IndexType & lastIndex);
00146 
00148   virtual ~LineConstIterator() {}
00149 protected: //made protected so other iterators can access
00150 
00152   typename ImageType::ConstWeakPointer m_Image;
00153 
00155   RegionType m_Region;
00156 
00158   bool m_IsAtEnd;
00159 
00161   IndexType m_CurrentImageIndex;
00162   IndexType m_StartIndex;
00163   IndexType m_LastIndex;
00164   IndexType m_EndIndex;  // one past the end of the line in the m_MainDirection
00165 
00167   // The dimension with the largest difference between start and end
00168   unsigned int m_MainDirection;
00169 
00170   // Accumulated error for the other dimensions
00171   IndexType m_AccumulateError;
00172 
00173   // Increment for the error for each step. Two times the difference between
00174   // start and end
00175   IndexType m_IncrementError;
00176 
00177   // If enough is accumulated for a dimension, the index has to be
00178   // incremented. Will be the number of pixels in the line
00179   IndexType m_MaximalError;
00180 
00181   // Direction of increment. -1 or 1
00182   IndexType m_OverflowIncrement;
00183 
00184   // After an overflow, the accumulated error is reduced again. Will be
00185   // two times the number of pixels in the line
00186   IndexType m_ReduceErrorAfterIncrement;
00187 };
00188 } // end namespace itk
00189 
00190 // Define instantiation macro for this template.
00191 #define ITK_TEMPLATE_LineConstIterator(_, EXPORT, TypeX, TypeY)     \
00192   namespace itk                                                     \
00193   {                                                                 \
00194   _( 1 ( class EXPORT LineConstIterator< ITK_TEMPLATE_1 TypeX > ) ) \
00195   namespace Templates                                               \
00196   {                                                                 \
00197   typedef LineConstIterator< ITK_TEMPLATE_1 TypeX >                 \
00198   LineConstIterator##TypeY;                                       \
00199   }                                                                 \
00200   }
00201 
00202 #if ITK_TEMPLATE_EXPLICIT
00203 #include "Templates/itkLineConstIterator+-.h"
00204 #endif
00205 
00206 #if ITK_TEMPLATE_TXX
00207 #include "itkLineConstIterator.hxx"
00208 #endif
00209 
00210 #endif
00211