ITK  4.4.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 {
102 template< typename TImage >
104 {
105 public:
109 
114  typedef typename TImage::IndexType IndexType;
115 
120  typedef typename TImage::RegionType RegionType;
121 
126  typedef TImage ImageType;
127 
131  typedef typename TImage::PixelContainer PixelContainer;
132  typedef typename PixelContainer::Pointer PixelContainerPointer;
133 
136 
139  ImageLinearConstIteratorWithIndex(const ImageType *ptr, const RegionType & region);
140 
149 
152  inline void NextLine(void);
153 
156  inline void PreviousLine(void);
157 
160  void GoToBeginOfLine(void);
161 
164  void GoToReverseBeginOfLine(void);
165 
168  void GoToEndOfLine(void);
169 
171  inline bool IsAtEndOfLine(void)
172  {
173  return this->m_PositionIndex[m_Direction] >= this->m_EndIndex[m_Direction];
174  }
175 
177  inline bool IsAtReverseEndOfLine(void)
178  {
179  return this->m_PositionIndex[m_Direction] < this->m_BeginIndex[m_Direction];
180  }
181 
183  inline void SetDirection(unsigned int direction)
184  {
185  if ( direction >= TImage::ImageDimension )
186  {
187  itkGenericExceptionMacro(
188  << "In image of dimension " << TImage::ImageDimension << " Direction " << direction << " sas selected");
189  }
190  m_Direction = direction;
191  m_Jump = this->m_OffsetTable[m_Direction];
192  }
194 
196  unsigned int GetDirection()
197  {
198  return m_Direction;
199  }
200 
203  inline Self & operator++()
204  {
205  this->m_PositionIndex[m_Direction]++;
206  this->m_Position += m_Jump;
207  return *this;
208  }
210 
213  inline Self & operator--()
214  {
215  this->m_PositionIndex[m_Direction]--;
216  this->m_Position -= m_Jump;
217  return *this;
218  }
220 
221 private:
223  unsigned int m_Direction;
224 };
225 
226 //----------------------------------------------------------------------
227 // Go to next line
228 //----------------------------------------------------------------------
229 template< class TImage >
230 inline
231 void
234 {
235  this->m_Position -= this->m_OffsetTable[m_Direction]
236  * ( this->m_PositionIndex[m_Direction] - this->m_BeginIndex[m_Direction] );
237 
238  this->m_PositionIndex[m_Direction] = this->m_BeginIndex[m_Direction];
239 
240  for ( unsigned int n = 0; n < TImage::ImageDimension; n++ )
241  {
242  this->m_Remaining = false;
243 
244  if ( n == m_Direction )
245  {
246  continue;
247  }
248 
249  this->m_PositionIndex[n]++;
250  if ( this->m_PositionIndex[n] < this->m_EndIndex[n] )
251  {
252  this->m_Position += this->m_OffsetTable[n];
253  this->m_Remaining = true;
254  break;
255  }
256  else
257  {
258  this->m_Position -= this->m_OffsetTable[n] * ( this->m_Region.GetSize()[n] - 1 );
259  this->m_PositionIndex[n] = this->m_BeginIndex[n];
260  }
261  }
262 }
263 
264 //----------------------------------------------------------------------
265 // Pass to the last pixel on the previous line
266 //----------------------------------------------------------------------
267 template< class TImage >
268 inline
269 void
272 {
273  this->m_Position += this->m_OffsetTable[m_Direction]
274  * ( this->m_EndIndex[m_Direction] - 1 - this->m_PositionIndex[m_Direction] );
275 
276  this->m_PositionIndex[m_Direction] = this->m_EndIndex[m_Direction] - 1;
277 
278  for ( unsigned int n = 0; n < TImage::ImageDimension; n++ )
279  {
280  this->m_Remaining = false;
281 
282  if ( n == m_Direction )
283  {
284  continue;
285  }
286 
287  this->m_PositionIndex[n]--;
288  if ( this->m_PositionIndex[n] >= this->m_BeginIndex[n] )
289  {
290  this->m_Position -= this->m_OffsetTable[n];
291  this->m_Remaining = true;
292  break;
293  }
294  else
295  {
296  this->m_Position += this->m_OffsetTable[n] * ( this->m_Region.GetSize()[n] - 1 );
297  this->m_PositionIndex[n] = this->m_EndIndex[n] - 1;
298  }
299  }
300 }
301 } // end namespace itk
302 
303 #ifndef ITK_MANUAL_INSTANTIATION
304 #include "itkImageLinearConstIteratorWithIndex.hxx"
305 #endif
306 
307 #endif
308