ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkConstNeighborhoodIterator.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 itkConstNeighborhoodIterator_h
19#define itkConstNeighborhoodIterator_h
20
21#include <vector>
22#include <cstring>
23#include <iostream>
24#include <type_traits> // For remove_const_t.
25
26#include "itkImage.h"
27#include "itkNeighborhood.h"
28#include "itkMacro.h"
30
31namespace itk
32{
52template <typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
53class ITK_TEMPLATE_EXPORT ConstNeighborhoodIterator
54 : public Neighborhood<typename TImage::InternalPixelType *, TImage::ImageDimension>
55{
56public:
58 using InternalPixelType = typename TImage::InternalPixelType;
59 using PixelType = typename TImage::PixelType;
60
62 using DimensionValueType = unsigned int;
63
65 static constexpr DimensionValueType Dimension = TImage::ImageDimension;
66
70
72 using typename Superclass::OffsetType;
73 using typename Superclass::RadiusType;
74 using typename Superclass::SizeType;
75 using typename Superclass::Iterator;
76 using typename Superclass::ConstIterator;
77
79 using ImageType = TImage;
80 using RegionType = typename TImage::RegionType;
83
84
86 using BoundaryConditionType = TBoundaryCondition;
87
88 using OutputImageType = typename BoundaryConditionType::OutputImageType;
89
92
96 using NeighborhoodAccessorFunctorType = typename ImageType::NeighborhoodAccessorFunctorType;
97
101
104
106 ~ConstNeighborhoodIterator() override = default;
107
110
113 ConstNeighborhoodIterator(const SizeType & radius, const TImage * ptr, const RegionType & region)
114 {
115 this->Initialize(radius, ptr, region);
116 for (DimensionValueType i = 0; i < Dimension; ++i)
117 {
118 m_InBounds[i] = false;
119 }
121 m_NeighborhoodAccessorFunctor = ptr->GetNeighborhoodAccessor();
122 m_NeighborhoodAccessorFunctor.SetBegin(ptr->GetBufferPointer());
123 }
124
126 Self &
127 operator=(const Self & orig);
128
130 void
131 PrintSelf(std::ostream &, Indent) const override;
132
137
140 GetBound() const
141 {
142 return m_Bound;
143 }
144
149 {
150 return m_Bound[n];
151 }
152
154 const InternalPixelType *
156 {
157 return (this->operator[]((this->Size()) >> 1));
158 }
159
162 PixelType
164 {
166 }
167
169 const ImageType *
171 {
172 return m_ConstImage;
173 }
174
177 IndexType
178 GetIndex() const
179 {
180 return m_Loop;
181 }
182
183 inline IndexType
185 {
186 return m_Loop + o;
187 }
188
191 NeighborhoodType
193
197 {
199 {
200 return (m_NeighborhoodAccessorFunctor.Get(this->operator[](i)));
201 }
202
203 OffsetType internalIndex;
204 OffsetType offset;
205
206 return this->IndexInBounds(i, internalIndex, offset)
207 ? m_NeighborhoodAccessorFunctor.Get(this->operator[](i))
208 : m_NeighborhoodAccessorFunctor.BoundaryCondition(internalIndex, offset, this, m_BoundaryCondition);
209 }
210
216 PixelType
217 GetPixel(NeighborIndexType n, bool & IsInBounds) const;
218
222 GetPixel(const OffsetType & o) const
223 {
224 bool inbounds = false;
225
226 return (this->GetPixel(this->GetNeighborhoodIndex(o), inbounds));
227 }
228
234 PixelType
235 GetPixel(const OffsetType & o, bool & IsInBounds) const
236 {
237 return (this->GetPixel(this->GetNeighborhoodIndex(o), IsInBounds));
238 }
239
243 PixelType
244 GetNext(const unsigned int axis, NeighborIndexType i) const
245 {
246 return (this->GetPixel(this->GetCenterNeighborhoodIndex() + (i * this->GetStride(axis))));
247 }
248
252 PixelType
253 GetNext(const unsigned int axis) const
254 {
255 return (this->GetPixel(this->GetCenterNeighborhoodIndex() + this->GetStride(axis)));
256 }
257
261 PixelType
262 GetPrevious(const unsigned int axis, NeighborIndexType i) const
263 {
264 return (this->GetPixel(this->GetCenterNeighborhoodIndex() - (i * this->GetStride(axis))));
265 }
266
270 PixelType
271 GetPrevious(const unsigned int axis) const
272 {
273 return (this->GetPixel(this->GetCenterNeighborhoodIndex() - this->GetStride(axis)));
274 }
275
278 IndexType
279 GetIndex(const OffsetType & o) const
280 {
281 return this->GetIndex() + o;
282 }
283
286 IndexType
288 {
289 return this->GetIndex() + this->GetOffset(i);
290 }
291
293 RegionType
294 GetRegion() const
295 {
296 return m_Region;
297 }
298
301 IndexType
303 {
304 return m_BeginIndex;
305 }
306
309 RegionType
311
315 {
316 return m_WrapOffset;
317 }
318
326 {
327 return m_WrapOffset[n];
328 }
329
331 void
333
336 void
338
341 void
342 Initialize(const SizeType & radius, const ImageType * ptr, const RegionType & region);
343
346 bool
347 IsAtBegin() const
348 {
349 return this->GetCenterPointer() == m_Begin;
350 }
351
354 bool
355 IsAtEnd() const
356 {
357 if (this->GetCenterPointer() > m_End)
358 {
359 ExceptionObject e(__FILE__, __LINE__);
360 std::ostringstream msg;
361 msg << "In method IsAtEnd, CenterPointer = " << this->GetCenterPointer() << " is greater than End = " << m_End
362 << std::endl
363 << " " << *this;
364 e.SetDescription(msg.str().c_str());
365 throw e;
366 }
367 return this->GetCenterPointer() == m_End;
368 }
369
374 Self &
376
381 Self &
383
387 bool
388 operator==(const Self & it) const
389 {
390 return it.GetCenterPointer() == this->GetCenterPointer();
391 }
392
394
398 bool
399 operator<(const Self & it) const
400 {
401 return this->GetCenterPointer() < it.GetCenterPointer();
402 }
403
407 bool
408 operator<=(const Self & it) const
409 {
410 return this->GetCenterPointer() <= it.GetCenterPointer();
411 }
412
416 bool
417 operator>(const Self & it) const
418 {
419 return this->GetCenterPointer() > it.GetCenterPointer();
420 }
421
425 bool
426 operator>=(const Self & it) const
427 {
428 return this->GetCenterPointer() >= it.GetCenterPointer();
429 }
430
435 void
436 SetLocation(const IndexType & position)
437 {
438 this->SetLoop(position);
439 this->SetPixelPointers(position);
440 }
441
445 Self &
447
451 Self &
453
456 operator-(const Self & b) const
457 {
458 return m_Loop - b.m_Loop;
459 }
460
464 bool
465 InBounds() const;
466
478 bool
479 IndexInBounds(const NeighborIndexType n, OffsetType & internalIndex, OffsetType & offset) const;
480
483 bool
485
491 void
496
499 void
504
506 void
507 SetBoundaryCondition(const TBoundaryCondition & c)
508 {
510 }
511
513 ImageBoundaryConditionPointerType
515 {
516 return m_BoundaryCondition;
517 }
518
520 void
525
526 void
531
532 void
537
538 bool
543
545 void
546 SetRegion(const RegionType & region);
547
548protected:
551 void
553 {
554 m_Loop = p;
555 m_IsInBoundsValid = false;
556 }
557
561 void
563
568 void
570
573 void
575 {
576 m_BeginIndex = start;
577 }
578
581 void
583
587
590
592 const InternalPixelType * m_Begin{ nullptr };
593
595 typename ImageType::ConstWeakPointer m_ConstImage{};
596
598 const InternalPixelType * m_End{ nullptr };
599
603
606
609
616
618 TBoundaryCondition m_InternalBoundaryCondition{};
619
625
628 mutable bool m_InBounds[Dimension]{ false };
629
631 mutable bool m_IsInBounds{ false };
632
636 mutable bool m_IsInBoundsValid{ false };
637
640
643
646
649};
650
651// Deduction guide for class template argument deduction (CTAD).
652template <typename TImage>
653ConstNeighborhoodIterator(const typename TImage::SizeType &, SmartPointer<TImage>, const typename TImage::RegionType &)
655
656
657template <typename TImage>
661{
663 ret += ind;
664 return ret;
665}
666
667template <typename TImage>
671{
672 return it + ind;
673}
674
675template <typename TImage>
679{
681 ret -= ind;
682 return ret;
683}
684} // namespace itk
685
686#ifndef ITK_MANUAL_INSTANTIATION
687# include "itkConstNeighborhoodIterator.hxx"
688#endif
689
690#endif
Const version of NeighborhoodIterator, defining iteration of a local N-dimensional neighborhood of pi...
IndexValueType GetBound(NeighborIndexType n) const
NeighborhoodType GetNeighborhood() const
void SetRegion(const RegionType &region)
PixelType GetNext(const unsigned int axis) const
~ConstNeighborhoodIterator() override=default
const InternalPixelType * GetCenterPointer() const
typename ImageType::NeighborhoodAccessorFunctorType NeighborhoodAccessorFunctorType
Neighborhood< PixelType, Self::Dimension > NeighborhoodType
Self & operator=(const Self &orig)
bool IndexInBounds(const NeighborIndexType n) const
void OverrideBoundaryCondition(const ImageBoundaryConditionPointerType i)
PixelType GetPixel(const NeighborIndexType i) const
void SetBeginIndex(const IndexType &start)
typename TImage::InternalPixelType InternalPixelType
const ImageBoundaryCondition< ImageType, OutputImageType > * ImageBoundaryConditionConstPointerType
void SetBoundaryCondition(const TBoundaryCondition &c)
Self & operator+=(const OffsetType &)
ConstNeighborhoodIterator(const SizeType &radius, const TImage *ptr, const RegionType &region)
Neighborhood< InternalPixelType *, Self::Dimension > Superclass
OffsetType ComputeInternalIndex(const NeighborIndexType n) const
RegionType GetBoundingBoxAsImageRegion() const
PixelType GetPixel(const OffsetType &o, bool &IsInBounds) const
ConstNeighborhoodIterator(const ConstNeighborhoodIterator &)
void Initialize(const SizeType &radius, const ImageType *ptr, const RegionType &region)
OffsetValueType GetWrapOffset(NeighborIndexType n) const
void SetBound(const SizeType &)
void PrintSelf(std::ostream &, Indent) const override
IndexType GetIndex(NeighborIndexType i) const
PixelType GetPrevious(const unsigned int axis, NeighborIndexType i) const
IndexType GetIndex(const OffsetType &o) const
ImageBoundaryCondition< ImageType, OutputImageType > * ImageBoundaryConditionPointerType
Self & operator-=(const OffsetType &)
PixelType GetPrevious(const unsigned int axis) const
typename NeighborhoodType::NeighborIndexType NeighborIndexType
PixelType GetPixel(NeighborIndexType n, bool &IsInBounds) const
bool IndexInBounds(const NeighborIndexType n, OffsetType &internalIndex, OffsetType &offset) const
OffsetType operator-(const Self &b) const
PixelType GetPixel(const OffsetType &o) const
ImageBoundaryConditionPointerType GetBoundaryCondition() const
typename BoundaryConditionType::OutputImageType OutputImageType
IndexType GetFastIndexPlusOffset(const OffsetType &o) const
void SetLocation(const IndexType &position)
PixelType GetNext(const unsigned int axis, NeighborIndexType i) const
Standard exception handling object.
virtual void SetDescription(const std::string &s)
A virtual base object that defines an interface to a class of boundary condition objects for use by n...
Control indentation during Print() invocation.
Definition itkIndent.h:51
virtual NeighborIndexType GetNeighborhoodIndex(const OffsetType &) const
typename AllocatorType::const_iterator ConstIterator
Implements transparent reference counting.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
long OffsetValueType
Definition itkIntTypes.h:97
ConstNeighborhoodIterator< TImage > operator-(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
ConstNeighborhoodIterator(const typename TImage::SizeType &, SmartPointer< TImage >, const typename TImage::RegionType &) -> ConstNeighborhoodIterator< std::remove_const_t< TImage > >
ConstNeighborhoodIterator< TImage > operator+(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
long IndexValueType
Definition itkIntTypes.h:93
Represent a n-dimensional index in a n-dimensional image.
Definition itkIndex.h:69