ITK  5.4.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  * https://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 #include <type_traits> // For remove_const_t.
23 
24 namespace itk
25 {
63 template <typename TImage>
64 class ITK_TEMPLATE_EXPORT ImageScanlineConstIterator : public ImageConstIterator<TImage>
65 {
66 public:
70 
75  static constexpr unsigned int ImageIteratorDimension = Superclass::ImageIteratorDimension;
76 
83  using typename Superclass::IndexType;
84  using typename Superclass::SizeType;
85  using typename Superclass::OffsetType;
86  using typename Superclass::RegionType;
87  using typename Superclass::ImageType;
88  using typename Superclass::PixelContainer;
89  using typename Superclass::PixelContainerPointer;
90  using typename Superclass::InternalPixelType;
91  using typename Superclass::PixelType;
92  using typename Superclass::AccessorType;
93 
95  itkOverrideGetNameOfClassMacro(ImageScanlineConstIterator);
96 
99  : ImageConstIterator<TImage>()
100  {
101  m_SpanBeginOffset = 0;
102  m_SpanEndOffset = 0;
103  }
108  ImageScanlineConstIterator(const TImage * ptr, const RegionType & region)
109  : ImageConstIterator<TImage>(ptr, region)
110  {
111  m_SpanBeginOffset = this->m_BeginOffset;
112  m_SpanEndOffset = this->m_BeginOffset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
113  }
123  {
125 
126  IndexType ind = this->GetIndex();
127  m_SpanEndOffset = this->m_Offset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]) -
128  (ind[0] - this->m_Region.GetIndex()[0]);
129  m_SpanBeginOffset = m_SpanEndOffset - static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
130  }
131 
139  {
141 
142  IndexType ind = this->GetIndex();
143  m_SpanEndOffset = this->m_Offset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]) -
144  (ind[0] - this->m_Region.GetIndex()[0]);
145  m_SpanBeginOffset = m_SpanEndOffset - static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
146  }
147 
150  void
152  {
153  Superclass::GoToBegin();
154 
155  // reset the span offsets
156  m_SpanBeginOffset = this->m_BeginOffset;
157  m_SpanEndOffset = this->m_BeginOffset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
158  }
159 
165  void
167  {
168  Superclass::GoToEnd();
169 
170  // reset the span offsets
171  m_SpanEndOffset = this->m_EndOffset;
172  m_SpanBeginOffset = m_SpanEndOffset - static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
173  }
174 
182  void
184  {
185  this->m_Offset = m_SpanBeginOffset;
186  }
187 
196  void
198  {
199  this->m_Offset = m_SpanEndOffset;
200  }
201 
204  inline bool
206  {
207  return this->m_Offset >= m_SpanEndOffset;
208  }
209 
210 
216  void
217  SetIndex(const IndexType & ind) override
218  {
219  Superclass::SetIndex(ind);
220  m_SpanEndOffset = this->m_Offset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]) -
221  (ind[0] - this->m_Region.GetIndex()[0]);
222  m_SpanBeginOffset = m_SpanEndOffset - static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
223  }
234  void
235  NextLine();
236 
244  Self &
246  {
247  itkAssertInDebugAndIgnoreInReleaseMacro(!this->IsAtEndOfLine());
248  ++this->m_Offset;
249  return *this;
250  }
256  Self &
258  {
259  itkAssertInDebugAndIgnoreInReleaseMacro(!this->IsAtEndOfLine());
260  --this->m_Offset;
261  return *this;
262  }
266 protected:
267  OffsetValueType m_SpanBeginOffset{}; // one pixel the beginning of the scanline
268  OffsetValueType m_SpanEndOffset{}; // one pixel past the end of the scanline
269 };
270 
271 // Deduction guide for class template argument deduction (CTAD).
272 template <typename TImage>
273 ImageScanlineConstIterator(SmartPointer<TImage>, const typename TImage::RegionType &)
274  ->ImageScanlineConstIterator<std::remove_const_t<TImage>>;
275 
276 } // end namespace itk
277 
278 #ifndef ITK_MANUAL_INSTANTIATION
279 # include "itkImageScanlineConstIterator.hxx"
280 #endif
281 
282 #endif
itk::ImageScanlineConstIterator::GoToEndOfLine
void GoToEndOfLine()
Definition: itkImageScanlineConstIterator.h:197
itkImageIterator.h
itk::ImageConstIterator::PixelType
typename TImage::PixelType PixelType
Definition: itkImageConstIterator.h:124
itk::ImageScanlineConstIterator::ImageScanlineConstIterator
ImageScanlineConstIterator()
Definition: itkImageScanlineConstIterator.h:98
itk::ImageScanlineConstIterator::GoToBeginOfLine
void GoToBeginOfLine()
Definition: itkImageScanlineConstIterator.h:183
itk::ImageConstIterator::OffsetType
typename TImage::OffsetType OffsetType
Definition: itkImageConstIterator.h:106
itk::ImageScanlineConstIterator::operator--
Self & operator--()
Definition: itkImageScanlineConstIterator.h:257
itk::ImageConstIterator::AccessorType
typename TImage::AccessorType AccessorType
Definition: itkImageConstIterator.h:128
itk::ImageScanlineConstIterator
ImageScanlineConstIterator(SmartPointer< TImage >, const typename TImage::RegionType &) -> ImageScanlineConstIterator< std::remove_const_t< TImage >>
itk::ImageConstIterator::RegionType
typename TImage::RegionType RegionType
Definition: itkImageConstIterator.h:109
itk::ImageScanlineConstIterator::operator++
Self & operator++()
Definition: itkImageScanlineConstIterator.h:245
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::ImageConstIterator::operator=
Self & operator=(const Self &it)
Definition: itkImageConstIterator.h:185
itk::ImageScanlineConstIterator::ImageScanlineConstIterator
ImageScanlineConstIterator(const ImageIterator< TImage > &it)
Definition: itkImageScanlineConstIterator.h:122
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::ImageScanlineConstIterator
ImageScanlineConstIterator(const TImage *ptr, const RegionType &region)
Definition: itkImageScanlineConstIterator.h:108
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::ImageScanlineConstIterator::ImageScanlineConstIterator
ImageScanlineConstIterator(const ImageConstIterator< TImage > &it)
Definition: itkImageScanlineConstIterator.h:138
itk::OffsetValueType
long OffsetValueType
Definition: itkIntTypes.h:94
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::ImageScanlineConstIterator::GoToEnd
void GoToEnd()
Definition: itkImageScanlineConstIterator.h:166
itk::ImageScanlineConstIterator::IsAtEndOfLine
bool IsAtEndOfLine() const
Definition: itkImageScanlineConstIterator.h:205
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
AddImageFilter
Definition: itkAddImageFilter.h:81
itk::ImageScanlineConstIterator
A multi-dimensional iterator templated over image type that walks a region of pixels,...
Definition: itkImageScanlineConstIterator.h:64
itk::ImageScanlineConstIterator::SetIndex
void SetIndex(const IndexType &ind) override
Definition: itkImageScanlineConstIterator.h:217
itk::ImageScanlineConstIterator::GoToBegin
void GoToBegin()
Definition: itkImageScanlineConstIterator.h:151