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: 2006-03-19 23:23:51 $
00007   Version:   $Revision: 1.6 $
00008 
00009   Copyright (c) Insight Software 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:
00051 
00053   ConstSliceIterator(const TContainer *n, std::slice s)
00054     : m_ContainerPointer(n), m_Pos(0), m_Slice(s) {}
00055 
00057   ConstSliceIterator Begin()
00058     {
00059     ConstSliceIterator ans = *this;
00060     ans.m_Pos = 0;
00061     return ans;
00062     }
00063 
00066   ConstSliceIterator End()
00067     {
00068     ConstSliceIterator ans = *this;
00069     ans.m_Pos = m_Slice.size();
00070     return ans;
00071     }
00073 
00075   ConstSliceIterator operator++()
00076     {
00077     m_Pos++;
00078     return *this;
00079     }
00080 
00082   ConstSliceIterator operator++(int)
00083     {
00084     ConstSliceIterator ans  = *this;
00085     m_Pos++;
00086     return ans;
00087     }
00088 
00091   const TPixel& operator[](unsigned long n)
00092     {
00093     return this->Loc(m_Pos=n);
00094     }
00095 
00098   const TPixel& operator*()
00099     {
00100     return Loc(m_Pos);
00101     }
00102 
00105   bool operator==(const ConstSliceIterator &orig)
00106     {
00107     return orig.m_Pos == this->m_Pos
00108       &&   orig.m_Slice.stride() == this->m_Slice.stride()
00109       &&   orig.m_Slice.start() == this->m_Slice.start();
00110     }
00111 
00113   bool operator!=(const ConstSliceIterator &orig)
00114     {
00115     return ! operator==(orig);
00116     }
00117 
00121   bool operator<(const ConstSliceIterator &orig)
00122     {
00123     return this->m_Pos < orig.m_Pos
00124       &&   this->m_Slice.stride() == orig.m_Slice.stride()
00125       &&   this->m_Slice.start() == orig.m_Slice.start();
00126     }
00127 
00128 private:
00130   const TPixel& Loc(unsigned long n) const
00131     {
00132     return (*m_ContainerPointer)[m_Slice.start() + n * m_Slice.stride()];
00133     }  
00134 
00136   const TContainer *m_ContainerPointer;
00137 
00139   unsigned long m_Pos;
00140 
00142   std::slice m_Slice;
00143 };
00144 
00145 } // end namespace itk
00146 
00147 #endif
00148 

Generated at Sat Feb 28 12:15:44 2009 for ITK by doxygen 1.5.6 written by Dimitri van Heesch, © 1997-2000