ITK  6.0.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
24namespace itk
25{
63template <typename TImage>
64class ITK_TEMPLATE_EXPORT ImageScanlineConstIterator : public ImageConstIterator<TImage>
65{
66public:
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;
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
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 }
266protected:
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).
272template <typename TImage>
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
Pixel-wise addition of two images.
A multi-dimensional image iterator templated over image type.
typename TImage::IndexType IndexType
typename TImage::PixelContainer PixelContainer
typename TImage::OffsetType OffsetType
typename TImage::InternalPixelType InternalPixelType
typename PixelContainer::Pointer PixelContainerPointer
typename TImage::AccessorType AccessorType
typename TImage::RegionType RegionType
Self & operator=(const Self &it)
typename TImage::PixelType PixelType
A multi-dimensional iterator templated over image type.
A multi-dimensional iterator templated over image type that walks a region of pixels,...
ImageScanlineConstIterator(const ImageConstIterator< TImage > &it)
ImageScanlineConstIterator(const ImageIterator< TImage > &it)
ImageScanlineConstIterator(const TImage *ptr, const RegionType &region)
void SetIndex(const IndexType &ind) override
Implements transparent reference counting.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
ImageScanlineConstIterator(SmartPointer< TImage >, const typename TImage::RegionType &) -> ImageScanlineConstIterator< std::remove_const_t< TImage > >
long OffsetValueType
Definition: itkIntTypes.h:97