ITK  5.4.0
Insight Toolkit
itkConstNeighborhoodIteratorWithOnlyIndex.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 itkConstNeighborhoodIteratorWithOnlyIndex_h
19 #define itkConstNeighborhoodIteratorWithOnlyIndex_h
20 
21 #include <vector>
22 #include <cstring>
23 #include <iostream>
24 #include "itkImage.h"
25 #include "itkNeighborhood.h"
26 #include "itkMacro.h"
27 
28 namespace itk
29 {
59 template <typename TImage>
60 class ITK_TEMPLATE_EXPORT ConstNeighborhoodIteratorWithOnlyIndex : public Neighborhood<char, TImage::ImageDimension>
61 {
62 public:
64  using DimensionValueType = unsigned int;
65 
67  static constexpr DimensionValueType Dimension = TImage::ImageDimension;
68 
70 
74 
76  using typename Superclass::OffsetType;
77  using typename Superclass::RadiusType;
78  using typename Superclass::SizeType;
79  using typename Superclass::Iterator;
80  using typename Superclass::ConstIterator;
81 
83  using ImageType = TImage;
84  using RegionType = typename TImage::RegionType;
87 
90 
93 
95  ~ConstNeighborhoodIteratorWithOnlyIndex() override = default;
96 
99 
102  ConstNeighborhoodIteratorWithOnlyIndex(const SizeType & radius, const ImageType * ptr, const RegionType & region);
103 
105  Self &
106  operator=(const Self & orig);
107 
109  void
110  PrintSelf(std::ostream &, Indent) const override;
111 
114  OffsetType
115  ComputeInternalIndex(NeighborIndexType n) const;
116 
118  IndexType
119  GetBound() const
120  {
121  return m_Bound;
122  }
123 
128  {
129  return m_Bound[n];
130  }
131 
133  const ImageType *
135  {
136  return m_ConstImage;
137  }
138 
141  ITK_ITERATOR_VIRTUAL IndexType
142  GetIndex() const ITK_ITERATOR_FINAL
143  {
144  return m_Loop;
145  }
146 
149  ITK_ITERATOR_VIRTUAL IndexType
150  GetIndex(const OffsetType & o) const ITK_ITERATOR_FINAL
151  {
152  return (this->GetIndex() + o);
153  }
154 
157  ITK_ITERATOR_VIRTUAL IndexType
158  GetIndex(NeighborIndexType i) const ITK_ITERATOR_FINAL
159  {
160  return (this->GetIndex() + this->GetOffset(i));
161  }
162 
164  RegionType
165  GetRegion() const
166  {
167  return m_Region;
168  }
169 
172  IndexType
174  {
175  return m_BeginIndex;
176  }
177 
180  RegionType
181  GetBoundingBoxAsImageRegion() const;
182 
184  ITK_ITERATOR_VIRTUAL void
185  GoToBegin() ITK_ITERATOR_FINAL;
186 
189  ITK_ITERATOR_VIRTUAL void
190  GoToEnd() ITK_ITERATOR_FINAL;
191 
194  ITK_ITERATOR_VIRTUAL void
195  Initialize(const SizeType & radius, const ImageType * ptr, const RegionType & region) ITK_ITERATOR_FINAL;
196 
199  ITK_ITERATOR_VIRTUAL bool
200  IsAtBegin() const ITK_ITERATOR_FINAL
201  {
202  return (this->GetIndex() == m_BeginIndex);
203  }
204 
207  ITK_ITERATOR_VIRTUAL bool
208  IsAtEnd() const ITK_ITERATOR_FINAL;
209 
214  Self &
215  operator++();
216 
221  Self &
222  operator--();
223 
227  bool
228  operator==(const Self & it) const
229  {
230  return it.GetIndex() == this->GetIndex();
231  }
232 
233  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self);
234 
240  bool
241  operator<(const Self & it) const;
242 
248  bool
249  operator<=(const Self & it) const;
250 
256  bool
257  operator>(const Self & it) const;
258 
264  bool
265  operator>=(const Self & it) const;
266 
271  void
272  SetLocation(const IndexType & position)
273  {
274  this->SetLoop(position);
275  }
276 
280  Self &
281  operator+=(const OffsetType &);
282 
286  Self &
287  operator-=(const OffsetType &);
288 
290  OffsetType
291  operator-(const Self & b) const
292  {
293  return m_Loop - b.m_Loop;
294  }
295 
299  bool
300  InBounds() const;
301 
313  bool
314  IndexInBounds(const NeighborIndexType n, OffsetType & internalIndex, OffsetType & offset) const;
315 
317  void
319  {
320  this->SetNeedToUseBoundaryCondition(true);
321  }
322 
323  void
325  {
326  this->SetNeedToUseBoundaryCondition(false);
327  }
328 
329  void
331  {
332  m_NeedToUseBoundaryCondition = b;
333  }
334 
335  bool
337  {
338  return m_NeedToUseBoundaryCondition;
339  }
340 
341 protected:
344  ITK_ITERATOR_VIRTUAL void
345  SetLoop(const IndexType & p) ITK_ITERATOR_FINAL
346  {
347  m_Loop = p;
348  m_IsInBoundsValid = false;
349  }
350 
354  ITK_ITERATOR_VIRTUAL void
355  SetBound(const SizeType &) ITK_ITERATOR_FINAL;
356 
359  ITK_ITERATOR_VIRTUAL void
360  SetBeginIndex(const IndexType & start) ITK_ITERATOR_FINAL
361  {
362  m_BeginIndex = start;
363  }
364 
367  ITK_ITERATOR_VIRTUAL void
368  SetEndIndex() ITK_ITERATOR_FINAL;
369 
372  IndexType m_BeginIndex{ { 0 } };
373 
375  IndexType m_Bound{ { 0 } };
376 
378  typename ImageType::ConstPointer m_ConstImage{};
379 
382  IndexType m_EndIndex{ { 0 } };
383 
385  IndexType m_Loop{ { 0 } };
386 
388  RegionType m_Region{};
389 
392  mutable bool m_InBounds[Dimension]{ false };
393 
395  mutable bool m_IsInBounds{ false };
396 
400  mutable bool m_IsInBoundsValid{ false };
401 
403  IndexType m_InnerBoundsLow{};
404 
406  IndexType m_InnerBoundsHigh{};
407 
409  bool m_NeedToUseBoundaryCondition{ false };
410 };
411 
412 template <typename TImage>
413 inline ConstNeighborhoodIteratorWithOnlyIndex<TImage>
416 {
418  ret = it;
419  ret += ind;
420  return ret;
421 }
422 
423 template <typename TImage>
424 inline ConstNeighborhoodIteratorWithOnlyIndex<TImage>
427 {
428  return (it + ind);
429 }
430 
431 template <typename TImage>
432 inline ConstNeighborhoodIteratorWithOnlyIndex<TImage>
435 {
437  ret = it;
438  ret -= ind;
439  return ret;
440 }
441 } // namespace itk
442 
443 #ifndef ITK_MANUAL_INSTANTIATION
444 # include "itkConstNeighborhoodIteratorWithOnlyIndex.hxx"
445 #endif
446 
447 #endif
ConstPointer
SmartPointer< const Self > ConstPointer
Definition: itkAddImageFilter.h:94
itk::Index< Self::Dimension >
itk::operator<
bool operator<(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:559
itk::operator<=
bool operator<=(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:573
itk::Size
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:71
itk::ConstNeighborhoodIteratorWithOnlyIndex::GetIndex
ITK_ITERATOR_VIRTUAL IndexType GetIndex() const ITK_ITERATOR_FINAL
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:142
itk::ConstNeighborhoodIteratorWithOnlyIndex::GetRegion
RegionType GetRegion() const
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:165
itk::operator-
ConstNeighborhoodIterator< TImage > operator-(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
Definition: itkConstNeighborhoodIterator.h:672
itk::Neighborhood
A light-weight container object for storing an N-dimensional neighborhood of values.
Definition: itkNeighborhood.h:54
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itkImage.h
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ConstNeighborhoodIteratorWithOnlyIndex::ImageType
TImage ImageType
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:83
itkNeighborhood.h
itk::ConstNeighborhoodIteratorWithOnlyIndex::SetBeginIndex
ITK_ITERATOR_VIRTUAL void SetBeginIndex(const IndexType &start) ITK_ITERATOR_FINAL
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:360
itk::ConstNeighborhoodIteratorWithOnlyIndex::GetIndex
ITK_ITERATOR_VIRTUAL IndexType GetIndex(const OffsetType &o) const ITK_ITERATOR_FINAL
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:150
itk::ConstNeighborhoodIteratorWithOnlyIndex::operator-
OffsetType operator-(const Self &b) const
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:291
itk::ConstNeighborhoodIteratorWithOnlyIndex::NeighborIndexType
typename NeighborhoodType::NeighborIndexType NeighborIndexType
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:89
itk::ConstNeighborhoodIteratorWithOnlyIndex::GetImagePointer
const ImageType * GetImagePointer() const
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:134
itk::ConstNeighborhoodIteratorWithOnlyIndex::DummyNeighborhoodPixelType
char DummyNeighborhoodPixelType
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:69
itk::IndexValueType
long IndexValueType
Definition: itkIntTypes.h:90
itk::ConstNeighborhoodIteratorWithOnlyIndex::m_Loop
IndexType m_Loop
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:385
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::ConstNeighborhoodIteratorWithOnlyIndex::GetIndex
ITK_ITERATOR_VIRTUAL IndexType GetIndex(NeighborIndexType i) const ITK_ITERATOR_FINAL
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:158
itkMacro.h
itk::ConstNeighborhoodIteratorWithOnlyIndex::NeedToUseBoundaryConditionOff
void NeedToUseBoundaryConditionOff()
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:324
itk::ConstNeighborhoodIteratorWithOnlyIndex::GetBeginIndex
IndexType GetBeginIndex() const
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:173
itk::ConstNeighborhoodIteratorWithOnlyIndex::SetLocation
void SetLocation(const IndexType &position)
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:272
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::ConstNeighborhoodIteratorWithOnlyIndex::SetLoop
ITK_ITERATOR_VIRTUAL void SetLoop(const IndexType &p) ITK_ITERATOR_FINAL
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:345
itk::Neighborhood::Iterator
typename AllocatorType::iterator Iterator
Definition: itkNeighborhood.h:75
itk::ConstNeighborhoodIteratorWithOnlyIndex::DimensionValueType
unsigned int DimensionValueType
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:64
itk::ConstNeighborhoodIteratorWithOnlyIndex::NeedToUseBoundaryConditionOn
void NeedToUseBoundaryConditionOn()
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:318
itk::operator>=
bool operator>=(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:580
itk::ConstNeighborhoodIteratorWithOnlyIndex::SetNeedToUseBoundaryCondition
void SetNeedToUseBoundaryCondition(bool b)
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:330
itk::operator>
bool operator>(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:566
itk::Neighborhood::ConstIterator
typename AllocatorType::const_iterator ConstIterator
Definition: itkNeighborhood.h:76
itk::Offset
Represent a n-dimensional offset between two n-dimensional indexes of n-dimensional image.
Definition: itkOffset.h:69
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ConstNeighborhoodIteratorWithOnlyIndex::GetBound
IndexType GetBound() const
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:119
itk::operator+
ConstNeighborhoodIterator< TImage > operator+(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
Definition: itkConstNeighborhoodIterator.h:654
itk::ConstNeighborhoodIteratorWithOnlyIndex
Index-only version of ConstNeighborhoodIterator, defining iteration of a local N-dimensional neighbor...
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:60
AddImageFilter
Definition: itkAddImageFilter.h:81
itk::Neighborhood::NeighborIndexType
SizeValueType NeighborIndexType
Definition: itkNeighborhood.h:96
itk::ConstNeighborhoodIteratorWithOnlyIndex::RegionType
typename TImage::RegionType RegionType
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:84
itk::GTest::TypedefsAndConstructors::Dimension2::Dimension
constexpr unsigned int Dimension
Definition: itkGTestTypedefsAndConstructors.h:44
itk::ConstNeighborhoodIteratorWithOnlyIndex::GetBound
IndexValueType GetBound(NeighborIndexType n) const
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:127
itk::ConstNeighborhoodIteratorWithOnlyIndex::GetNeedToUseBoundaryCondition
bool GetNeedToUseBoundaryCondition() const
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:336