ITK  5.3.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 
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 typename Superclass::IndexType;
83  using typename Superclass::SizeType;
84  using typename Superclass::OffsetType;
85  using typename Superclass::RegionType;
86  using typename Superclass::ImageType;
87  using typename Superclass::PixelContainer;
88  using typename Superclass::PixelContainerPointer;
89  using typename Superclass::InternalPixelType;
90  using typename Superclass::PixelType;
91  using typename Superclass::AccessorType;
92 
95 
98  : ImageConstIterator<TImage>()
99  {
100  m_SpanBeginOffset = 0;
101  m_SpanEndOffset = 0;
102  }
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  }
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  }
233  void
234  NextLine();
235 
243  Self &
245  {
246  itkAssertInDebugAndIgnoreInReleaseMacro(!this->IsAtEndOfLine());
247  ++this->m_Offset;
248  return *this;
249  }
255  Self &
257  {
258  itkAssertInDebugAndIgnoreInReleaseMacro(!this->IsAtEndOfLine());
259  --this->m_Offset;
260  return *this;
261  }
265 protected:
266  OffsetValueType m_SpanBeginOffset; // one pixel the beginning of the scanline
267  OffsetValueType m_SpanEndOffset; // one pixel past the end of the scanline
268 };
269 } // end namespace itk
270 
271 #ifndef ITK_MANUAL_INSTANTIATION
272 # include "itkImageScanlineConstIterator.hxx"
273 #endif
274 
275 #endif
itk::ImageScanlineConstIterator::GoToEndOfLine
void GoToEndOfLine()
Definition: itkImageScanlineConstIterator.h:196
itkImageIterator.h
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::ImageConstIterator::OffsetType
typename TImage::OffsetType OffsetType
Definition: itkImageConstIterator.h:106
itk::ImageScanlineConstIterator::operator--
Self & operator--()
Definition: itkImageScanlineConstIterator.h:256
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:244
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:266
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:267
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::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: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
AddImageFilter
Definition: itkAddImageFilter.h:80
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