ITK  5.2.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  * 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 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 
90  using SizeType = 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  }
125 
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  bool
174  operator==(const ConstIterator & o) const
175  {
176  return m_ListIterator == o.m_ListIterator;
177  }
178 
179  bool
180  IsAtEnd() const
181  {
182  if (m_ListIterator == m_NeighborhoodIterator->GetActiveIndexList().end())
183  {
184  return true;
185  }
186  else
187  {
188  return false;
189  }
190  }
191 
192  void
194  {
195  m_ListIterator = m_NeighborhoodIterator->GetActiveIndexList().begin();
196  }
197 
198  void
200  {
201  m_ListIterator = m_NeighborhoodIterator->GetActiveIndexList().end();
202  }
203 
204  PixelType
205  Get() const
206  {
207  return m_NeighborhoodIterator->GetPixel(*m_ListIterator);
208  }
209 
210  OffsetType
212  {
213  return m_NeighborhoodIterator->GetOffset(*m_ListIterator);
214  }
215 
216  typename IndexListType::value_type
218  {
219  return *m_ListIterator;
220  }
221 
222  protected:
223  friend Self;
224 
225  ConstIterator(const Self * s, const typename IndexListType::const_iterator & li)
226  : m_NeighborhoodIterator(const_cast<Self *>(s))
227  , m_ListIterator(li)
228  {}
229 
231 
232  typename IndexListType::const_iterator m_ListIterator;
233 
234  void
235  ProtectedSet(const PixelType & v) const
236  {
237  m_NeighborhoodIterator->SetPixel(*m_ListIterator, v);
238  }
239  };
240 
243  ConstIterator
244  Begin() const
245  {
246  return ConstIterator(this, this->m_ActiveIndexList.begin());
247  }
248 
251  ConstIterator
252  End() const
253  {
254  return ConstIterator(this, this->m_ActiveIndexList.end());
255  }
256 
259 
261  ~ConstShapedNeighborhoodIterator() override = default;
262 
265  ConstShapedNeighborhoodIterator(const SizeType & radius, const ImageType * ptr, const RegionType & region)
266  : Superclass(radius, const_cast<ImageType *>(ptr), region)
267  {}
268 
271 
272  // Expose the following methods from the superclass. This is a
273  // restricted subset of the methods available for
274  // ConstNeighborhoodIterator.
275  using Superclass::GetImagePointer;
276  using Superclass::GetRadius;
277  using Superclass::GetIndex;
278  using Superclass::GetNeighborhoodIndex;
279  using Superclass::GetCenterNeighborhoodIndex;
280  using Superclass::GetRegion;
281  using Superclass::GetBeginIndex;
282  using Superclass::GoToBegin;
283  using Superclass::GoToEnd;
284  using Superclass::IsAtBegin;
285  using Superclass::IsAtEnd;
286  using Superclass::GetOffset;
287  using Superclass::operator==;
288  using Superclass::operator!=;
289  using Superclass::operator<;
290  using Superclass::operator>;
291  using Superclass::operator>=;
292  using Superclass::operator<=;
293  using Superclass::operator[];
294  using Superclass::GetElement;
295  using Superclass::SetLocation;
296  using Superclass::GetCenterPointer;
297  using Superclass::GetCenterPixel;
298  using Superclass::OverrideBoundaryCondition;
299  using Superclass::ResetBoundaryCondition;
300  using Superclass::GetBoundaryCondition;
301  using Superclass::SetBoundaryCondition;
302  using Superclass::GetNeedToUseBoundaryCondition;
303  using Superclass::SetNeedToUseBoundaryCondition;
304  using Superclass::NeedToUseBoundaryConditionOn;
305  using Superclass::NeedToUseBoundaryConditionOff;
306  using Superclass::Print;
307  using Superclass::operator-;
308  using Superclass::GetPixel;
309  using Superclass::SetRegion;
310 
312  Self &
313  operator=(const Self & orig)
314  {
315  if (this != &orig)
316  {
317  Superclass::operator=(orig);
318  m_ActiveIndexList = orig.m_ActiveIndexList;
319  m_CenterIsActive = orig.m_CenterIsActive;
320  }
321  return *this;
322  }
324 
326  void
327  PrintSelf(std::ostream &, Indent) const override;
328 
332  ITK_ITERATOR_VIRTUAL void
333  ActivateOffset(const OffsetType & off) ITK_ITERATOR_FINAL
334  {
335  this->ActivateIndex(Superclass::GetNeighborhoodIndex(off));
336  }
337  ITK_ITERATOR_VIRTUAL void
338  DeactivateOffset(const OffsetType & off) ITK_ITERATOR_FINAL
339  {
340  this->DeactivateIndex(Superclass::GetNeighborhoodIndex(off));
341  }
343 
346  template <typename TOffsets>
347  void
348  ActivateOffsets(const TOffsets & offsets)
349  {
350  for (const auto & offset : offsets)
351  {
352  this->ActivateOffset(offset);
353  }
354  }
356 
358  ITK_ITERATOR_VIRTUAL void
359  ClearActiveList() ITK_ITERATOR_FINAL
360  {
361  m_ActiveIndexList.clear();
362  m_CenterIsActive = false;
363  }
365 
367  const IndexListType &
369  {
370  return m_ActiveIndexList;
371  }
372 
374  typename IndexListType::size_type
376  {
377  return m_ActiveIndexList.size();
378  }
379 
383  void
384  CreateActiveListFromNeighborhood(const NeighborhoodType &);
385 
388  Self &
389  operator++();
390 
393  Self &
394  operator--();
395 
399  Self &
400  operator+=(const OffsetType &);
401 
405  Self &
406  operator-=(const OffsetType &);
407 
408 protected:
409  using Superclass::SetPixel;
410  using Superclass::SetCenterPixel;
411 
412  friend struct ConstIterator;
413 
416  // Superclass::SetPixel;
417  // Superclass::SetCenterPixel;
418 
424  ITK_ITERATOR_VIRTUAL void ActivateIndex(NeighborIndexType) ITK_ITERATOR_FINAL;
425 
426  ITK_ITERATOR_VIRTUAL void DeactivateIndex(NeighborIndexType) ITK_ITERATOR_FINAL;
427 
428 
429  bool m_CenterIsActive{ false };
431 };
432 } // namespace itk
433 
434 #ifndef ITK_MANUAL_INSTANTIATION
435 # include "itkConstShapedNeighborhoodIterator.hxx"
436 #endif
437 
438 #endif
itk::ConstShapedNeighborhoodIterator::ConstIterator::GetNeighborhoodIndex
IndexListType::value_type GetNeighborhoodIndex() const
Definition: itkConstShapedNeighborhoodIterator.h:217
itk::Index< Self::Dimension >
itk::ConstShapedNeighborhoodIterator::ConstIterator::ConstIterator
ConstIterator(const Self *s, const typename IndexListType::const_iterator &li)
Definition: itkConstShapedNeighborhoodIterator.h:225
itk::ConstShapedNeighborhoodIterator::ConstIterator::operator!=
bool operator!=(const ConstIterator &o) const
Definition: itkConstShapedNeighborhoodIterator.h:169
itk::ConstNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::RadiusType
typename Superclass::RadiusType RadiusType
Definition: itkConstNeighborhoodIterator.h:71
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:69
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:338
itk::ConstShapedNeighborhoodIterator::ConstIterator::m_ListIterator
IndexListType::const_iterator m_ListIterator
Definition: itkConstShapedNeighborhoodIterator.h:232
itk::ConstShapedNeighborhoodIterator::ConstIterator::GoToBegin
void GoToBegin()
Definition: itkConstShapedNeighborhoodIterator.h:193
itk::ConstShapedNeighborhoodIterator::m_ActiveIndexList
IndexListType m_ActiveIndexList
Definition: itkConstShapedNeighborhoodIterator.h:430
itk::ConstShapedNeighborhoodIterator::ConstShapedNeighborhoodIterator
ConstShapedNeighborhoodIterator(const SizeType &radius, const ImageType *ptr, const RegionType &region)
Definition: itkConstShapedNeighborhoodIterator.h:265
itk::ConstShapedNeighborhoodIterator::ConstIterator::Get
PixelType Get() const
Definition: itkConstShapedNeighborhoodIterator.h:205
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::ConstShapedNeighborhoodIterator::ActivateOffset
ITK_ITERATOR_VIRTUAL void ActivateOffset(const OffsetType &off) ITK_ITERATOR_FINAL
Definition: itkConstShapedNeighborhoodIterator.h:333
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:211
itk::ConstShapedNeighborhoodIterator::operator=
Self & operator=(const Self &orig)
Definition: itkConstShapedNeighborhoodIterator.h:313
itk::ConstShapedNeighborhoodIterator::ConstIterator::operator=
ConstIterator & operator=(const ConstIterator &o)
Definition: itkConstShapedNeighborhoodIterator.h:129
itk::ConstNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::ImageType
ImageType ImageType
Definition: itkConstNeighborhoodIterator.h:77
itk::ConstShapedNeighborhoodIterator::ConstIterator::Self
friend Self
Definition: itkConstShapedNeighborhoodIterator.h:223
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:244
itk::ConstShapedNeighborhoodIterator::ConstIterator::m_NeighborhoodIterator
Self * m_NeighborhoodIterator
Definition: itkConstShapedNeighborhoodIterator.h:230
itk::ConstShapedNeighborhoodIterator::ClearActiveList
ITK_ITERATOR_VIRTUAL void ClearActiveList() ITK_ITERATOR_FINAL
Definition: itkConstShapedNeighborhoodIterator.h:359
itk::ConstShapedNeighborhoodIterator::ConstIterator::ProtectedSet
void ProtectedSet(const PixelType &v) const
Definition: itkConstShapedNeighborhoodIterator.h:235
itk::ConstShapedNeighborhoodIterator::ActivateOffsets
void ActivateOffsets(const TOffsets &offsets)
Definition: itkConstShapedNeighborhoodIterator.h:348
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::ConstShapedNeighborhoodIterator::ConstIterator::GoToEnd
void GoToEnd()
Definition: itkConstShapedNeighborhoodIterator.h:199
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::ConstShapedNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::IndexListType
std::list< NeighborIndexType > IndexListType
Definition: itkConstShapedNeighborhoodIterator.h:104
itk::ConstShapedNeighborhoodIterator::GetActiveIndexListSize
IndexListType::size_type GetActiveIndexListSize() const
Definition: itkConstShapedNeighborhoodIterator.h:375
itk::Offset
Represent a n-dimensional offset between two n-dimensional indexes of n-dimensional image.
Definition: itkOffset.h:67
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:368
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::OffsetValueType
signed long OffsetValueType
Definition: itkIntTypes.h:94
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::IndexValueType
signed long IndexValueType
Definition: itkIntTypes.h:90
itk::ConstNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::ConstIterator
typename Superclass::ConstIterator ConstIterator
Definition: itkConstNeighborhoodIterator.h:74
itk::ConstShapedNeighborhoodIterator::ConstIterator::ConstIterator
ConstIterator()
Definition: itkConstShapedNeighborhoodIterator.h:118
itk::ConstNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::OffsetType
typename Superclass::OffsetType OffsetType
Definition: itkConstNeighborhoodIterator.h:70
itk::ZeroFluxNeumannBoundaryCondition< ImageType >
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:174
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:252
itk::ConstNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::SizeType
typename Superclass::SizeType SizeType
Definition: itkConstNeighborhoodIterator.h:72
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
itk::ConstShapedNeighborhoodIterator::ConstIterator::IsAtEnd
bool IsAtEnd() const
Definition: itkConstShapedNeighborhoodIterator.h:180
itk::ConstShapedNeighborhoodIterator::ConstIterator::operator--
const ConstIterator & operator--()
Definition: itkConstShapedNeighborhoodIterator.h:162