ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkImageReverseConstIterator.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 itkImageReverseConstIterator_h
19#define itkImageReverseConstIterator_h
20
21#include "itkSize.h"
23#include <memory>
24
25namespace itk
26{
86template <typename TImage>
87class ITK_TEMPLATE_EXPORT ImageReverseConstIterator
88{
89public:
92
97 static constexpr unsigned int ImageIteratorDimension = TImage::ImageDimension;
98
100 itkVirtualGetNameOfClassMacro(ImageReverseConstIterator);
101
103 using IndexType = typename TImage::IndexType;
104
106 using SizeType = typename TImage::SizeType;
107
109 using OffsetType = typename TImage::OffsetType;
110
112 using RegionType = typename TImage::RegionType;
113
115 using ImageType = TImage;
120 using PixelContainer = typename TImage::PixelContainer;
121 using PixelContainerPointer = typename PixelContainer::Pointer;
122
124 using InternalPixelType = typename TImage::InternalPixelType;
125
127 using PixelType = typename TImage::PixelType;
128
131 using AccessorType = typename TImage::AccessorType;
134 using AccessorFunctorType = typename TImage::AccessorFunctorType;
135
145
147 virtual ~ImageReverseConstIterator() = default;
148
152 : m_Image(it.m_Image)
153 , m_Region(it.m_Region)
154 , m_Offset(it.m_Offset)
157 , m_Buffer(it.m_Buffer)
160 {
161 // copy the smart pointer
162
163
165 }
166
169 ImageReverseConstIterator(const ImageType * ptr, const RegionType & region)
170 : m_Image(ptr)
171 , m_Region(region)
172 , m_Buffer(m_Image->GetBufferPointer())
173 {
174
175
176 // Compute the end offset, one pixel before the first pixel
177 SizeValueType offset = m_Image->ComputeOffset(m_Region.GetIndex());
178 m_EndOffset = offset - 1;
179
180 // Compute the begin offset, the last pixel in the region
181 IndexType ind(m_Region.GetIndex());
182 SizeType size(m_Region.GetSize());
183 for (unsigned int i = 0; i < TImage::ImageDimension; ++i)
184 {
185 ind[i] += (size[i] - 1);
186 }
187 m_BeginOffset = m_Image->ComputeOffset(ind);
189
190 m_PixelAccessor = ptr->GetPixelAccessor();
191 m_PixelAccessorFunctor.SetPixelAccessor(m_PixelAccessor);
193 }
194
203 : m_Image(it.GetImage())
204 , m_Region(it.GetRegion())
205 , m_EndOffset(m_Image->ComputeOffset(m_Region.GetIndex()) - 1)
206 , m_Buffer(m_Image->GetBufferPointer())
207 {
208
209
210 const IndexType ind = it.GetIndex();
211
212 m_Offset = m_Image->ComputeOffset(ind);
213
214 // Compute the end offset, one pixel before the first pixel
215
216
217 // Compute the begin offset, the last pixel in the region
218 IndexType regInd(m_Region.GetIndex());
219 SizeType regSize(m_Region.GetSize());
220 for (unsigned int i = 0; i < TImage::ImageDimension; ++i)
221 {
222 regInd[i] += (regSize[i] - 1);
223 }
224 m_BeginOffset = m_Image->ComputeOffset(regInd);
225
226 m_PixelAccessor = m_Image->GetPixelAccessor();
227 m_PixelAccessorFunctor.SetPixelAccessor(m_PixelAccessor);
229 }
230
233 Self &
234 operator=(const Self & it)
235 {
236 if (this != &it)
237 {
238 m_Image = it.m_Image; // copy the smart pointer
239 m_Region = it.m_Region;
240
241 m_Buffer = it.m_Buffer;
242 m_Offset = it.m_Offset;
246 m_PixelAccessorFunctor.SetPixelAccessor(m_PixelAccessor);
248 }
249 return *this;
250 }
251
254 Self &
256 {
257 m_Image = it.GetImage();
258 m_Region = it.GetRegion();
259 m_Buffer = m_Image->GetBufferPointer();
260
261 IndexType ind = it.GetIndex();
262
263 m_Offset = m_Image->ComputeOffset(ind);
264
265 // Compute the end offset, one pixel before the first pixel
266 m_EndOffset = m_Image->ComputeOffset(m_Region.GetIndex()) - 1;
267
268 // Compute the begin offset, the last pixel in the region
269 IndexType regInd(m_Region.GetIndex());
270 SizeType regSize(m_Region.GetSize());
271 for (unsigned int i = 0; i < TImage::ImageDimension; ++i)
272 {
273 regInd[i] += (regSize[i] - 1);
274 }
275 m_BeginOffset = m_Image->ComputeOffset(regInd);
276
277 m_PixelAccessor = m_Image->GetPixelAccessor();
278 m_PixelAccessorFunctor.SetPixelAccessor(m_PixelAccessor);
280 return *this;
281 }
282
284 static unsigned int
286 {
287 return TImage::ImageDimension;
288 }
289
292 bool
293 operator==(const Self & it) const
294 {
295 // two iterators are the same if they "point to" the same memory location
296 return (m_Buffer + m_Offset) == (it.m_Buffer + it.m_Offset);
297 }
298
300
301
306 const IndexType
308 {
309 return m_Image->ComputeIndex(m_Offset);
310 }
311
314 virtual void
315 SetIndex(const IndexType & ind)
316 {
317 m_Offset = m_Image->ComputeOffset(ind);
318 }
319
322 [[nodiscard]] const RegionType &
323 GetRegion() const
324 {
325 return m_Region;
326 }
327
329 [[nodiscard]] const PixelType
330 Get() const
331 {
333 }
334
336 void
337 Set(const PixelType & value) const
338 {
339 this->m_PixelAccessorFunctor.Set(*(const_cast<InternalPixelType *>(this->m_Buffer + this->m_Offset)), value);
340 }
341
345 [[nodiscard]] const PixelType &
346 Value() const
347 {
348 return *(m_Buffer + m_Offset);
349 }
350
354 const PixelType &
356 {
357 return *(m_Buffer + m_Offset);
358 }
359
362 void
364 {
366 }
367
370 void
372 {
374 }
375
378 [[nodiscard]] bool
379 IsAtBegin() const
380 {
381 return (m_Offset == m_BeginOffset);
382 }
383
386 [[nodiscard]] bool
387 IsAtEnd() const
388 {
389 return (m_Offset == m_EndOffset);
390 }
391
392protected: // made protected so other iterators can access
393 typename ImageType::ConstWeakPointer m_Image{};
394
395 RegionType m_Region{}; // region to iterate over
396
398 SizeValueType m_BeginOffset{}; // offset to last pixel in region
399 SizeValueType m_EndOffset{}; // offset to one pixel before first pixel
400
402
405};
406} // end namespace itk
407
408#endif
A multi-dimensional image iterator templated over image type.
const RegionType & GetRegion() const
const IndexType GetIndex() const
const ImageType * GetImage() const
typename TImage::PixelContainer PixelContainer
virtual void SetIndex(const IndexType &ind)
ImageReverseConstIterator(const ImageConstIterator< TImage > &it)
static constexpr unsigned int ImageIteratorDimension
typename TImage::AccessorFunctorType AccessorFunctorType
Self & operator=(const ImageConstIterator< TImage > &it)
virtual ~ImageReverseConstIterator()=default
typename TImage::AccessorType AccessorType
typename PixelContainer::Pointer PixelContainerPointer
typename TImage::InternalPixelType InternalPixelType
ImageReverseConstIterator(const ImageType *ptr, const RegionType &region)
void Set(const PixelType &value) const
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition itkIntTypes.h:86