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 "itkImage.h"
25#include "itkNeighborhood.h"
26#include "itkMacro.h"
28
29namespace itk
30{
50template <typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
51class ITK_TEMPLATE_EXPORT ConstNeighborhoodIterator
52 : public Neighborhood<typename TImage::InternalPixelType *, TImage::ImageDimension>
53{
54public:
56 using InternalPixelType = typename TImage::InternalPixelType;
57 using PixelType = typename TImage::PixelType;
58
60 using DimensionValueType = unsigned int;
61
63 static constexpr DimensionValueType Dimension = TImage::ImageDimension;
64
68
70 using typename Superclass::OffsetType;
71 using typename Superclass::RadiusType;
72 using typename Superclass::SizeType;
73 using typename Superclass::Iterator;
74 using typename Superclass::ConstIterator;
75
77 using ImageType = TImage;
78 using RegionType = typename TImage::RegionType;
81
82
84 using BoundaryConditionType = TBoundaryCondition;
85
86 using OutputImageType = typename BoundaryConditionType::OutputImageType;
87
90
94 using NeighborhoodAccessorFunctorType = typename ImageType::NeighborhoodAccessorFunctorType;
95
99
102
104 ~ConstNeighborhoodIterator() override = default;
105
108
111 ConstNeighborhoodIterator(const SizeType & radius, const ImageType * ptr, const RegionType & region)
112 {
113 this->Initialize(radius, ptr, region);
114 for (DimensionValueType i = 0; i < Dimension; ++i)
115 {
116 m_InBounds[i] = false;
117 }
119 m_NeighborhoodAccessorFunctor = ptr->GetNeighborhoodAccessor();
120 m_NeighborhoodAccessorFunctor.SetBegin(ptr->GetBufferPointer());
121 }
122
123
125 Self &
126 operator=(const Self & orig);
127
129 void
130 PrintSelf(std::ostream &, Indent) const override;
131
136
139 GetBound() const
140 {
141 return m_Bound;
142 }
143
148 {
149 return m_Bound[n];
150 }
151
153 const InternalPixelType *
155 {
156 return (this->operator[]((this->Size()) >> 1));
157 }
158
161 PixelType
163 {
165 }
166
168 const ImageType *
170 {
171 return m_ConstImage;
172 }
173
176 IndexType
177 GetIndex() const
178 {
179 return m_Loop;
180 }
181
182 inline IndexType
184 {
185 return m_Loop + o;
186 }
187
190 NeighborhoodType
192
196 {
198 {
199 return (m_NeighborhoodAccessorFunctor.Get(this->operator[](i)));
200 }
201
202 OffsetType internalIndex;
203 OffsetType offset;
204
205 return this->IndexInBounds(i, internalIndex, offset)
206 ? m_NeighborhoodAccessorFunctor.Get(this->operator[](i))
207 : m_NeighborhoodAccessorFunctor.BoundaryCondition(internalIndex, offset, this, m_BoundaryCondition);
208 }
209
215 PixelType
216 GetPixel(NeighborIndexType n, bool & IsInBounds) const;
217
221 GetPixel(const OffsetType & o) const
222 {
223 bool inbounds;
224
225 return (this->GetPixel(this->GetNeighborhoodIndex(o), inbounds));
226 }
227
233 PixelType
234 GetPixel(const OffsetType & o, bool & IsInBounds) const
235 {
236 return (this->GetPixel(this->GetNeighborhoodIndex(o), IsInBounds));
237 }
238
242 PixelType
243 GetNext(const unsigned int axis, NeighborIndexType i) const
244 {
245 return (this->GetPixel(this->GetCenterNeighborhoodIndex() + (i * this->GetStride(axis))));
246 }
247
251 PixelType
252 GetNext(const unsigned int axis) const
253 {
254 return (this->GetPixel(this->GetCenterNeighborhoodIndex() + this->GetStride(axis)));
255 }
256
260 PixelType
261 GetPrevious(const unsigned int axis, NeighborIndexType i) const
262 {
263 return (this->GetPixel(this->GetCenterNeighborhoodIndex() - (i * this->GetStride(axis))));
264 }
265
269 PixelType
270 GetPrevious(const unsigned int axis) const
271 {
272 return (this->GetPixel(this->GetCenterNeighborhoodIndex() - this->GetStride(axis)));
273 }
274
277 IndexType
278 GetIndex(const OffsetType & o) const
279 {
280 return (this->GetIndex() + o);
281 }
282
285 IndexType
287 {
288 return (this->GetIndex() + this->GetOffset(i));
289 }
290
292 RegionType
293 GetRegion() const
294 {
295 return m_Region;
296 }
297
300 IndexType
302 {
303 return m_BeginIndex;
304 }
305
308 RegionType
310
314 {
315 return m_WrapOffset;
316 }
317
325 {
326 return m_WrapOffset[n];
327 }
328
330 void
332
335 void
337
340 void
341 Initialize(const SizeType & radius, const ImageType * ptr, const RegionType & region);
342
345 bool
346 IsAtBegin() const
347 {
348 return (this->GetCenterPointer() == m_Begin);
349 }
350
353 bool
354 IsAtEnd() const
355 {
356 if (this->GetCenterPointer() > m_End)
357 {
358 ExceptionObject e(__FILE__, __LINE__);
359 std::ostringstream msg;
360 msg << "In method IsAtEnd, CenterPointer = " << this->GetCenterPointer() << " is greater than End = " << m_End
361 << std::endl
362 << " " << *this;
363 e.SetDescription(msg.str().c_str());
364 throw e;
365 }
366 return (this->GetCenterPointer() == m_End);
367 }
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
442
446 Self &
448
452 Self &
454
457 operator-(const Self & b) const
458 {
459 return m_Loop - b.m_Loop;
460 }
461
465 bool
466 InBounds() const;
467
479 bool
480 IndexInBounds(const NeighborIndexType n, OffsetType & internalIndex, OffsetType & offset) const;
481
484 bool
486
492 void
497
500 void
505
507 void
508 SetBoundaryCondition(const TBoundaryCondition & c)
509 {
511 }
512
514 ImageBoundaryConditionPointerType
516 {
517 return m_BoundaryCondition;
518 }
519
521 void
526
527 void
532
533 void
538
539 bool
544
546 void
547 SetRegion(const RegionType & region);
548
549protected:
552 void
554 {
555 m_Loop = p;
556 m_IsInBoundsValid = false;
557 }
558
562 void
564
569 void
571
574 void
576 {
577 m_BeginIndex = start;
578 }
579
582 void
584
588
591
593 const InternalPixelType * m_Begin{ nullptr };
594
596 typename ImageType::ConstWeakPointer m_ConstImage{};
597
599 const InternalPixelType * m_End{ nullptr };
600
604
607
610
617
619 TBoundaryCondition m_InternalBoundaryCondition{};
620
626
629 mutable bool m_InBounds[Dimension]{ false };
630
632 mutable bool m_IsInBounds{ false };
633
637 mutable bool m_IsInBoundsValid{ false };
638
641
644
647
650};
651
652template <typename TImage>
653inline ConstNeighborhoodIterator<TImage>
656{
658 ret += ind;
659 return ret;
660}
661
662template <typename TImage>
663inline ConstNeighborhoodIterator<TImage>
666{
667 return (it + ind);
668}
669
670template <typename TImage>
671inline ConstNeighborhoodIterator<TImage>
674{
676 ret -= ind;
677 return ret;
678}
679} // namespace itk
680
681#ifndef ITK_MANUAL_INSTANTIATION
682# include "itkConstNeighborhoodIterator.hxx"
683#endif
684
685#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 &)
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
ConstNeighborhoodIterator(const SizeType &radius, const ImageType *ptr, const RegionType &region)
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:50
virtual NeighborIndexType GetNeighborhoodIndex(const OffsetType &) const
typename AllocatorType::const_iterator ConstIterator
AddImageFilter Self
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< 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