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

itkSliceIterator.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkSliceIterator.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-03-03 15:09:26 $
00007   Version:   $Revision: 1.13 $
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 __itkSliceIterator_h
00018 #define __itkSliceIterator_h
00019 
00020 #include "itkMacro.h"
00021 #include "itkExceptionObject.h"
00022 #include <valarray>
00023 namespace itk {
00024 
00044 template<class TPixel, class TContainer>
00045 class ITK_EXPORT SliceIterator
00046 {
00047 public:
00049   SliceIterator(TContainer *n, std::slice s)
00050     : m_ContainerPointer(n), m_Pos(0), m_Slice(s) {}
00051 
00053   SliceIterator Begin()
00054     {
00055     SliceIterator ans = *this;
00056     ans.m_Pos = 0;
00057     return ans;
00058     }
00059 
00061   SliceIterator End()
00062     {
00063     SliceIterator ans = *this;
00064     ans.m_Pos = static_cast<unsigned long>(m_Slice.size());
00065     return ans;
00066     }
00068 
00070   SliceIterator operator++()
00071     {
00072     m_Pos++;
00073     return *this;
00074     }
00075 
00077   SliceIterator operator++(int)
00078     {
00079     SliceIterator ans  = *this;
00080     m_Pos++;
00081     return ans;
00082     }
00083 
00086   TPixel& operator[](unsigned long n)
00087     { return this->Loc(m_Pos=n); }
00088 
00091   TPixel& operator*()
00092     { return Loc(m_Pos); }
00093 
00096   bool operator==(const SliceIterator &orig)
00097     {
00098     return orig.m_Pos == this->m_Pos
00099       &&   orig.m_Slice.stride() == this->m_Slice.stride()
00100       &&   orig.m_Slice.start() == this->m_Slice.start();
00101     }
00102 
00104   bool operator!=(const SliceIterator &orig)
00105     {
00106       return ! operator==(orig);
00107     }
00108 
00112   bool operator<(const SliceIterator &orig)
00113     {
00114     return this->m_Pos < orig.m_Pos
00115       &&   this->m_Slice.stride() == orig.m_Slice.stride()
00116       &&   this->m_Slice.start() == orig.m_Slice.start();
00117     }
00118 
00119 private:
00121   TPixel& Loc(unsigned long n) const
00122     {
00123     const unsigned long start  = static_cast<unsigned long>( m_Slice.start() );
00124     const unsigned long stride = static_cast<unsigned long>( m_Slice.stride() );
00125     return (*m_ContainerPointer)[ start + n * stride ];
00126     }  
00128 
00130   TContainer *m_ContainerPointer;
00131 
00133   unsigned long m_Pos;
00134 
00136   std::slice m_Slice;
00137 };
00138 
00139 } // end namespace itk
00140 
00141 #endif
00142 

Generated at Thu May 28 11:40:30 2009 for ITK by doxygen 1.5.5 written by Dimitri van Heesch, © 1997-2000