ITK  5.0.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 >
101 class ITK_TEMPLATE_EXPORT ImageLinearConstIteratorWithIndex:public ImageConstIteratorWithIndex< TImage >
102 {
103 public:
107 
112  using IndexType = typename TImage::IndexType;
113 
118  using RegionType = typename TImage::RegionType;
119 
124  using ImageType = TImage;
125 
129  using PixelContainer = typename TImage::PixelContainer;
130  using PixelContainerPointer = typename PixelContainer::Pointer;
131 
134  ImageConstIteratorWithIndex< TImage >()
135 
136  {}
137 
140  ImageLinearConstIteratorWithIndex(const ImageType *ptr, const RegionType & region);
141 
150 
153  inline void NextLine();
154 
157  inline void PreviousLine();
158 
161  void GoToBeginOfLine();
162 
165  void GoToReverseBeginOfLine();
166 
169  void GoToEndOfLine();
170 
172  inline bool IsAtEndOfLine() const
173  {
174  return this->m_PositionIndex[m_Direction] >= this->m_EndIndex[m_Direction];
175  }
176 
178  inline bool IsAtReverseEndOfLine() const
179  {
180  return this->m_PositionIndex[m_Direction] < this->m_BeginIndex[m_Direction];
181  }
182 
184  inline void SetDirection(unsigned int direction)
185  {
186  if ( direction >= TImage::ImageDimension )
187  {
188  itkGenericExceptionMacro(
189  << "In image of dimension " << TImage::ImageDimension << " Direction " << direction << " sas selected");
190  }
191  m_Direction = direction;
192  m_Jump = this->m_OffsetTable[m_Direction];
193  }
195 
197  unsigned int GetDirection()
198  {
199  return m_Direction;
200  }
201 
204  inline Self & operator++()
205  {
206  this->m_PositionIndex[m_Direction]++;
207  this->m_Position += m_Jump;
208  return *this;
209  }
211 
214  inline Self & operator--()
215  {
216  this->m_PositionIndex[m_Direction]--;
217  this->m_Position -= m_Jump;
218  return *this;
219  }
221 
222 private:
223  OffsetValueType m_Jump{0};
224  unsigned int m_Direction{0};
225 };
226 
227 //----------------------------------------------------------------------
228 // Go to next line
229 //----------------------------------------------------------------------
230 template< typename TImage >
231 inline
232 void
235 {
236  this->m_Position -= this->m_OffsetTable[m_Direction]
237  * ( this->m_PositionIndex[m_Direction] - this->m_BeginIndex[m_Direction] );
238 
239  this->m_PositionIndex[m_Direction] = this->m_BeginIndex[m_Direction];
240 
241  for ( unsigned int n = 0; n < TImage::ImageDimension; n++ )
242  {
243  this->m_Remaining = false;
244 
245  if ( n == m_Direction )
246  {
247  continue;
248  }
249 
250  this->m_PositionIndex[n]++;
251  if ( this->m_PositionIndex[n] < this->m_EndIndex[n] )
252  {
253  this->m_Position += this->m_OffsetTable[n];
254  this->m_Remaining = true;
255  break;
256  }
257  else
258  {
259  this->m_Position -= this->m_OffsetTable[n] * ( this->m_Region.GetSize()[n] - 1 );
260  this->m_PositionIndex[n] = this->m_BeginIndex[n];
261  }
262  }
263 }
264 
265 //----------------------------------------------------------------------
266 // Pass to the last pixel on the previous line
267 //----------------------------------------------------------------------
268 template< typename TImage >
269 inline
270 void
273 {
274  this->m_Position += this->m_OffsetTable[m_Direction]
275  * ( this->m_EndIndex[m_Direction] - 1 - this->m_PositionIndex[m_Direction] );
276 
277  this->m_PositionIndex[m_Direction] = this->m_EndIndex[m_Direction] - 1;
278 
279  for ( unsigned int n = 0; n < TImage::ImageDimension; n++ )
280  {
281  this->m_Remaining = false;
282 
283  if ( n == m_Direction )
284  {
285  continue;
286  }
287 
288  this->m_PositionIndex[n]--;
289  if ( this->m_PositionIndex[n] >= this->m_BeginIndex[n] )
290  {
291  this->m_Position -= this->m_OffsetTable[n];
292  this->m_Remaining = true;
293  break;
294  }
295  else
296  {
297  this->m_Position += this->m_OffsetTable[n] * ( this->m_Region.GetSize()[n] - 1 );
298  this->m_PositionIndex[n] = this->m_EndIndex[n] - 1;
299  }
300  }
301 }
302 } // end namespace itk
303 
304 #ifndef ITK_MANUAL_INSTANTIATION
305 #include "itkImageLinearConstIteratorWithIndex.hxx"
306 #endif
307 
308 #endif
ImageLinearConstIteratorWithIndex(const ImageConstIteratorWithIndex< TImage > &it)
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)