ITK  4.5.0
Insight Segmentation and Registration Toolkit
itkImageLinearConstIteratorWithIndex.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkImageLinearConstIteratorWithIndex_h
19 #define __itkImageLinearConstIteratorWithIndex_h
20 
22 
23 namespace itk
24 {
100 template< typename TImage >
102 {
103 public:
107 
112  typedef typename TImage::IndexType IndexType;
113 
118  typedef typename TImage::RegionType RegionType;
119 
124  typedef TImage ImageType;
125 
129  typedef typename TImage::PixelContainer PixelContainer;
130  typedef typename PixelContainer::Pointer PixelContainerPointer;
131 
134 
137  ImageLinearConstIteratorWithIndex(const ImageType *ptr, const RegionType & region);
138 
147 
150  inline void NextLine(void);
151 
154  inline void PreviousLine(void);
155 
158  void GoToBeginOfLine(void);
159 
162  void GoToReverseBeginOfLine(void);
163 
166  void GoToEndOfLine(void);
167 
169  inline bool IsAtEndOfLine(void)
170  {
171  return this->m_PositionIndex[m_Direction] >= this->m_EndIndex[m_Direction];
172  }
173 
175  inline bool IsAtReverseEndOfLine(void)
176  {
177  return this->m_PositionIndex[m_Direction] < this->m_BeginIndex[m_Direction];
178  }
179 
181  inline void SetDirection(unsigned int direction)
182  {
183  if ( direction >= TImage::ImageDimension )
184  {
185  itkGenericExceptionMacro(
186  << "In image of dimension " << TImage::ImageDimension << " Direction " << direction << " sas selected");
187  }
188  m_Direction = direction;
190  }
192 
194  unsigned int GetDirection()
195  {
196  return m_Direction;
197  }
198 
201  inline Self & operator++()
202  {
203  this->m_PositionIndex[m_Direction]++;
204  this->m_Position += m_Jump;
205  return *this;
206  }
208 
211  inline Self & operator--()
212  {
213  this->m_PositionIndex[m_Direction]--;
214  this->m_Position -= m_Jump;
215  return *this;
216  }
218 
219 private:
221  unsigned int m_Direction;
222 };
223 
224 //----------------------------------------------------------------------
225 // Go to next line
226 //----------------------------------------------------------------------
227 template< typename TImage >
228 inline
229 void
232 {
233  this->m_Position -= this->m_OffsetTable[m_Direction]
234  * ( this->m_PositionIndex[m_Direction] - this->m_BeginIndex[m_Direction] );
235 
236  this->m_PositionIndex[m_Direction] = this->m_BeginIndex[m_Direction];
237 
238  for ( unsigned int n = 0; n < TImage::ImageDimension; n++ )
239  {
240  this->m_Remaining = false;
241 
242  if ( n == m_Direction )
243  {
244  continue;
245  }
246 
247  this->m_PositionIndex[n]++;
248  if ( this->m_PositionIndex[n] < this->m_EndIndex[n] )
249  {
250  this->m_Position += this->m_OffsetTable[n];
251  this->m_Remaining = true;
252  break;
253  }
254  else
255  {
256  this->m_Position -= this->m_OffsetTable[n] * ( this->m_Region.GetSize()[n] - 1 );
257  this->m_PositionIndex[n] = this->m_BeginIndex[n];
258  }
259  }
260 }
261 
262 //----------------------------------------------------------------------
263 // Pass to the last pixel on the previous line
264 //----------------------------------------------------------------------
265 template< typename TImage >
266 inline
267 void
270 {
271  this->m_Position += this->m_OffsetTable[m_Direction]
272  * ( this->m_EndIndex[m_Direction] - 1 - this->m_PositionIndex[m_Direction] );
273 
274  this->m_PositionIndex[m_Direction] = this->m_EndIndex[m_Direction] - 1;
275 
276  for ( unsigned int n = 0; n < TImage::ImageDimension; n++ )
277  {
278  this->m_Remaining = false;
279 
280  if ( n == m_Direction )
281  {
282  continue;
283  }
284 
285  this->m_PositionIndex[n]--;
286  if ( this->m_PositionIndex[n] >= this->m_BeginIndex[n] )
287  {
288  this->m_Position -= this->m_OffsetTable[n];
289  this->m_Remaining = true;
290  break;
291  }
292  else
293  {
294  this->m_Position += this->m_OffsetTable[n] * ( this->m_Region.GetSize()[n] - 1 );
295  this->m_PositionIndex[n] = this->m_EndIndex[n] - 1;
296  }
297  }
298 }
299 } // end namespace itk
300 
301 #ifndef ITK_MANUAL_INSTANTIATION
302 #include "itkImageLinearConstIteratorWithIndex.hxx"
303 #endif
304 
305 #endif
ImageLinearConstIteratorWithIndex(const ImageConstIteratorWithIndex< TImage > &it)
OffsetValueType m_OffsetTable[ImageDimension+1]
A multi-dimensional image iterator that visits image pixels within a region in a &quot;scan-line&quot; order...
A base class for multi-dimensional iterators templated over image type that are designed to efficient...
Self & operator=(const Self &it)