ITK  6.0.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:
63  ITK_DEFAULT_COPY_AND_MOVE(ConstNeighborhoodIteratorWithOnlyIndex);
64 
66  using DimensionValueType = unsigned int;
67 
69  static constexpr DimensionValueType Dimension = TImage::ImageDimension;
70 
72 
76 
78  using typename Superclass::OffsetType;
79  using typename Superclass::RadiusType;
80  using typename Superclass::SizeType;
81  using typename Superclass::Iterator;
82  using typename Superclass::ConstIterator;
83 
85  using ImageType = TImage;
86  using RegionType = typename TImage::RegionType;
89 
92 
95 
97  ~ConstNeighborhoodIteratorWithOnlyIndex() override = default;
98 
101  ConstNeighborhoodIteratorWithOnlyIndex(const SizeType & radius, const ImageType * ptr, const RegionType & region);
102 
104  void
105  PrintSelf(std::ostream &, Indent) const override;
106 
109  OffsetType
110  ComputeInternalIndex(NeighborIndexType n) const;
111 
113  IndexType
114  GetBound() const
115  {
116  return m_Bound;
117  }
118 
123  {
124  return m_Bound[n];
125  }
126 
128  const ImageType *
130  {
131  return m_ConstImage;
132  }
133 
136  IndexType
137  GetIndex() const
138  {
139  return m_Loop;
140  }
141 
144  IndexType
145  GetIndex(const OffsetType & o) const
146  {
147  return (this->GetIndex() + o);
148  }
149 
152  IndexType
154  {
155  return (this->GetIndex() + this->GetOffset(i));
156  }
157 
159  RegionType
160  GetRegion() const
161  {
162  return m_Region;
163  }
164 
167  IndexType
169  {
170  return m_BeginIndex;
171  }
172 
175  RegionType
176  GetBoundingBoxAsImageRegion() const;
177 
179  void
180  GoToBegin();
181 
184  void
185  GoToEnd();
186 
189  void
190  Initialize(const SizeType & radius, const ImageType * ptr, const RegionType & region);
191 
194  bool
195  IsAtBegin() const
196  {
197  return (this->GetIndex() == m_BeginIndex);
198  }
199 
202  bool
203  IsAtEnd() const;
204 
209  Self &
210  operator++();
211 
216  Self &
217  operator--();
218 
222  bool
223  operator==(const Self & it) const
224  {
225  return it.GetIndex() == this->GetIndex();
226  }
227 
228  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self);
229 
235  bool
236  operator<(const Self & it) const;
237 
243  bool
244  operator<=(const Self & it) const;
245 
251  bool
252  operator>(const Self & it) const;
253 
259  bool
260  operator>=(const Self & it) const;
261 
266  void
267  SetLocation(const IndexType & position)
268  {
269  this->SetLoop(position);
270  }
271 
275  Self &
276  operator+=(const OffsetType &);
277 
281  Self &
282  operator-=(const OffsetType &);
283 
285  OffsetType
286  operator-(const Self & b) const
287  {
288  return m_Loop - b.m_Loop;
289  }
290 
294  bool
295  InBounds() const;
296 
308  bool
309  IndexInBounds(const NeighborIndexType n, OffsetType & internalIndex, OffsetType & offset) const;
310 
312  void
314  {
315  this->SetNeedToUseBoundaryCondition(true);
316  }
317 
318  void
320  {
321  this->SetNeedToUseBoundaryCondition(false);
322  }
323 
324  void
326  {
327  m_NeedToUseBoundaryCondition = b;
328  }
329 
330  bool
332  {
333  return m_NeedToUseBoundaryCondition;
334  }
335 
336 protected:
339  void
340  SetLoop(const IndexType & p)
341  {
342  m_Loop = p;
343  m_IsInBoundsValid = false;
344  }
345 
349  void
350  SetBound(const SizeType &);
351 
354  void
355  SetBeginIndex(const IndexType & start)
356  {
357  m_BeginIndex = start;
358  }
359 
362  void
363  SetEndIndex();
364 
367  IndexType m_BeginIndex{ { 0 } };
368 
370  IndexType m_Bound{ { 0 } };
371 
373  typename ImageType::ConstPointer m_ConstImage{};
374 
377  IndexType m_EndIndex{ { 0 } };
378 
380  IndexType m_Loop{ { 0 } };
381 
383  RegionType m_Region{};
384 
387  mutable bool m_InBounds[Dimension]{ false };
388 
390  mutable bool m_IsInBounds{ false };
391 
395  mutable bool m_IsInBoundsValid{ false };
396 
398  IndexType m_InnerBoundsLow{};
399 
401  IndexType m_InnerBoundsHigh{};
402 
404  bool m_NeedToUseBoundaryCondition{ false };
405 };
406 
407 template <typename TImage>
408 inline ConstNeighborhoodIteratorWithOnlyIndex<TImage>
411 {
413  ret = it;
414  ret += ind;
415  return ret;
416 }
417 
418 template <typename TImage>
419 inline ConstNeighborhoodIteratorWithOnlyIndex<TImage>
422 {
423  return (it + ind);
424 }
425 
426 template <typename TImage>
427 inline ConstNeighborhoodIteratorWithOnlyIndex<TImage>
430 {
432  ret = it;
433  ret -= ind;
434  return ret;
435 }
436 } // namespace itk
437 
438 #ifndef ITK_MANUAL_INSTANTIATION
439 # include "itkConstNeighborhoodIteratorWithOnlyIndex.hxx"
440 #endif
441 
442 #endif
itk::ConstNeighborhoodIteratorWithOnlyIndex::SetLoop
void SetLoop(const IndexType &p)
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:340
ConstPointer
SmartPointer< const Self > ConstPointer
Definition: itkAddImageFilter.h:94
itk::ConstNeighborhoodIteratorWithOnlyIndex::SetBeginIndex
void SetBeginIndex(const IndexType &start)
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:355
itk::Index< Self::Dimension >
itk::operator<
bool operator<(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:557
itk::operator<=
bool operator<=(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:571
itk::Size
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:69
itk::ConstNeighborhoodIteratorWithOnlyIndex::GetIndex
IndexType GetIndex(NeighborIndexType i) const
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:153
itk::ConstNeighborhoodIteratorWithOnlyIndex::GetRegion
RegionType GetRegion() const
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:160
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:85
itkNeighborhood.h
itk::ConstNeighborhoodIteratorWithOnlyIndex::operator-
OffsetType operator-(const Self &b) const
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:286
itk::ConstNeighborhoodIteratorWithOnlyIndex::NeighborIndexType
typename NeighborhoodType::NeighborIndexType NeighborIndexType
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:91
itk::ConstNeighborhoodIteratorWithOnlyIndex::GetImagePointer
const ImageType * GetImagePointer() const
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:129
itk::ConstNeighborhoodIteratorWithOnlyIndex::DummyNeighborhoodPixelType
char DummyNeighborhoodPixelType
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:71
itk::IndexValueType
long IndexValueType
Definition: itkIntTypes.h:93
itk::ConstNeighborhoodIteratorWithOnlyIndex::m_Loop
IndexType m_Loop
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:380
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itkMacro.h
itk::ConstNeighborhoodIteratorWithOnlyIndex::NeedToUseBoundaryConditionOff
void NeedToUseBoundaryConditionOff()
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:319
itk::ConstNeighborhoodIteratorWithOnlyIndex::GetBeginIndex
IndexType GetBeginIndex() const
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:168
itk::ConstNeighborhoodIteratorWithOnlyIndex::IsAtBegin
bool IsAtBegin() const
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:195
itk::ConstNeighborhoodIteratorWithOnlyIndex::SetLocation
void SetLocation(const IndexType &position)
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:267
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::Neighborhood::Iterator
typename AllocatorType::iterator Iterator
Definition: itkNeighborhood.h:75
itk::ConstNeighborhoodIteratorWithOnlyIndex::DimensionValueType
unsigned int DimensionValueType
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:66
itk::ConstNeighborhoodIteratorWithOnlyIndex::NeedToUseBoundaryConditionOn
void NeedToUseBoundaryConditionOn()
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:313
itk::operator>=
bool operator>=(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:578
itk::ConstNeighborhoodIteratorWithOnlyIndex::SetNeedToUseBoundaryCondition
void SetNeedToUseBoundaryCondition(bool b)
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:325
itk::operator>
bool operator>(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:564
itk::Neighborhood::ConstIterator
typename AllocatorType::const_iterator ConstIterator
Definition: itkNeighborhood.h:76
itk::ConstNeighborhoodIteratorWithOnlyIndex::operator==
bool operator==(const Self &it) const
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:223
itk::Offset
Represent a n-dimensional offset between two n-dimensional indexes of n-dimensional image.
Definition: itkOffset.h:66
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::ConstNeighborhoodIteratorWithOnlyIndex::GetBound
IndexType GetBound() const
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:114
itk::operator+
ConstNeighborhoodIterator< TImage > operator+(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
Definition: itkConstNeighborhoodIterator.h:654
itk::ConstNeighborhoodIteratorWithOnlyIndex::GetIndex
IndexType GetIndex(const OffsetType &o) const
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:145
itk::ConstNeighborhoodIteratorWithOnlyIndex::GetIndex
IndexType GetIndex() const
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:137
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:86
itk::GTest::TypedefsAndConstructors::Dimension2::Dimension
constexpr unsigned int Dimension
Definition: itkGTestTypedefsAndConstructors.h:44
itk::ConstNeighborhoodIteratorWithOnlyIndex::GetBound
IndexValueType GetBound(NeighborIndexType n) const
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:122
itk::ConstNeighborhoodIteratorWithOnlyIndex::GetNeedToUseBoundaryCondition
bool GetNeedToUseBoundaryCondition() const
Definition: itkConstNeighborhoodIteratorWithOnlyIndex.h:331