ITK  5.2.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  * http://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 
78  using SizeType = typename Superclass::SizeType;
79  using Iterator = typename Superclass::Iterator;
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 
236  bool
237  operator!=(const Self & it) const
238  {
239  return it.GetIndex() != this->GetIndex();
240  }
241 
247  bool
248  operator<(const Self & it) const;
249 
255  bool
256  operator<=(const Self & it) const;
257 
263  bool
264  operator>(const Self & it) const;
265 
271  bool
272  operator>=(const Self & it) const;
273 
278  void
279  SetLocation(const IndexType & position)
280  {
281  this->SetLoop(position);
282  }
283 
287  Self &
288  operator+=(const OffsetType &);
289 
293  Self &
294  operator-=(const OffsetType &);
295 
297  OffsetType
298  operator-(const Self & b)
299  {
300  return m_Loop - b.m_Loop;
301  }
302 
306  bool
307  InBounds() const;
308 
320  bool
321  IndexInBounds(const NeighborIndexType n, OffsetType & internalIndex, OffsetType & offset) const;
322 
324  void
326  {
327  this->SetNeedToUseBoundaryCondition(true);
328  }
329 
330  void
332  {
333  this->SetNeedToUseBoundaryCondition(false);
334  }
335 
336  void
338  {
339  m_NeedToUseBoundaryCondition = b;
340  }
341 
342  bool
344  {
345  return m_NeedToUseBoundaryCondition;
346  }
347 
348 protected:
351  ITK_ITERATOR_VIRTUAL void
352  SetLoop(const IndexType & p) ITK_ITERATOR_FINAL
353  {
354  m_Loop = p;
355  m_IsInBoundsValid = false;
356  }
357 
361  ITK_ITERATOR_VIRTUAL void
362  SetBound(const SizeType &) ITK_ITERATOR_FINAL;
363 
366  ITK_ITERATOR_VIRTUAL void
367  SetBeginIndex(const IndexType & start) ITK_ITERATOR_FINAL
368  {
369  m_BeginIndex = start;
370  }
371 
374  ITK_ITERATOR_VIRTUAL void
375  SetEndIndex() ITK_ITERATOR_FINAL;
376 
379  IndexType m_BeginIndex;
380 
382  IndexType m_Bound;
383 
385  typename ImageType::ConstPointer m_ConstImage;
386 
389  IndexType m_EndIndex;
390 
392  IndexType m_Loop;
393 
395  RegionType m_Region;
396 
399  mutable bool m_InBounds[Dimension];
400 
402  mutable bool m_IsInBounds;
403 
407  mutable bool m_IsInBoundsValid;
408 
410  IndexType m_InnerBoundsLow;
411 
413  IndexType m_InnerBoundsHigh;
414 
416  bool m_NeedToUseBoundaryCondition;
417 };
418 
419 template <typename TImage>
421 operator+(const ConstNeighborhoodIteratorWithOnlyIndex<TImage> & it,
422  const typename ConstNeighborhoodIteratorWithOnlyIndex<TImage>::OffsetType & ind)
423 {
425  ret = it;
426  ret += ind;
427  return ret;
428 }
429 
430 template <typename TImage>
431 inline ConstNeighborhoodIteratorWithOnlyIndex<TImage>
434 {
435  return (it + ind);
436 }
437 
438 template <typename TImage>
439 inline ConstNeighborhoodIteratorWithOnlyIndex<TImage>
442 {
444  ret = it;
445  ret -= ind;
446  return ret;
447 }
448 } // namespace itk
449 
450 #ifndef ITK_MANUAL_INSTANTIATION
451 # include "itkConstNeighborhoodIteratorWithOnlyIndex.hxx"
452 #endif
453 
454 #endif
itk::ConstNeighborhoodIteratorWithOnlyIndex::operator-
OffsetType operator-(const Self &b)
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:298
itk::Index< Self::Dimension >
itk::operator<
bool operator<(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:546
itk::operator<=
bool operator<=(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:560
itk::Size
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:69
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:679
itk::ConstNeighborhoodIteratorWithOnlyIndex::operator!=
bool operator!=(const Self &it) const
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:237
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
itk::ConstNeighborhoodIteratorWithOnlyIndex::Iterator
typename Superclass::Iterator Iterator
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:79
itkImage.h
itk::ConstNeighborhoodIteratorWithOnlyIndex::RadiusType
typename Superclass::RadiusType RadiusType
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:77
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:367
itk::ConstNeighborhoodIteratorWithOnlyIndex::GetIndex
ITK_ITERATOR_VIRTUAL IndexType GetIndex(const OffsetType &o) const ITK_ITERATOR_FINAL
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:150
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::ConstNeighborhoodIteratorWithOnlyIndex::m_Loop
IndexType m_Loop
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:392
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:331
itk::ConstNeighborhoodIteratorWithOnlyIndex::GetBeginIndex
IndexType GetBeginIndex() const
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:173
itk::ConstNeighborhoodIteratorWithOnlyIndex::SetLocation
void SetLocation(const IndexType &position)
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:279
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:352
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:325
itk::operator>=
bool operator>=(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:567
itk::ConstNeighborhoodIteratorWithOnlyIndex::SetNeedToUseBoundaryCondition
void SetNeedToUseBoundaryCondition(bool b)
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:337
itk::operator>
bool operator>(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:553
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:67
itk::ConstNeighborhoodIteratorWithOnlyIndex::OffsetType
typename Superclass::OffsetType OffsetType
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:76
itk::ConstNeighborhoodIteratorWithOnlyIndex::SizeType
typename Superclass::SizeType SizeType
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:78
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:661
itk::IndexValueType
signed long IndexValueType
Definition: itkIntTypes.h:90
itk::ConstNeighborhoodIteratorWithOnlyIndex::ConstIterator
typename Superclass::ConstIterator ConstIterator
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:80
itk::ConstNeighborhoodIteratorWithOnlyIndex
Index-only version of ConstNeighborhoodIterator, defining iteration of a local N-dimensional neighbor...
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:60
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:343