ITK  5.2.0
Insight Toolkit
itkImageLinearConstIteratorWithIndex.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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 
149  {
151  }
152 
155  inline void
156  NextLine();
157 
160  inline void
161  PreviousLine();
162 
165  void
166  GoToBeginOfLine();
167 
170  void
171  GoToReverseBeginOfLine();
172 
175  void
176  GoToEndOfLine();
177 
179  inline bool
181  {
182  return this->m_PositionIndex[m_Direction] >= this->m_EndIndex[m_Direction];
183  }
184 
186  inline bool
188  {
189  return this->m_PositionIndex[m_Direction] < this->m_BeginIndex[m_Direction];
190  }
191 
193  inline void
194  SetDirection(unsigned int direction)
195  {
196  if (direction >= TImage::ImageDimension)
197  {
198  itkGenericExceptionMacro(<< "In image of dimension " << TImage::ImageDimension << " Direction " << direction
199  << " sas selected");
200  }
201  m_Direction = direction;
202  m_Jump = this->m_OffsetTable[m_Direction];
203  }
205 
207  unsigned int
209  {
210  return m_Direction;
211  }
212 
215  inline Self &
217  {
218  this->m_PositionIndex[m_Direction]++;
219  this->m_Position += m_Jump;
220  return *this;
221  }
223 
226  inline Self &
228  {
229  this->m_PositionIndex[m_Direction]--;
230  this->m_Position -= m_Jump;
231  return *this;
232  }
234 
235 private:
236  OffsetValueType m_Jump{ 0 };
237  unsigned int m_Direction{ 0 };
238 };
239 
240 //----------------------------------------------------------------------
241 // Go to next line
242 //----------------------------------------------------------------------
243 template <typename TImage>
244 inline void
246 {
247  this->m_Position -=
248  this->m_OffsetTable[m_Direction] * (this->m_PositionIndex[m_Direction] - this->m_BeginIndex[m_Direction]);
249 
250  this->m_PositionIndex[m_Direction] = this->m_BeginIndex[m_Direction];
251 
252  for (unsigned int n = 0; n < TImage::ImageDimension; n++)
253  {
254  this->m_Remaining = false;
255 
256  if (n == m_Direction)
257  {
258  continue;
259  }
260 
261  this->m_PositionIndex[n]++;
262  if (this->m_PositionIndex[n] < this->m_EndIndex[n])
263  {
264  this->m_Position += this->m_OffsetTable[n];
265  this->m_Remaining = true;
266  break;
267  }
268  else
269  {
270  this->m_Position -= this->m_OffsetTable[n] * (this->m_Region.GetSize()[n] - 1);
271  this->m_PositionIndex[n] = this->m_BeginIndex[n];
272  }
273  }
274 }
275 
276 //----------------------------------------------------------------------
277 // Pass to the last pixel on the previous line
278 //----------------------------------------------------------------------
279 template <typename TImage>
280 inline void
282 {
283  this->m_Position +=
284  this->m_OffsetTable[m_Direction] * (this->m_EndIndex[m_Direction] - 1 - this->m_PositionIndex[m_Direction]);
285 
286  this->m_PositionIndex[m_Direction] = this->m_EndIndex[m_Direction] - 1;
287 
288  for (unsigned int n = 0; n < TImage::ImageDimension; n++)
289  {
290  this->m_Remaining = false;
291 
292  if (n == m_Direction)
293  {
294  continue;
295  }
296 
297  this->m_PositionIndex[n]--;
298  if (this->m_PositionIndex[n] >= this->m_BeginIndex[n])
299  {
300  this->m_Position -= this->m_OffsetTable[n];
301  this->m_Remaining = true;
302  break;
303  }
304  else
305  {
306  this->m_Position += this->m_OffsetTable[n] * (this->m_Region.GetSize()[n] - 1);
307  this->m_PositionIndex[n] = this->m_EndIndex[n] - 1;
308  }
309  }
310 }
311 } // end namespace itk
312 
313 #ifndef ITK_MANUAL_INSTANTIATION
314 # include "itkImageLinearConstIteratorWithIndex.hxx"
315 #endif
316 
317 #endif
itk::ImageLinearConstIteratorWithIndex::operator--
Self & operator--()
Definition: itkImageLinearConstIteratorWithIndex.h:227
itk::ImageConstIteratorWithIndex< TImageType >::PixelContainerPointer
typename PixelContainer::Pointer PixelContainerPointer
Definition: itkImageConstIteratorWithIndex.h:122
itk::ImageConstIteratorWithIndex< TImageType >::OffsetValueType
typename OffsetType::OffsetValueType OffsetValueType
Definition: itkImageConstIteratorWithIndex.h:137
itkImageConstIteratorWithIndex.h
itk::ImageLinearConstIteratorWithIndex::operator++
Self & operator++()
Definition: itkImageLinearConstIteratorWithIndex.h:216
itk::ImageLinearConstIteratorWithIndex::SetDirection
void SetDirection(unsigned int direction)
Definition: itkImageLinearConstIteratorWithIndex.h:194
itk::ImageLinearConstIteratorWithIndex::IsAtEndOfLine
bool IsAtEndOfLine() const
Definition: itkImageLinearConstIteratorWithIndex.h:180
itk::ImageConstIteratorWithIndex< TImageType >::IndexType
typename TImageType ::IndexType IndexType
Definition: itkImageConstIteratorWithIndex.h:105
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::ImageLinearConstIteratorWithIndex::IsAtReverseEndOfLine
bool IsAtReverseEndOfLine() const
Definition: itkImageLinearConstIteratorWithIndex.h:187
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::ImageLinearConstIteratorWithIndex::NextLine
void NextLine()
Definition: itkImageLinearConstIteratorWithIndex.h:245
itk::ImageConstIteratorWithIndex
A base class for multi-dimensional iterators templated over image type that are designed to efficient...
Definition: itkImageConstIteratorWithIndex.h:92
itk::ImageLinearConstIteratorWithIndex::ImageLinearConstIteratorWithIndex
ImageLinearConstIteratorWithIndex(const ImageConstIteratorWithIndex< TImage > &it)
Definition: itkImageLinearConstIteratorWithIndex.h:148
itk::ImageLinearConstIteratorWithIndex::ImageLinearConstIteratorWithIndex
ImageLinearConstIteratorWithIndex()
Definition: itkImageLinearConstIteratorWithIndex.h:133
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ImageConstIteratorWithIndex< TImageType >::RegionType
typename TImageType ::RegionType RegionType
Definition: itkImageConstIteratorWithIndex.h:113
itk::ImageConstIteratorWithIndex< TImageType >::ImageType
TImageType ImageType
Definition: itkImageConstIteratorWithIndex.h:116
itk::ImageConstIteratorWithIndex< TImageType >::PixelContainer
typename TImageType ::PixelContainer PixelContainer
Definition: itkImageConstIteratorWithIndex.h:121
itk::ImageLinearConstIteratorWithIndex
A multi-dimensional image iterator that visits image pixels within a region in a "scan-line" order.
Definition: itkImageLinearConstIteratorWithIndex.h:101
itk::ImageLinearConstIteratorWithIndex::PreviousLine
void PreviousLine()
Definition: itkImageLinearConstIteratorWithIndex.h:281
itk::ImageConstIteratorWithIndex::operator=
Self & operator=(const Self &it)
itk::ImageLinearConstIteratorWithIndex::GetDirection
unsigned int GetDirection()
Definition: itkImageLinearConstIteratorWithIndex.h:208