ITK  5.2.0
Insight Toolkit
itkImageScanlineConstIterator.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 itkImageScanlineConstIterator_h
19 #define itkImageScanlineConstIterator_h
20 
21 #include "itkImageIterator.h"
22 
23 namespace itk
24 {
62 template <typename TImage>
63 class ITK_TEMPLATE_EXPORT ImageScanlineConstIterator : public ImageConstIterator<TImage>
64 {
65 public:
69 
74  static constexpr unsigned int ImageIteratorDimension = Superclass::ImageIteratorDimension;
75 
82  using IndexType = typename Superclass::IndexType;
83  using SizeType = typename Superclass::SizeType;
86  using ImageType = typename Superclass::ImageType;
90  using PixelType = typename Superclass::PixelType;
92 
95 
98  : ImageConstIterator<TImage>()
99  {
100  m_SpanBeginOffset = 0;
101  m_SpanEndOffset = 0;
102  }
104 
107  ImageScanlineConstIterator(const ImageType * ptr, const RegionType & region)
108  : ImageConstIterator<TImage>(ptr, region)
109  {
110  m_SpanBeginOffset = this->m_BeginOffset;
111  m_SpanEndOffset = this->m_BeginOffset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
112  }
114 
122  {
124 
125  IndexType ind = this->GetIndex();
126  m_SpanEndOffset = this->m_Offset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]) -
127  (ind[0] - this->m_Region.GetIndex()[0]);
128  m_SpanBeginOffset = m_SpanEndOffset - static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
129  }
130 
138  {
140 
141  IndexType ind = this->GetIndex();
142  m_SpanEndOffset = this->m_Offset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]) -
143  (ind[0] - this->m_Region.GetIndex()[0]);
144  m_SpanBeginOffset = m_SpanEndOffset - static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
145  }
146 
149  void
151  {
152  Superclass::GoToBegin();
153 
154  // reset the span offsets
155  m_SpanBeginOffset = this->m_BeginOffset;
156  m_SpanEndOffset = this->m_BeginOffset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
157  }
158 
164  void
166  {
167  Superclass::GoToEnd();
168 
169  // reset the span offsets
170  m_SpanEndOffset = this->m_EndOffset;
171  m_SpanBeginOffset = m_SpanEndOffset - static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
172  }
173 
181  void
183  {
184  this->m_Offset = m_SpanBeginOffset;
185  }
186 
195  void
197  {
198  this->m_Offset = m_SpanEndOffset;
199  }
200 
203  inline bool
205  {
206  return this->m_Offset >= m_SpanEndOffset;
207  }
208 
209 
215  void
216  SetIndex(const IndexType & ind) override
217  {
218  Superclass::SetIndex(ind);
219  m_SpanEndOffset = this->m_Offset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]) -
220  (ind[0] - this->m_Region.GetIndex()[0]);
221  m_SpanBeginOffset = m_SpanEndOffset - static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
222  }
224 
233  inline void
235  {
236  this->Increment();
237  };
239 
247  Self &
249  {
250  itkAssertInDebugAndIgnoreInReleaseMacro(!this->IsAtEndOfLine());
251  ++this->m_Offset;
252  return *this;
253  }
255 
259  Self &
261  {
262  itkAssertInDebugAndIgnoreInReleaseMacro(!this->IsAtEndOfLine());
263  --this->m_Offset;
264  return *this;
265  }
267 
268 
269 protected:
270  OffsetValueType m_SpanBeginOffset; // one pixel the beginning of the scanline
271  OffsetValueType m_SpanEndOffset; // one pixel past the end of the scanline
272 
273 private:
274  /* Move to the beginning of the next scanline
275  */
276  void
277  Increment();
278 };
279 } // end namespace itk
280 
281 #ifndef ITK_MANUAL_INSTANTIATION
282 # include "itkImageScanlineConstIterator.hxx"
283 #endif
284 
285 #endif
itk::ImageScanlineConstIterator::GoToEndOfLine
void GoToEndOfLine()
Definition: itkImageScanlineConstIterator.h:196
itkImageIterator.h
itk::ImageConstIterator::SizeType
typename TImage::SizeType SizeType
Definition: itkImageConstIterator.h:103
itk::ImageConstIterator::PixelType
typename TImage::PixelType PixelType
Definition: itkImageConstIterator.h:124
itk::ImageScanlineConstIterator::ImageScanlineConstIterator
ImageScanlineConstIterator()
Definition: itkImageScanlineConstIterator.h:97
itk::ImageScanlineConstIterator::GoToBeginOfLine
void GoToBeginOfLine()
Definition: itkImageScanlineConstIterator.h:182
itk::ImageScanlineConstIterator::NextLine
void NextLine()
Definition: itkImageScanlineConstIterator.h:234
itk::ImageConstIterator::OffsetType
typename TImage::OffsetType OffsetType
Definition: itkImageConstIterator.h:106
itk::ImageScanlineConstIterator::operator--
Self & operator--()
Definition: itkImageScanlineConstIterator.h:260
itk::ImageConstIterator::AccessorType
typename TImage::AccessorType AccessorType
Definition: itkImageConstIterator.h:128
itk::ImageConstIterator::RegionType
typename TImage::RegionType RegionType
Definition: itkImageConstIterator.h:109
itk::ImageScanlineConstIterator::operator++
Self & operator++()
Definition: itkImageScanlineConstIterator.h:248
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::ImageScanlineConstIterator::ImageScanlineConstIterator
ImageScanlineConstIterator(const ImageType *ptr, const RegionType &region)
Definition: itkImageScanlineConstIterator.h:107
itk::ImageScanlineConstIterator::m_SpanBeginOffset
OffsetValueType m_SpanBeginOffset
Definition: itkImageScanlineConstIterator.h:270
itk::ImageConstIterator::operator=
Self & operator=(const Self &it)
Definition: itkImageConstIterator.h:185
itk::ImageScanlineConstIterator::ImageScanlineConstIterator
ImageScanlineConstIterator(const ImageIterator< TImage > &it)
Definition: itkImageScanlineConstIterator.h:121
itk::ImageConstIterator::PixelContainerPointer
typename PixelContainer::Pointer PixelContainerPointer
Definition: itkImageConstIterator.h:118
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::ImageScanlineConstIterator::m_SpanEndOffset
OffsetValueType m_SpanEndOffset
Definition: itkImageScanlineConstIterator.h:271
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::ImageScanlineConstIterator::ImageScanlineConstIterator
ImageScanlineConstIterator(const ImageConstIterator< TImage > &it)
Definition: itkImageScanlineConstIterator.h:137
itk::ImageConstIterator::InternalPixelType
typename TImage::InternalPixelType InternalPixelType
Definition: itkImageConstIterator.h:121
itk::ImageIterator
A multi-dimensional iterator templated over image type.
Definition: itkImageIterator.h:65
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ImageConstIterator
A multi-dimensional image iterator templated over image type.
Definition: itkImageConstIterator.h:84
itk::OffsetValueType
signed long OffsetValueType
Definition: itkIntTypes.h:94
itk::ImageScanlineConstIterator::GoToEnd
void GoToEnd()
Definition: itkImageScanlineConstIterator.h:165
itk::ImageScanlineConstIterator::IsAtEndOfLine
bool IsAtEndOfLine() const
Definition: itkImageScanlineConstIterator.h:204
itk::ImageConstIterator::ImageType
TImage ImageType
Definition: itkImageConstIterator.h:112
itk::ImageConstIterator::PixelContainer
typename TImage::PixelContainer PixelContainer
Definition: itkImageConstIterator.h:117
itk::ImageConstIterator::IndexType
typename TImage::IndexType IndexType
Definition: itkImageConstIterator.h:100
itk::ImageScanlineConstIterator
A multi-dimensional iterator templated over image type that walks a region of pixels,...
Definition: itkImageScanlineConstIterator.h:63
itk::ImageScanlineConstIterator::SetIndex
void SetIndex(const IndexType &ind) override
Definition: itkImageScanlineConstIterator.h:216
itk::ImageScanlineConstIterator::GoToBegin
void GoToBegin()
Definition: itkImageScanlineConstIterator.h:150