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
148
150 virtual ~ImageReverseConstIterator() = default;
151
155 {
156 m_Image = it.m_Image; // copy the smart pointer
157
158 m_Region = it.m_Region;
159
160 m_Buffer = it.m_Buffer;
161 m_Offset = it.m_Offset;
167 }
168
171 ImageReverseConstIterator(const ImageType * ptr, const RegionType & region)
172 {
173 m_Image = ptr;
174 m_Buffer = m_Image->GetBufferPointer();
175 m_Region = region;
176
177 // Compute the end offset, one pixel before the first pixel
178 SizeValueType offset = m_Image->ComputeOffset(m_Region.GetIndex());
179 m_EndOffset = offset - 1;
180
181 // Compute the begin offset, the last pixel in the region
182 IndexType ind(m_Region.GetIndex());
183 SizeType size(m_Region.GetSize());
184 for (unsigned int i = 0; i < TImage::ImageDimension; ++i)
185 {
186 ind[i] += (size[i] - 1);
187 }
188 m_BeginOffset = m_Image->ComputeOffset(ind);
190
191 m_PixelAccessor = ptr->GetPixelAccessor();
192 m_PixelAccessorFunctor.SetPixelAccessor(m_PixelAccessor);
194 }
195
204 {
205 m_Image = it.GetImage();
206 m_Region = it.GetRegion();
207 m_Buffer = m_Image->GetBufferPointer();
208
209 const IndexType ind = it.GetIndex();
210
211 m_Offset = m_Image->ComputeOffset(ind);
212
213 // Compute the end offset, one pixel before the first pixel
214 m_EndOffset = m_Image->ComputeOffset(m_Region.GetIndex()) - 1;
215
216 // Compute the begin offset, the last pixel in the region
217 IndexType regInd(m_Region.GetIndex());
218 SizeType regSize(m_Region.GetSize());
219 for (unsigned int i = 0; i < TImage::ImageDimension; ++i)
220 {
221 regInd[i] += (regSize[i] - 1);
222 }
223 m_BeginOffset = m_Image->ComputeOffset(regInd);
224
225 m_PixelAccessor = m_Image->GetPixelAccessor();
226 m_PixelAccessorFunctor.SetPixelAccessor(m_PixelAccessor);
228 }
229
232 Self &
233 operator=(const Self & it)
234 {
235 if (this != &it)
236 {
237 m_Image = it.m_Image; // copy the smart pointer
238 m_Region = it.m_Region;
239
240 m_Buffer = it.m_Buffer;
241 m_Offset = it.m_Offset;
245 m_PixelAccessorFunctor.SetPixelAccessor(m_PixelAccessor);
247 }
248 return *this;
249 }
250
253 Self &
255 {
256 m_Image = it.GetImage();
257 m_Region = it.GetRegion();
258 m_Buffer = m_Image->GetBufferPointer();
259
260 IndexType ind = it.GetIndex();
261
262 m_Offset = m_Image->ComputeOffset(ind);
263
264 // Compute the end offset, one pixel before the first pixel
265 m_EndOffset = m_Image->ComputeOffset(m_Region.GetIndex()) - 1;
266
267 // Compute the begin offset, the last pixel in the region
268 IndexType regInd(m_Region.GetIndex());
269 SizeType regSize(m_Region.GetSize());
270 for (unsigned int i = 0; i < TImage::ImageDimension; ++i)
271 {
272 regInd[i] += (regSize[i] - 1);
273 }
274 m_BeginOffset = m_Image->ComputeOffset(regInd);
275
276 m_PixelAccessor = m_Image->GetPixelAccessor();
277 m_PixelAccessorFunctor.SetPixelAccessor(m_PixelAccessor);
279 return *this;
280 }
281
283 static unsigned int
285 {
286 return TImage::ImageDimension;
287 }
288
291 bool
292 operator==(const Self & it) const
293 {
294 // two iterators are the same if they "point to" the same memory location
295 return (m_Buffer + m_Offset) == (it.m_Buffer + it.m_Offset);
296 }
297
299
300
305 const IndexType
307 {
308 return m_Image->ComputeIndex(m_Offset);
309 }
310
313 virtual void
314 SetIndex(const IndexType & ind)
315 {
316 m_Offset = m_Image->ComputeOffset(ind);
317 }
318
321 const RegionType &
322 GetRegion() const
323 {
324 return m_Region;
325 }
326
328 const PixelType
329 Get() const
330 {
332 }
333
335 void
336 Set(const PixelType & value) const
337 {
338 this->m_PixelAccessorFunctor.Set(*(const_cast<InternalPixelType *>(this->m_Buffer + this->m_Offset)), value);
339 }
340
344 const PixelType &
345 Value() const
346 {
347 return *(m_Buffer + m_Offset);
348 }
349
353 const PixelType &
355 {
356 return *(m_Buffer + m_Offset);
357 }
358
361 void
363 {
365 }
366
369 void
371 {
373 }
374
377 bool
378 IsAtBegin() const
379 {
380 return (m_Offset == m_BeginOffset);
381 }
382
385 bool
386 IsAtEnd() const
387 {
388 return (m_Offset == m_EndOffset);
389 }
390
391protected: // made protected so other iterators can access
392 typename ImageType::ConstWeakPointer m_Image{};
393
394 RegionType m_Region{}; // region to iterate over
395
397 SizeValueType m_BeginOffset{}; // offset to last pixel in region
398 SizeValueType m_EndOffset{}; // offset to one pixel before first pixel
399
401
404};
405} // end namespace itk
406
407#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