ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkImageIteratorWithIndex.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 itkImageIteratorWithIndex_h
19#define itkImageIteratorWithIndex_h
20
21#include "itkImageIterator.h"
22#include <memory>
23#include <type_traits> // For remove_const_t.
24
25namespace itk
26{
89template <typename TImage>
90class ITK_TEMPLATE_EXPORT ImageIteratorWithIndex
92 template <typename>
95public:
103 static constexpr unsigned int ImageDimension = TImage::ImageDimension;
104 static constexpr unsigned int ImageIteratorDimension = ImageDimension;
105
107 using IndexType = typename TImage::IndexType;
108 using IndexValueType = typename IndexType::IndexValueType;
109
111 using SizeType = typename TImage::SizeType;
112 using SizeValueType = typename SizeType::SizeValueType;
113
115 using RegionType = typename TImage::RegionType;
116
119
122 using PixelContainer = typename TImage::PixelContainer;
123 using PixelContainerPointer = typename PixelContainer::Pointer;
124
126 using InternalPixelType = typename TImage::InternalPixelType;
129 using PixelType = typename TImage::PixelType;
133 using AccessorType = typename TImage::AccessorType;
134 using AccessorFunctorType = typename TImage::AccessorFunctorType;
137 using OffsetType = typename TImage::OffsetType;
138 using OffsetValueType = typename OffsetType::OffsetValueType;
142
143 ImageIteratorWithIndex(const Self &) = default;
144 Self &
145 operator=(const Self &) = default;
146
149 ImageIteratorWithIndex(TImage * ptr, const RegionType & region);
152 template <typename TOtherImage, std::enable_if_t<detail::IsImageIteratorConvertible_v<TOtherImage, TImage>, int> = 0>
168
170 virtual ~ImageIteratorWithIndex() = default;
171
173 static constexpr unsigned int
175 {
176 return ImageDimension;
177 }
178
181 template <typename TOtherImage,
182 std::enable_if_t<std::is_same_v<std::remove_const_t<TOtherImage>, std::remove_const_t<TImage>>, int> = 0>
183 bool
185 {
186 // two iterators are the same if they "point to" the same memory location
187 return (m_Position) == (it.m_Position);
188 }
189
190#ifndef ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
191 template <typename TOtherImage,
192 std::enable_if_t<std::is_same_v<std::remove_const_t<TOtherImage>, std::remove_const_t<TImage>>, int> = 0>
193 bool
195 {
196 return !(this->operator==(it));
197 }
198#endif
199
202 template <typename TOtherImage,
203 std::enable_if_t<std::is_same_v<std::remove_const_t<TOtherImage>, std::remove_const_t<TImage>>, int> = 0>
204 bool
206 {
207 // an iterator is "less than" another if it "points to" a lower
208 // memory location
209 return (m_Position) <= (it.m_Position);
210 }
211
214 template <typename TOtherImage,
215 std::enable_if_t<std::is_same_v<std::remove_const_t<TOtherImage>, std::remove_const_t<TImage>>, int> = 0>
216 bool
218 {
219 // an iterator is "less than" another if it "points to" a lower
220 // memory location
221 return (m_Position) < (it.m_Position);
222 }
223
226 template <typename TOtherImage,
227 std::enable_if_t<std::is_same_v<std::remove_const_t<TOtherImage>, std::remove_const_t<TImage>>, int> = 0>
228 bool
230 {
231 // an iterator is "greater than" another if it "points to" a higher
232 // memory location
233 return (m_Position) >= (it.m_Position);
234 }
235
238 template <typename TOtherImage,
239 std::enable_if_t<std::is_same_v<std::remove_const_t<TOtherImage>, std::remove_const_t<TImage>>, int> = 0>
240 bool
243 // an iterator is "greater than" another if it "points to" a higher
244 // memory location
245 return (m_Position) > (it.m_Position);
250 [[nodiscard]] const IndexType &
251 GetIndex() const
252 {
253 return m_PositionIndex;
254 }
255
258 [[nodiscard]] const RegionType &
259 GetRegion() const
260 {
261 return m_Region;
262 }
263
266 void
267 SetIndex(const IndexType & ind)
268 {
269 m_Position = m_Image->GetBufferPointer() + m_Image->ComputeOffset(ind);
270 m_PositionIndex = ind;
271 }
272
274 [[nodiscard]] PixelType
275 Get() const
276 {
278 }
279
281 template <typename T = TImage, std::enable_if_t<std::is_same_v<T, TImage> && !std::is_const_v<T>, int> = 0>
282 void
283 Set(const PixelType & value) const
284 {
286 }
287
291 [[nodiscard]] const PixelType &
292 Value() const
293 {
294 return *m_Position;
295 }
296
300 template <typename T = TImage, std::enable_if_t<std::is_same_v<T, TImage> && !std::is_const_v<T>, int> = 0>
301 PixelType &
303 {
304 return *m_Position;
305 }
306
308 void
310
312 void
314
316 [[nodiscard]] bool
318 {
319 return !m_Remaining;
320 }
321
323 [[nodiscard]] bool
324 IsAtEnd() const
325 {
326 return !m_Remaining;
327 }
328
330 bool
332 {
333 return m_Remaining;
334 }
335
336protected: // made protected so other iterators can access
339 std::conditional_t<std::is_const_v<TImage>, const InternalPixelType, InternalPixelType>;
340
342
343 IndexType m_PositionIndex{ { 0 } }; // Index where we currently are
344 IndexType m_BeginIndex{ { 0 } }; // Index to start iterating over
345 IndexType m_EndIndex{ { 0 } }; // Index to finish iterating:
346 // one pixel past the end of each
347 // row, col, slice, etc....
348
349 RegionType m_Region{}; // region to iterate over
350
352
356
357 bool m_Remaining{ false };
358
361};
362
363// Deduction guides for class template argument deduction (CTAD).
364template <typename TImage>
366
376template <typename TImage>
377class ITK_TEMPLATE_EXPORT ImageConstIteratorWithIndex : public ImageIteratorWithIndex<std::add_const_t<TImage>>
378{
379public:
383
384 using Superclass::Superclass;
385
387
392};
393
394// Deduction guides for class template argument deduction (CTAD).
395template <typename TImage>
396ImageConstIteratorWithIndex(const TImage *, const typename TImage::RegionType &) -> ImageConstIteratorWithIndex<TImage>;
397
398template <typename TImage>
399ImageConstIteratorWithIndex(SmartPointer<TImage>, const typename TImage::RegionType &)
401
402template <typename TImage>
405
406} // end namespace itk
407
408#ifndef ITK_MANUAL_INSTANTIATION
409# include "itkImageIteratorWithIndex.hxx"
410#endif
411
412#endif
Read-only ImageIteratorWithIndex: ImageConstIteratorWithIndex<TImage> behaves as ImageIteratorWithInd...
ImageIteratorWithIndex< std::add_const_t< TImage > > Superclass
A base class for multi-dimensional iterators templated over image type that are designed to efficient...
QualifiedInternalPixelType * m_Begin
bool operator>=(const ImageIteratorWithIndex< TOtherImage > &it) const
Self & operator=(const Self &)=default
typename OffsetType::OffsetValueType OffsetValueType
ImageIteratorWithIndex(const ImageIteratorWithIndex< TOtherImage > &it)
typename IndexType::IndexValueType IndexValueType
std::conditional_t< std::is_const_v< TImage >, const InternalPixelType, InternalPixelType > QualifiedInternalPixelType
OffsetValueType m_OffsetTable[ImageDimension+1]
typename PixelContainer::Pointer PixelContainerPointer
QualifiedInternalPixelType * m_Position
typename SizeType::SizeValueType SizeValueType
detail::IteratorImageType_t< TImage > ImageType
ImageIteratorWithIndex(TImage *ptr, const RegionType &region)
typename TImage::AccessorFunctorType AccessorFunctorType
static constexpr unsigned int GetImageDimension()
QualifiedInternalPixelType * m_End
bool operator<=(const ImageIteratorWithIndex< TOtherImage > &it) const
typename TImage::AccessorType AccessorType
virtual ~ImageIteratorWithIndex()=default
typename TImage::InternalPixelType InternalPixelType
bool operator<(const ImageIteratorWithIndex< TOtherImage > &it) const
typename TImage::PixelContainer PixelContainer
void SetIndex(const IndexType &ind)
bool operator==(const ImageIteratorWithIndex< TOtherImage > &it) const
const RegionType & GetRegion() const
ImageIteratorWithIndex(const Self &)=default
typename TImage::OffsetType OffsetType
bool operator!=(const ImageIteratorWithIndex< TOtherImage > &it) const
typename TImage::RegionType RegionType
void Set(const PixelType &value) const
bool operator>(const ImageIteratorWithIndex< TOtherImage > &it) const
typename TImage::IndexType IndexType
Implements transparent reference counting.
Implements a weak reference to an object.
bool ITKIOXML_EXPORT operator==(itk::FancyString &s, const std::string &)
TImage IteratorImageType_t
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
ImageIteratorWithIndex(SmartPointer< TImage >, const typename TImage::RegionType &) -> ImageIteratorWithIndex< TImage >
ImageConstIteratorWithIndex(const TImage *, const typename TImage::RegionType &) -> ImageConstIteratorWithIndex< TImage >