Orfeo Toolbox  3.16
itkSliceIterator.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkSliceIterator.h,v $
5  Language: C++
6  Date: $Date: 2009-03-03 15:09:26 $
7  Version: $Revision: 1.13 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkSliceIterator_h
18 #define __itkSliceIterator_h
19 
20 #include "itkMacro.h"
21 #include "itkExceptionObject.h"
22 #include <valarray>
23 namespace itk {
24 
44 template<class TPixel, class TContainer>
46 {
47 public:
49  SliceIterator(TContainer *n, std::slice s)
50  : m_ContainerPointer(n), m_Pos(0), m_Slice(s) {}
51 
53  SliceIterator Begin()
54  {
55  SliceIterator ans = *this;
56  ans.m_Pos = 0;
57  return ans;
58  }
59 
62  {
63  SliceIterator ans = *this;
64  ans.m_Pos = static_cast<unsigned long>(m_Slice.size());
65  return ans;
66  }
67 
69  SliceIterator operator++()
70  {
71  m_Pos++;
72  return *this;
73  }
74 
76  SliceIterator operator++(int)
77  {
78  SliceIterator ans = *this;
79  m_Pos++;
80  return ans;
81  }
82 
85  TPixel& operator[](unsigned long n)
86  { return this->Loc(m_Pos=n); }
87 
90  TPixel& operator*()
91  { return Loc(m_Pos); }
92 
95  bool operator==(const SliceIterator &orig)
96  {
97  return orig.m_Pos == this->m_Pos
98  && orig.m_Slice.stride() == this->m_Slice.stride()
99  && orig.m_Slice.start() == this->m_Slice.start();
100  }
101 
103  bool operator!=(const SliceIterator &orig)
104  {
105  return ! operator==(orig);
106  }
107 
111  bool operator<(const SliceIterator &orig)
112  {
113  return this->m_Pos < orig.m_Pos
114  && this->m_Slice.stride() == orig.m_Slice.stride()
115  && this->m_Slice.start() == orig.m_Slice.start();
116  }
117 
118 private:
120  TPixel& Loc(unsigned long n) const
121  {
122  const unsigned long start = static_cast<unsigned long>( m_Slice.start() );
123  const unsigned long stride = static_cast<unsigned long>( m_Slice.stride() );
124  return (*m_ContainerPointer)[ start + n * stride ];
125  }
126 
128  TContainer *m_ContainerPointer;
129 
131  unsigned long m_Pos;
132 
134  std::slice m_Slice;
135 };
136 
137 } // end namespace itk
138 
139 #endif

Generated at Sun Feb 3 2013 00:07:40 for Orfeo Toolbox with doxygen 1.8.1.1