ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkImageRegionIterator.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 itkImageRegionIterator_h
19#define itkImageRegionIterator_h
20
21#include "itkImageIterator.h"
22#include <type_traits> // For remove_const_t.
23
24namespace itk
25{
110template <typename TImage>
111class ITK_TEMPLATE_EXPORT ImageRegionIterator : public ImageIterator<TImage>
112{
113 template <typename>
115
116public:
120
126
128 using typename Superclass::IndexType;
129 using typename Superclass::SizeType;
130 using typename Superclass::OffsetType;
131 using typename Superclass::RegionType;
132 using typename Superclass::ImageType;
133 using typename Superclass::PixelContainer;
135 using typename Superclass::InternalPixelType;
136 using typename Superclass::PixelType;
137 using typename Superclass::AccessorType;
138
140 itkOverrideGetNameOfClassMacro(ImageRegionIterator);
141
144
147 ImageRegionIterator(TImage * ptr, const RegionType & region)
148 : Superclass(ptr, region)
150 , m_SpanEndOffset(this->m_BeginOffset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]))
151 {}
152
159 template <typename TOtherImage, std::enable_if_t<detail::IsImageIteratorConvertible_v<TOtherImage, TImage>, int> = 0>
161 : Superclass(it)
162 {
163 IndexType ind = this->GetIndex();
164 m_SpanEndOffset = this->m_Offset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]) -
165 (ind[0] - this->m_Region.GetIndex()[0]);
166 m_SpanBeginOffset = m_SpanEndOffset - static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
167 }
168
170 template <typename TOtherImage, std::enable_if_t<detail::IsImageIteratorConvertible_v<TOtherImage, TImage>, int> = 0>
176
179 void
181 {
183
184 // reset the span offsets
186 m_SpanEndOffset = this->m_BeginOffset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
187 }
188
191 void
193 {
195
196 // reset the span offsets
198 m_SpanBeginOffset = m_SpanEndOffset - static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
199 }
200
204 void
205 SetIndex(const IndexType & ind) override
206 {
208 m_SpanEndOffset = this->m_Offset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]) -
209 (ind[0] - this->m_Region.GetIndex()[0]);
210 m_SpanBeginOffset = m_SpanEndOffset - static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
211 }
212
220 Self &
222 {
223 if (++this->m_Offset >= m_SpanEndOffset)
224 {
225 this->Increment();
226 }
227 return *this;
228 }
229
237 Self &
239 {
240 if (--this->m_Offset < m_SpanBeginOffset)
241 {
242 this->Decrement();
243 }
244 return *this;
245 }
246
247protected:
248 OffsetValueType m_SpanBeginOffset{}; // one pixel before the beginning of the span
249 // (row)
250 OffsetValueType m_SpanEndOffset{}; // one pixel past the end of the span (row)
251
252private:
253 void
254 Increment(); // advance in a direction other than the fastest moving
255
256 void
257 Decrement(); // go back in a direction other than the fastest moving
258};
259
260// Deduction guides for class template argument deduction (CTAD).
261template <typename TImage>
263
264template <typename TImage>
266
275template <typename TImage>
276class ITK_TEMPLATE_EXPORT ImageRegionConstIterator : public ImageRegionIterator<std::add_const_t<TImage>>
277{
278public:
282
284 itkOverrideGetNameOfClassMacro(ImageRegionConstIterator);
285
287
289
292 : Superclass(it)
293 {}
294};
295
296// Deduction guides for class template argument deduction (CTAD).
297template <typename TImage>
298ImageRegionConstIterator(const TImage *, const typename TImage::RegionType &) -> ImageRegionConstIterator<TImage>;
299
300template <typename TImage>
301ImageRegionConstIterator(SmartPointer<TImage>, const typename TImage::RegionType &)
303
304template <typename TImage>
306
307} // end namespace itk
308
309#ifndef ITK_MANUAL_INSTANTIATION
310# include "itkImageRegionIterator.hxx"
311#endif
312
313#endif
A multi-dimensional image iterator templated over image type.
typename TImage::AccessorType AccessorType
virtual void SetIndex(const IndexType &ind)
detail::IteratorImageType_t< TImage > ImageType
static constexpr unsigned int ImageIteratorDimension
typename TImage::OffsetType OffsetType
typename TImage::InternalPixelType InternalPixelType
typename PixelContainer::Pointer PixelContainerPointer
typename TImage::IndexType IndexType
OffsetValueType m_Offset
OffsetValueType m_EndOffset
OffsetValueType m_BeginOffset
typename TImage::SizeType SizeType
typename TImage::RegionType RegionType
friend class ImageIterator
typename TImage::PixelType PixelType
typename TImage::PixelContainer PixelContainer
Read-only ImageRegionIterator: ImageRegionConstIterator<TImage> behaves as ImageRegionIterator<const ...
ImageRegionIterator< std::add_const_t< TImage > > Superclass
ImageRegionConstIterator(const Superclass &it)
A multi-dimensional iterator templated over image type that walks a region of pixels.
ImageRegionIterator(TImage *ptr, const RegionType &region)
ImageIterator< TImage > Superclass
ImageRegionIterator(const ImageIterator< TOtherImage > &it)
ImageRegionIterator(const ImageRegionIterator< TOtherImage > &it)
void SetIndex(const IndexType &ind) override
Implements transparent reference counting.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
ImageRegionIterator(SmartPointer< TImage >, const typename TImage::RegionType &) -> ImageRegionIterator< TImage >
long OffsetValueType
Definition itkIntTypes.h:89
ImageRegionConstIterator(const TImage *, const typename TImage::RegionType &) -> ImageRegionConstIterator< TImage >