Orfeo Toolbox  3.16
itkImageConstIteratorWithIndex.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkImageConstIteratorWithIndex.txx,v $
5  Language: C++
6  Date: $Date: 2009-05-11 21:48:29 $
7  Version: $Revision: 1.31 $
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 __itkImageConstIteratorWithIndex_txx
18 #define __itkImageConstIteratorWithIndex_txx
19 
21 #include <string.h>
22 
23 namespace itk
24 {
25 
26 
27 //----------------------------------------------------------------------
28 // Constructor
29 //----------------------------------------------------------------------
30 template<class TImage>
33 {
34  m_Position = 0;
35  m_Begin = 0;
36  m_End = 0;
37  m_Remaining = false;
38 }
39 
40 
41 //----------------------------------------------------------------------
42 // Constructor
43 //----------------------------------------------------------------------
44 template<class TImage>
47 {
48  m_Image = it.m_Image; // copy the smart pointer
49 
50  m_PositionIndex = it.m_PositionIndex;
51  m_BeginIndex = it.m_BeginIndex;
52  m_EndIndex = it.m_EndIndex;
53  m_Region = it.m_Region;
54 
55  memcpy(m_OffsetTable, it.m_OffsetTable,
56  (ImageDimension+1)*sizeof(unsigned long));
57 
58  m_Position = it.m_Position;
59  m_Begin = it.m_Begin;
60  m_End = it.m_End;
61  m_Remaining = it.m_Remaining;
62 
63  m_PixelAccessor = it.m_PixelAccessor;
64  m_PixelAccessorFunctor = it.m_PixelAccessorFunctor;
65  m_PixelAccessorFunctor.SetBegin( m_Image->GetBufferPointer() );
66 }
67 
68 
69 //----------------------------------------------------------------------
70 // Constructor
71 //----------------------------------------------------------------------
72 template<class TImage>
74 ::ImageConstIteratorWithIndex( const TImage *ptr,
75  const RegionType & region )
76 {
77  m_Image = ptr;
78 
79  const InternalPixelType * buffer = m_Image->GetBufferPointer();
80 
81  m_BeginIndex = region.GetIndex();
82  m_PositionIndex = m_BeginIndex;
83  m_Region = region;
84 
85 #ifdef ITK_USE_REGION_VALIDATION_IN_ITERATORS
86  if( region.GetNumberOfPixels() > 0 ) // If region is non-empty
87  {
88  const RegionType & bufferedRegion = m_Image->GetBufferedRegion();
89  itkAssertOrThrowMacro( (bufferedRegion.IsInside( m_Region )),
90  "Region " << m_Region << " is outside of buffered region " << bufferedRegion );
91  }
92 #endif
93 
94  memcpy(m_OffsetTable, m_Image->GetOffsetTable(),
95  (ImageDimension+1)*sizeof(unsigned long));
96 
97  // Compute the start position
98  long offs = m_Image->ComputeOffset( m_BeginIndex );
99  m_Begin = buffer + offs;
100  m_Position = m_Begin;
101 
102  // Compute the end offset
103  m_Remaining = false;
104  IndexType pastEnd;
105  for (unsigned int i=0; i < ImageDimension; ++i)
106  {
107  unsigned long size = region.GetSize()[i];
108  if( size > 0 )
109  {
110  m_Remaining = true;
111  }
112  m_EndIndex[i] = m_BeginIndex[i] + static_cast<long>(size);
113  pastEnd[i] = m_BeginIndex[i] + static_cast<long>(size)-1;
114  }
115  m_End = buffer + m_Image->ComputeOffset( pastEnd );
116 
117  m_PixelAccessor = m_Image->GetPixelAccessor();
118  m_PixelAccessorFunctor.SetPixelAccessor( m_PixelAccessor );
119  m_PixelAccessorFunctor.SetBegin( buffer );
120 
121  GoToBegin();
122 
123 }
124 
125 
126 //----------------------------------------------------------------------
127 // Assignment Operator
128 //----------------------------------------------------------------------
129 template<class TImage>
132 ::operator=(const Self& it)
133 {
134  m_Image = it.m_Image; // copy the smart pointer
135 
136  m_BeginIndex = it.m_BeginIndex;
137  m_EndIndex = it.m_EndIndex;
138  m_PositionIndex = it.m_PositionIndex;
139  m_Region = it.m_Region;
140 
141  memcpy(m_OffsetTable, it.m_OffsetTable,
142  (ImageDimension+1)*sizeof(unsigned long));
143 
144  m_Position = it.m_Position;
145  m_Begin = it.m_Begin;
146  m_End = it.m_End;
147  m_Remaining = it.m_Remaining;
148 
149  m_PixelAccessor = it.m_PixelAccessor;
150  m_PixelAccessorFunctor = it.m_PixelAccessorFunctor;
151  m_PixelAccessorFunctor.SetBegin( m_Image->GetBufferPointer() );
152 
153  return *this;
154 }
155 
156 
157 //----------------------------------------------------------------------------
158 // Begin() is the first pixel in the region.
159 //----------------------------------------------------------------------------
160 template<class TImage>
163 ::Begin() const
164 {
165  Self it( *this );
166  it.GoToBegin();
167  return it;
168 }
169 
170 
171 //----------------------------------------------------------------------------
172 // GoToBegin() is the first pixel in the region.
173 //----------------------------------------------------------------------------
174 template<class TImage>
175 void
178 {
179  // Set the position at begin
180 
181  m_Position = m_Begin;
182  m_PositionIndex = m_BeginIndex;
183 
184  if( m_Region.GetNumberOfPixels() > 0 )
185  {
186  m_Remaining = true;
187  }
188  else
189  {
190  m_Remaining = false;
191  }
192 
193 }
194 
195 
196 //----------------------------------------------------------------------------
197 // End() is the last pixel in the region. DEPRECATED
198 //----------------------------------------------------------------------------
199 template<class TImage>
202 ::End() const
203 {
204  Self it( *this );
205  it.GoToReverseBegin();
206  return it;
207 }
208 
209 
210 //----------------------------------------------------------------------------
211 // GoToReverseBegin() is the last pixel in the region.
212 //----------------------------------------------------------------------------
213 template<class TImage>
214 void
217 {
218 
219  for (unsigned int i=0; i < ImageDimension; ++i)
220  {
221  m_PositionIndex[i] = m_EndIndex[i]-1;
222  }
223 
224  if( m_Region.GetNumberOfPixels() > 0 )
225  {
226  m_Remaining = true;
227  }
228  else
229  {
230  m_Remaining = false;
231  }
232 
233 
234  // Set the position at the end
235  const InternalPixelType * buffer = m_Image->GetBufferPointer();
236  const unsigned long offset = m_Image->ComputeOffset( m_PositionIndex );
237  m_Position = buffer + offset;
238 
239 }
240 
241 } // end namespace itk
242 
243 #endif

Generated at Sat Feb 2 2013 23:42:41 for Orfeo Toolbox with doxygen 1.8.1.1