ITK  4.9.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  ImageConstIteratorWithIndex< TImage >(),
135  m_Jump(0),
136  m_Direction(0)
137  {}
138 
141  ImageLinearConstIteratorWithIndex(const ImageType *ptr, const RegionType & region);
142 
151 
154  inline void NextLine();
155 
158  inline void PreviousLine();
159 
162  void GoToBeginOfLine();
163 
166  void GoToReverseBeginOfLine();
167 
170  void GoToEndOfLine();
171 
173  inline bool IsAtEndOfLine(void)
174  {
175  return this->m_PositionIndex[m_Direction] >= this->m_EndIndex[m_Direction];
176  }
177 
179  inline bool IsAtReverseEndOfLine(void)
180  {
181  return this->m_PositionIndex[m_Direction] < this->m_BeginIndex[m_Direction];
182  }
183 
185  inline void SetDirection(unsigned int direction)
186  {
187  if ( direction >= TImage::ImageDimension )
188  {
189  itkGenericExceptionMacro(
190  << "In image of dimension " << TImage::ImageDimension << " Direction " << direction << " sas selected");
191  }
192  m_Direction = direction;
194  }
196 
198  unsigned int GetDirection()
199  {
200  return m_Direction;
201  }
202 
205  inline Self & operator++()
206  {
207  this->m_PositionIndex[m_Direction]++;
208  this->m_Position += m_Jump;
209  return *this;
210  }
212 
215  inline Self & operator--()
216  {
217  this->m_PositionIndex[m_Direction]--;
218  this->m_Position -= m_Jump;
219  return *this;
220  }
222 
223 private:
225  unsigned int m_Direction;
226 };
227 
228 //----------------------------------------------------------------------
229 // Go to next line
230 //----------------------------------------------------------------------
231 template< typename TImage >
232 inline
233 void
236 {
237  this->m_Position -= this->m_OffsetTable[m_Direction]
238  * ( this->m_PositionIndex[m_Direction] - this->m_BeginIndex[m_Direction] );
239 
240  this->m_PositionIndex[m_Direction] = this->m_BeginIndex[m_Direction];
241 
242  for ( unsigned int n = 0; n < TImage::ImageDimension; n++ )
243  {
244  this->m_Remaining = false;
245 
246  if ( n == m_Direction )
247  {
248  continue;
249  }
250 
251  this->m_PositionIndex[n]++;
252  if ( this->m_PositionIndex[n] < this->m_EndIndex[n] )
253  {
254  this->m_Position += this->m_OffsetTable[n];
255  this->m_Remaining = true;
256  break;
257  }
258  else
259  {
260  this->m_Position -= this->m_OffsetTable[n] * ( this->m_Region.GetSize()[n] - 1 );
261  this->m_PositionIndex[n] = this->m_BeginIndex[n];
262  }
263  }
264 }
265 
266 //----------------------------------------------------------------------
267 // Pass to the last pixel on the previous line
268 //----------------------------------------------------------------------
269 template< typename TImage >
270 inline
271 void
274 {
275  this->m_Position += this->m_OffsetTable[m_Direction]
276  * ( this->m_EndIndex[m_Direction] - 1 - this->m_PositionIndex[m_Direction] );
277 
278  this->m_PositionIndex[m_Direction] = this->m_EndIndex[m_Direction] - 1;
279 
280  for ( unsigned int n = 0; n < TImage::ImageDimension; n++ )
281  {
282  this->m_Remaining = false;
283 
284  if ( n == m_Direction )
285  {
286  continue;
287  }
288 
289  this->m_PositionIndex[n]--;
290  if ( this->m_PositionIndex[n] >= this->m_BeginIndex[n] )
291  {
292  this->m_Position -= this->m_OffsetTable[n];
293  this->m_Remaining = true;
294  break;
295  }
296  else
297  {
298  this->m_Position += this->m_OffsetTable[n] * ( this->m_Region.GetSize()[n] - 1 );
299  this->m_PositionIndex[n] = this->m_EndIndex[n] - 1;
300  }
301  }
302 }
303 } // end namespace itk
304 
305 #ifndef ITK_MANUAL_INSTANTIATION
306 #include "itkImageLinearConstIteratorWithIndex.hxx"
307 #endif
308 
309 #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)