ITK  6.0.0
Insight Toolkit
itkImageConstIteratorWithIndex.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 itkImageConstIteratorWithIndex_h
19#define itkImageConstIteratorWithIndex_h
20
21#include "itkIndex.h"
22#include "itkImage.h"
23#include <memory>
24
25namespace itk
26{
91template <typename TImage>
92class ITK_TEMPLATE_EXPORT ImageConstIteratorWithIndex
93{
94public:
97
102 static constexpr unsigned int ImageDimension = TImage::ImageDimension;
103
105 using IndexType = typename TImage::IndexType;
107
109 using SizeType = typename TImage::SizeType;
111
114
116 using ImageType = TImage;
117
121 using PixelContainer = typename TImage::PixelContainer;
123
125 using InternalPixelType = typename TImage::InternalPixelType;
126
128 using PixelType = typename TImage::PixelType;
129
132 using AccessorType = typename TImage::AccessorType;
133 using AccessorFunctorType = typename TImage::AccessorFunctorType;
134
136 using OffsetType = typename TImage::OffsetType;
138
142
146
149 ImageConstIteratorWithIndex(const TImage * ptr, const RegionType & region);
150
152 virtual ~ImageConstIteratorWithIndex() = default;
153
156 Self &
157 operator=(const Self & it);
158
160 static constexpr unsigned int
162 {
163 return ImageDimension;
164 }
165
168 bool
169 operator==(const Self & it) const
170 {
171 // two iterators are the same if they "point to" the same memory location
172 return (m_Position) == (it.m_Position);
173 }
174
176
179 bool
180 operator<=(const Self & it) const
181 {
182 // an iterator is "less than" another if it "points to" a lower
183 // memory location
184 return (m_Position) <= (it.m_Position);
185 }
186
189 bool
190 operator<(const Self & it) const
191 {
192 // an iterator is "less than" another if it "points to" a lower
193 // memory location
194 return (m_Position) < (it.m_Position);
195 }
196
199 bool
200 operator>=(const Self & it) const
201 {
202 // an iterator is "greater than" another if it "points to" a higher
203 // memory location
204 return (m_Position) >= (it.m_Position);
205 }
206
209 bool
210 operator>(const Self & it) const
211 {
212 // an iterator is "greater than" another if it "points to" a higher
213 // memory location
214 return (m_Position) > (it.m_Position);
215 }
216
219 const IndexType &
220 GetIndex() const
221 {
222 return m_PositionIndex;
223 }
224
227 const RegionType &
228 GetRegion() const
229 {
230 return m_Region;
231 }
232
235 void
236 SetIndex(const IndexType & ind)
237 {
238 m_Position = m_Image->GetBufferPointer() + m_Image->ComputeOffset(ind);
239 m_PositionIndex = ind;
240 }
244 PixelType
245 Get() const
246 {
247 return m_PixelAccessorFunctor.Get(*m_Position);
248 }
249
253 const PixelType &
254 Value() const
255 {
256 return *m_Position;
257 }
258
260 void
262
264 void
266
268 bool
270 {
271 return !m_Remaining;
272 }
273
275 bool
276 IsAtEnd() const
277 {
278 return !m_Remaining;
279 }
280
282 bool
284 {
285 return m_Remaining;
286 }
287
288protected: // made protected so other iterators can access
289 typename TImage::ConstWeakPointer m_Image{};
290
291 IndexType m_PositionIndex{ { 0 } }; // Index where we currently are
292 IndexType m_BeginIndex{ { 0 } }; // Index to start iterating over
293 IndexType m_EndIndex{ { 0 } }; // Index to finish iterating:
294 // one pixel past the end of each
295 // row, col, slice, etc....
296
297 RegionType m_Region{}; // region to iterate over
298
299 OffsetValueType m_OffsetTable[ImageDimension + 1]{};
300
301 const InternalPixelType * m_Position{ nullptr };
302 const InternalPixelType * m_Begin{ nullptr };
303 const InternalPixelType * m_End{ nullptr };
304
305 bool m_Remaining{ false };
306
307 AccessorType m_PixelAccessor{};
308 AccessorFunctorType m_PixelAccessorFunctor{};
309};
310} // end namespace itk
311
312#ifndef ITK_MANUAL_INSTANTIATION
313# include "itkImageConstIteratorWithIndex.hxx"
314#endif
315
316#endif
A base class for multi-dimensional iterators templated over image type that are designed to efficient...
typename TImage::AccessorFunctorType AccessorFunctorType
typename OffsetType::OffsetValueType OffsetValueType
Self & operator=(const Self &it)
ImageConstIteratorWithIndex(const TImage *ptr, const RegionType &region)
typename SizeType::SizeValueType SizeValueType
static constexpr unsigned int GetImageDimension()
ImageConstIteratorWithIndex(const Self &it)
virtual ~ImageConstIteratorWithIndex()=default
typename IndexType::IndexValueType IndexValueType
typename PixelContainer::Pointer PixelContainerPointer
typename TImage::InternalPixelType InternalPixelType
typename TImage::PixelContainer PixelContainer
SmartPointer< Self > Pointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
bool operator<=(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:571
long IndexValueType
Definition: itkIntTypes.h:93
unsigned long SizeValueType
Definition: itkIntTypes.h:86
bool operator<(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:557
long OffsetValueType
Definition: itkIntTypes.h:97