Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkConstSliceIterator.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkConstSliceIterator.h,v $
00005   Language:  C++
00006   Date:      $Date: 2002/01/15 18:56:30 $
00007   Version:   $Revision: 1.4 $
00008 
00009   Copyright (c) 2002 Insight Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkConstSliceIterator_h
00018 #define __itkConstSliceIterator_h
00019 
00020 #include "itkMacro.h"
00021 #include "itkExceptionObject.h"
00022 #include <valarray>
00023 namespace itk {
00024 
00047 template<class TPixel, class TContainer>
00048 class ITK_EXPORT ConstSliceIterator
00049 {
00050 public:
00052   ConstSliceIterator(const TContainer *n, std::slice s)
00053     : m_ContainerPointer(n), m_Pos(0), m_Slice(s) {}
00054 
00056   ConstSliceIterator Begin()
00057   {
00058     ConstSliceIterator ans = *this;
00059     ans.m_Pos = 0;
00060     return ans;
00061   }
00062   
00064   ConstSliceIterator End()
00065   {
00066     ConstSliceIterator ans = *this;
00067     ans.m_Pos = m_Slice.size();
00068     return ans;
00069   }
00070 
00072   ConstSliceIterator operator++()
00073   {
00074     m_Pos++;
00075     return *this;
00076   }
00077 
00079   ConstSliceIterator operator++(int)
00080   {
00081     ConstSliceIterator ans  = *this;
00082     m_Pos++;
00083     return ans;
00084   }
00085 
00088   const TPixel& operator[](unsigned long n)
00089   {
00090     return this->Loc(m_Pos=n);
00091   }
00092 
00095   const TPixel& operator*()
00096   {
00097     return Loc(m_Pos);
00098   }
00099 
00102   bool operator==(const ConstSliceIterator &orig)
00103   {
00104     return orig.m_Pos==this->m_Pos
00105       &&   orig.m_Slice.stride()==this->m_Slice.stride()
00106       &&   orig.m_Slice.start() ==this->m_Slice.start();
00107   }
00108   
00110   bool operator!=(const ConstSliceIterator &orig)
00111   {
00112     return ! operator==(orig);
00113   }
00114 
00118   bool operator<(const ConstSliceIterator &orig)
00119   {
00120     return this->m_Pos < orig.m_Pos
00121       &&   this->m_Slice.stride()==orig.m_Slice.stride()
00122       &&   this->m_Slice.start()==orig.m_Slice.start();
00123   }
00124   
00125 private:
00127   const TPixel& Loc(unsigned long n) const
00128   {
00129     return (*m_ContainerPointer)[m_Slice.start()
00130                                        + n * m_Slice.stride()];
00131   }  
00132 
00134   const TContainer *m_ContainerPointer;
00135 
00137   unsigned long m_Pos;
00138 
00140   std::slice m_Slice;
00141 };
00142   
00143 } // end namespace itk
00144 
00145 #endif

Generated at Fri May 21 01:14:35 2004 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000