ITK  5.4.0
Insight Toolkit
itkConstShapedNeighborhoodIterator.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 itkConstShapedNeighborhoodIterator_h
19 #define itkConstShapedNeighborhoodIterator_h
20 
21 #include <vector>
22 #include <list>
24 
25 namespace itk
26 {
71 template <typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
72 class ITK_TEMPLATE_EXPORT ConstShapedNeighborhoodIterator : private NeighborhoodIterator<TImage, TBoundaryCondition>
73 {
74 public:
76  using InternalPixelType = typename TImage::InternalPixelType;
77  using PixelType = typename TImage::PixelType;
78 
80  static constexpr unsigned int Dimension = TImage::ImageDimension;
81 
85 
87  using typename Superclass::OffsetType;
89  using typename Superclass::RadiusType;
90  using typename Superclass::SizeType;
92 
94  using ImageType = TImage;
95  using RegionType = typename TImage::RegionType;
99 
101 
104  using IndexListType = std::list<NeighborIndexType>;
105 
106  using IndexListIterator = typename IndexListType::iterator;
107  using IndexListConstIterator = typename IndexListType::const_iterator;
108 
110  using BoundaryConditionType = TBoundaryCondition;
111 
114 
117  {
118  ConstIterator() { m_NeighborhoodIterator = nullptr; }
120  {
121  m_NeighborhoodIterator = s;
122  this->GoToBegin();
123  }
126  ITK_ITERATOR_VIRTUAL ~ConstIterator() = default;
127 
128  ConstIterator &
130  {
131  m_NeighborhoodIterator = o.m_NeighborhoodIterator;
132  m_ListIterator = o.m_ListIterator;
133  return *this;
134  }
135 
137  {
138  m_NeighborhoodIterator = o.m_NeighborhoodIterator;
139  m_ListIterator = o.m_ListIterator;
140  }
141 
142  void
144  {
145  ++m_ListIterator;
146  }
147 
148  void
150  {
151  --m_ListIterator;
152  }
153 
154  const ConstIterator &
156  {
157  ++m_ListIterator;
158  return *this;
159  }
160 
161  const ConstIterator &
163  {
164  --m_ListIterator;
165  return *this;
166  }
167 
168  bool
169  operator==(const ConstIterator & o) const
170  {
171  return m_ListIterator == o.m_ListIterator;
172  }
173 
174  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(ConstIterator);
175 
176  bool
177  IsAtEnd() const
178  {
179  if (m_ListIterator == m_NeighborhoodIterator->GetActiveIndexList().end())
180  {
181  return true;
182  }
183  else
184  {
185  return false;
186  }
187  }
188 
189  void
191  {
192  m_ListIterator = m_NeighborhoodIterator->GetActiveIndexList().begin();
193  }
194 
195  void
197  {
198  m_ListIterator = m_NeighborhoodIterator->GetActiveIndexList().end();
199  }
200 
201  PixelType
202  Get() const
203  {
204  return m_NeighborhoodIterator->GetPixel(*m_ListIterator);
205  }
206 
207  OffsetType
209  {
210  return m_NeighborhoodIterator->GetOffset(*m_ListIterator);
211  }
212 
213  typename IndexListType::value_type
215  {
216  return *m_ListIterator;
217  }
218 
219  protected:
220  friend Self;
221 
222  ConstIterator(const Self * s, const typename IndexListType::const_iterator & li)
223  : m_NeighborhoodIterator(const_cast<Self *>(s))
224  , m_ListIterator(li)
225  {}
226 
228 
229  typename IndexListType::const_iterator m_ListIterator;
230 
231  void
232  ProtectedSet(const PixelType & v) const
233  {
234  m_NeighborhoodIterator->SetPixel(*m_ListIterator, v);
235  }
236  };
237 
240  ConstIterator
241  Begin() const
242  {
243  return ConstIterator(this, this->m_ActiveIndexList.begin());
244  }
245 
248  ConstIterator
249  End() const
250  {
251  return ConstIterator(this, this->m_ActiveIndexList.end());
252  }
253 
256 
258  ~ConstShapedNeighborhoodIterator() override = default;
259 
262  ConstShapedNeighborhoodIterator(const SizeType & radius, const ImageType * ptr, const RegionType & region)
263  : Superclass(radius, const_cast<ImageType *>(ptr), region)
264  {}
265 
268 
269  // Expose the following methods from the superclass. This is a
270  // restricted subset of the methods available for
271  // ConstNeighborhoodIterator.
272  using Superclass::GetImagePointer;
273  using Superclass::GetRadius;
274  using Superclass::GetIndex;
275  using Superclass::GetNeighborhoodIndex;
276  using Superclass::GetCenterNeighborhoodIndex;
277  using Superclass::GetRegion;
278  using Superclass::GetBeginIndex;
279  using Superclass::GoToBegin;
280  using Superclass::GoToEnd;
281  using Superclass::IsAtBegin;
282  using Superclass::IsAtEnd;
283  using Superclass::GetOffset;
284  using Superclass::operator==;
285 #ifndef ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
286  using Superclass::operator!=;
287 #endif
288  using Superclass::operator<;
289  using Superclass::operator>;
290  using Superclass::operator>=;
291  using Superclass::operator<=;
292  using Superclass::operator[];
293  using Superclass::GetElement;
294  using Superclass::SetLocation;
295  using Superclass::GetCenterPointer;
296  using Superclass::GetCenterPixel;
297  using Superclass::OverrideBoundaryCondition;
298  using Superclass::ResetBoundaryCondition;
299  using Superclass::GetBoundaryCondition;
300  using Superclass::SetBoundaryCondition;
301  using Superclass::GetNeedToUseBoundaryCondition;
302  using Superclass::SetNeedToUseBoundaryCondition;
303  using Superclass::NeedToUseBoundaryConditionOn;
304  using Superclass::NeedToUseBoundaryConditionOff;
305  using Superclass::Print;
306  using Superclass::operator-;
307  using Superclass::GetPixel;
308  using Superclass::SetRegion;
309 
311  Self &
312  operator=(const Self & orig)
313  {
314  if (this != &orig)
315  {
316  Superclass::operator=(orig);
317  m_ActiveIndexList = orig.m_ActiveIndexList;
318  m_CenterIsActive = orig.m_CenterIsActive;
319  }
320  return *this;
321  }
325  void
326  PrintSelf(std::ostream &, Indent) const override;
327 
331  ITK_ITERATOR_VIRTUAL void
332  ActivateOffset(const OffsetType & off) ITK_ITERATOR_FINAL
333  {
334  this->ActivateIndex(Superclass::GetNeighborhoodIndex(off));
335  }
336  ITK_ITERATOR_VIRTUAL void
337  DeactivateOffset(const OffsetType & off) ITK_ITERATOR_FINAL
338  {
339  this->DeactivateIndex(Superclass::GetNeighborhoodIndex(off));
340  }
345  template <typename TOffsets>
346  void
347  ActivateOffsets(const TOffsets & offsets)
348  {
349  for (const auto & offset : offsets)
350  {
351  this->ActivateOffset(offset);
352  }
353  }
357  ITK_ITERATOR_VIRTUAL void
358  ClearActiveList() ITK_ITERATOR_FINAL
359  {
360  m_ActiveIndexList.clear();
361  m_CenterIsActive = false;
362  }
366  const IndexListType &
368  {
369  return m_ActiveIndexList;
370  }
371 
373  typename IndexListType::size_type
375  {
376  return m_ActiveIndexList.size();
377  }
378 
382  template <typename TNeighborPixel>
383  void
384  CreateActiveListFromNeighborhood(const Neighborhood<TNeighborPixel, Self::Dimension> &);
385  void
387  {
388  // just delegate to the templated version
389  this->CreateActiveListFromNeighborhood<PixelType>(neighborhood);
390  }
395  Self &
396  operator++();
397 
400  Self &
401  operator--();
402 
406  Self &
407  operator+=(const OffsetType &);
408 
412  Self &
413  operator-=(const OffsetType &);
414 
415 protected:
416  using Superclass::SetPixel;
417  using Superclass::SetCenterPixel;
418 
419  friend struct ConstIterator;
420 
423  // Superclass::SetPixel;
424  // Superclass::SetCenterPixel;
425 
431  ITK_ITERATOR_VIRTUAL void ActivateIndex(NeighborIndexType) ITK_ITERATOR_FINAL;
432 
433  ITK_ITERATOR_VIRTUAL void DeactivateIndex(NeighborIndexType) ITK_ITERATOR_FINAL;
434 
435 
436  bool m_CenterIsActive{ false };
437  IndexListType m_ActiveIndexList{};
438 };
439 } // namespace itk
440 
441 #ifndef ITK_MANUAL_INSTANTIATION
442 # include "itkConstShapedNeighborhoodIterator.hxx"
443 #endif
444 
445 #endif
itk::ConstShapedNeighborhoodIterator::ConstIterator::GetNeighborhoodIndex
IndexListType::value_type GetNeighborhoodIndex() const
Definition: itkConstShapedNeighborhoodIterator.h:214
itk::Offset::GetOffset
const OffsetValueType * GetOffset() const
Definition: itkOffset.h:184
itk::Index< Self::Dimension >
itk::ConstShapedNeighborhoodIterator::ConstIterator::ConstIterator
ConstIterator(const Self *s, const typename IndexListType::const_iterator &li)
Definition: itkConstShapedNeighborhoodIterator.h:222
itk::ConstNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::NeighborIndexType
typename NeighborhoodType::NeighborIndexType NeighborIndexType
Definition: itkConstNeighborhoodIterator.h:89
itk::Size
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:71
itk::ConstNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::PixelType
typename ImageType ::PixelType PixelType
Definition: itkConstNeighborhoodIterator.h:57
itkNeighborhoodIterator.h
itk::ConstShapedNeighborhoodIterator::ConstIterator::ConstIterator
ConstIterator(Self *s)
Definition: itkConstShapedNeighborhoodIterator.h:119
itk::ConstShapedNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::IndexValueType
typename IndexType::IndexValueType IndexValueType
Definition: itkConstShapedNeighborhoodIterator.h:97
itk::ConstShapedNeighborhoodIterator::DeactivateOffset
ITK_ITERATOR_VIRTUAL void DeactivateOffset(const OffsetType &off) ITK_ITERATOR_FINAL
Definition: itkConstShapedNeighborhoodIterator.h:337
itk::ConstShapedNeighborhoodIterator::ConstIterator::m_ListIterator
IndexListType::const_iterator m_ListIterator
Definition: itkConstShapedNeighborhoodIterator.h:229
itk::ConstShapedNeighborhoodIterator::ConstIterator::GoToBegin
void GoToBegin()
Definition: itkConstShapedNeighborhoodIterator.h:190
itk::ConstShapedNeighborhoodIterator::ConstShapedNeighborhoodIterator
ConstShapedNeighborhoodIterator(const SizeType &radius, const ImageType *ptr, const RegionType &region)
Definition: itkConstShapedNeighborhoodIterator.h:262
itk::ConstShapedNeighborhoodIterator::ConstIterator::Get
PixelType Get() const
Definition: itkConstShapedNeighborhoodIterator.h:202
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::ConstNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::ConstIterator
typename AllocatorType::const_iterator ConstIterator
Definition: itkNeighborhood.h:76
itk::ConstShapedNeighborhoodIterator::ActivateOffset
ITK_ITERATOR_VIRTUAL void ActivateOffset(const OffsetType &off) ITK_ITERATOR_FINAL
Definition: itkConstShapedNeighborhoodIterator.h:332
itk::ConstShapedNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::SizeValueType
typename SizeType::SizeValueType SizeValueType
Definition: itkConstShapedNeighborhoodIterator.h:91
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ConstShapedNeighborhoodIterator::ConstIterator::GetNeighborhoodOffset
OffsetType GetNeighborhoodOffset() const
Definition: itkConstShapedNeighborhoodIterator.h:208
itk::ConstShapedNeighborhoodIterator::operator=
Self & operator=(const Self &orig)
Definition: itkConstShapedNeighborhoodIterator.h:312
itk::ConstShapedNeighborhoodIterator::ConstIterator::operator=
ConstIterator & operator=(const ConstIterator &o)
Definition: itkConstShapedNeighborhoodIterator.h:129
itk::IndexValueType
long IndexValueType
Definition: itkIntTypes.h:90
itk::ConstNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::ImageType
ImageType ImageType
Definition: itkConstNeighborhoodIterator.h:77
itk::ConstShapedNeighborhoodIterator::ConstIterator::Self
friend Self
Definition: itkConstShapedNeighborhoodIterator.h:220
itk::ImageBoundaryCondition< ImageType, OutputImageType >
itk::ConstNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::InternalPixelType
typename ImageType ::InternalPixelType InternalPixelType
Definition: itkConstNeighborhoodIterator.h:56
itk::ConstShapedNeighborhoodIterator::Begin
ConstIterator Begin() const
Definition: itkConstShapedNeighborhoodIterator.h:241
itk::ConstShapedNeighborhoodIterator::ConstIterator::m_NeighborhoodIterator
Self * m_NeighborhoodIterator
Definition: itkConstShapedNeighborhoodIterator.h:227
itk::ConstShapedNeighborhoodIterator::ClearActiveList
ITK_ITERATOR_VIRTUAL void ClearActiveList() ITK_ITERATOR_FINAL
Definition: itkConstShapedNeighborhoodIterator.h:358
itk::ConstShapedNeighborhoodIterator::ConstIterator::ProtectedSet
void ProtectedSet(const PixelType &v) const
Definition: itkConstShapedNeighborhoodIterator.h:232
itk::ConstShapedNeighborhoodIterator::ActivateOffsets
void ActivateOffsets(const TOffsets &offsets)
Definition: itkConstShapedNeighborhoodIterator.h:347
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::ConstShapedNeighborhoodIterator::ConstIterator::GoToEnd
void GoToEnd()
Definition: itkConstShapedNeighborhoodIterator.h:196
itk::ConstShapedNeighborhoodIterator::ConstIterator::operator++
void operator++(int)
Definition: itkConstShapedNeighborhoodIterator.h:143
itk::ConstShapedNeighborhoodIterator::ConstIterator::operator++
const ConstIterator & operator++()
Definition: itkConstShapedNeighborhoodIterator.h:155
itk::ConstShapedNeighborhoodIterator
Const version of ShapedNeighborhoodIterator, defining iteration of a local N-dimensional neighborhood...
Definition: itkConstShapedNeighborhoodIterator.h:72
itk::ConstShapedNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::IndexListConstIterator
typename IndexListType::const_iterator IndexListConstIterator
Definition: itkConstShapedNeighborhoodIterator.h:107
itk::OffsetValueType
long OffsetValueType
Definition: itkIntTypes.h:94
itk::ConstShapedNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::IndexListType
std::list< NeighborIndexType > IndexListType
Definition: itkConstShapedNeighborhoodIterator.h:104
itk::ConstShapedNeighborhoodIterator::GetActiveIndexListSize
IndexListType::size_type GetActiveIndexListSize() const
Definition: itkConstShapedNeighborhoodIterator.h:374
itk::Offset
Represent a n-dimensional offset between two n-dimensional indexes of n-dimensional image.
Definition: itkOffset.h:69
itk::NeighborhoodIterator
Defines iteration of a local N-dimensional neighborhood of pixels across an itk::Image.
Definition: itkNeighborhoodIterator.h:212
itk::ConstShapedNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::OffsetValueType
typename OffsetType::OffsetValueType OffsetValueType
Definition: itkConstShapedNeighborhoodIterator.h:88
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ConstShapedNeighborhoodIterator::GetActiveIndexList
const IndexListType & GetActiveIndexList() const
Definition: itkConstShapedNeighborhoodIterator.h:367
itk::ConstNeighborhoodIterator
Const version of NeighborhoodIterator, defining iteration of a local N-dimensional neighborhood of pi...
Definition: itkConstNeighborhoodIterator.h:51
itk::ConstNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::RegionType
typename ImageType ::RegionType RegionType
Definition: itkConstNeighborhoodIterator.h:78
itk::ConstShapedNeighborhoodIterator::CreateActiveListFromNeighborhood
void CreateActiveListFromNeighborhood(const NeighborhoodType &neighborhood)
Definition: itkConstShapedNeighborhoodIterator.h:386
itk::ConstShapedNeighborhoodIterator::ConstIterator::ConstIterator
ConstIterator(const ConstIterator &o)
Definition: itkConstShapedNeighborhoodIterator.h:136
itk::ConstShapedNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::IndexListIterator
typename IndexListType::iterator IndexListIterator
Definition: itkConstShapedNeighborhoodIterator.h:106
itk::ConstShapedNeighborhoodIterator::ConstIterator::ConstIterator
ConstIterator()
Definition: itkConstShapedNeighborhoodIterator.h:118
itk::ZeroFluxNeumannBoundaryCondition< ImageType >
AddImageFilter
Definition: itkAddImageFilter.h:81
itk::Neighborhood::NeighborIndexType
SizeValueType NeighborIndexType
Definition: itkNeighborhood.h:96
itk::ConstShapedNeighborhoodIterator::ConstIterator
Definition: itkConstShapedNeighborhoodIterator.h:116
itk::ConstShapedNeighborhoodIterator::ConstIterator::operator==
bool operator==(const ConstIterator &o) const
Definition: itkConstShapedNeighborhoodIterator.h:169
itk::GTest::TypedefsAndConstructors::Dimension2::Dimension
constexpr unsigned int Dimension
Definition: itkGTestTypedefsAndConstructors.h:44
itk::ConstShapedNeighborhoodIterator::ConstIterator::operator--
void operator--(int)
Definition: itkConstShapedNeighborhoodIterator.h:149
itk::ConstShapedNeighborhoodIterator::End
ConstIterator End() const
Definition: itkConstShapedNeighborhoodIterator.h:249
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
itk::ConstShapedNeighborhoodIterator::ConstIterator::IsAtEnd
bool IsAtEnd() const
Definition: itkConstShapedNeighborhoodIterator.h:177
itk::ConstShapedNeighborhoodIterator::ConstIterator::operator--
const ConstIterator & operator--()
Definition: itkConstShapedNeighborhoodIterator.h:162