ITK  5.1.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 {
70 template <typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
71 class ITK_TEMPLATE_EXPORT ConstShapedNeighborhoodIterator : private NeighborhoodIterator<TImage, TBoundaryCondition>
72 {
73 public:
75  using InternalPixelType = typename TImage::InternalPixelType;
76  using PixelType = typename TImage::PixelType;
77 
79  static constexpr unsigned int Dimension = TImage::ImageDimension;
80 
84 
89  using SizeType = typename Superclass::SizeType;
91 
93  using ImageType = TImage;
94  using RegionType = typename TImage::RegionType;
98 
100 
103  using IndexListType = std::list<NeighborIndexType>;
104 
105  using IndexListIterator = typename IndexListType::iterator;
106  using IndexListConstIterator = typename IndexListType::const_iterator;
107 
109  using BoundaryConditionType = TBoundaryCondition;
110 
113 
116  {
117  ConstIterator() { m_NeighborhoodIterator = nullptr; }
119  {
120  m_NeighborhoodIterator = s;
121  this->GoToBegin();
122  }
124 
125  ITK_ITERATOR_VIRTUAL ~ConstIterator() = default;
126 
127  ConstIterator &
129  {
130  m_NeighborhoodIterator = o.m_NeighborhoodIterator;
131  m_ListIterator = o.m_ListIterator;
132  return *this;
133  }
134 
136  {
137  m_NeighborhoodIterator = o.m_NeighborhoodIterator;
138  m_ListIterator = o.m_ListIterator;
139  }
140 
141  void
143  {
144  m_ListIterator++;
145  }
146 
147  void
149  {
150  m_ListIterator--;
151  }
152 
153  const ConstIterator &
155  {
156  m_ListIterator++;
157  return *this;
158  }
159 
160  const ConstIterator &
162  {
163  m_ListIterator--;
164  return *this;
165  }
166 
167  bool
168  operator!=(const ConstIterator & o) const
169  {
170  return m_ListIterator != o.m_ListIterator;
171  }
172  bool
173  operator==(const ConstIterator & o) const
174  {
175  return m_ListIterator == o.m_ListIterator;
176  }
177 
178  bool
179  IsAtEnd() const
180  {
181  if (m_ListIterator == m_NeighborhoodIterator->GetActiveIndexList().end())
182  {
183  return true;
184  }
185  else
186  {
187  return false;
188  }
189  }
190 
191  void
193  {
194  m_ListIterator = m_NeighborhoodIterator->GetActiveIndexList().begin();
195  }
196 
197  void
199  {
200  m_ListIterator = m_NeighborhoodIterator->GetActiveIndexList().end();
201  }
202 
203  PixelType
204  Get() const
205  {
206  return m_NeighborhoodIterator->GetPixel(*m_ListIterator);
207  }
208 
209  OffsetType
211  {
212  return m_NeighborhoodIterator->GetOffset(*m_ListIterator);
213  }
214 
215  typename IndexListType::value_type
217  {
218  return *m_ListIterator;
219  }
220 
221  protected:
222  friend Self;
223 
224  ConstIterator(const Self * s, const typename IndexListType::const_iterator & li)
225  : m_NeighborhoodIterator(const_cast<Self *>(s))
226  , m_ListIterator(li)
227  {}
228 
230 
231  typename IndexListType::const_iterator m_ListIterator;
232 
233  void
234  ProtectedSet(const PixelType & v) const
235  {
236  m_NeighborhoodIterator->SetPixel(*m_ListIterator, v);
237  }
238  };
239 
242  ConstIterator
243  Begin() const
244  {
245  return ConstIterator(this, this->m_ActiveIndexList.begin());
246  }
247 
250  ConstIterator
251  End() const
252  {
253  return ConstIterator(this, this->m_ActiveIndexList.end());
254  }
255 
258 
260  ~ConstShapedNeighborhoodIterator() override = default;
261 
264  ConstShapedNeighborhoodIterator(const SizeType & radius, const ImageType * ptr, const RegionType & region)
265  : Superclass(radius, const_cast<ImageType *>(ptr), region)
266  {}
267 
270 
271  // Expose the following methods from the superclass. This is a
272  // restricted subset of the methods available for
273  // ConstNeighborhoodIterator.
274  using Superclass::GetImagePointer;
275  using Superclass::GetRadius;
276  using Superclass::GetIndex;
277  using Superclass::GetNeighborhoodIndex;
278  using Superclass::GetCenterNeighborhoodIndex;
279  using Superclass::GetRegion;
280  using Superclass::GetBeginIndex;
281  using Superclass::GoToBegin;
282  using Superclass::GoToEnd;
283  using Superclass::IsAtBegin;
284  using Superclass::IsAtEnd;
285  using Superclass::GetOffset;
286  using Superclass::operator==;
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::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::GetNeedToUseBoundaryCondition;
301  using Superclass::SetNeedToUseBoundaryCondition;
302  using Superclass::NeedToUseBoundaryConditionOn;
303  using Superclass::NeedToUseBoundaryConditionOff;
304  using Superclass::Print;
305  using Superclass::operator-;
306  using Superclass::GetPixel;
307  using Superclass::SetRegion;
308 
310  Self &
311  operator=(const Self & orig)
312  {
313  if (this != &orig)
314  {
315  Superclass::operator=(orig);
316  m_ActiveIndexList = orig.m_ActiveIndexList;
317  m_CenterIsActive = orig.m_CenterIsActive;
318  }
319  return *this;
320  }
322 
324  void
325  PrintSelf(std::ostream &, Indent) const override;
326 
330  ITK_ITERATOR_VIRTUAL void
331  ActivateOffset(const OffsetType & off) ITK_ITERATOR_FINAL
332  {
333  this->ActivateIndex(Superclass::GetNeighborhoodIndex(off));
334  }
335  ITK_ITERATOR_VIRTUAL void
336  DeactivateOffset(const OffsetType & off) ITK_ITERATOR_FINAL
337  {
338  this->DeactivateIndex(Superclass::GetNeighborhoodIndex(off));
339  }
341 
344  template <typename TOffsets>
345  void
346  ActivateOffsets(const TOffsets & offsets)
347  {
348  for (const auto & offset : offsets)
349  {
350  this->ActivateOffset(offset);
351  }
352  }
354 
356  ITK_ITERATOR_VIRTUAL void
357  ClearActiveList() ITK_ITERATOR_FINAL
358  {
359  m_ActiveIndexList.clear();
360  m_CenterIsActive = false;
361  }
363 
365  const IndexListType &
367  {
368  return m_ActiveIndexList;
369  }
370 
372  typename IndexListType::size_type
374  {
375  return m_ActiveIndexList.size();
376  }
377 
381  void
382  CreateActiveListFromNeighborhood(const NeighborhoodType &);
383 
386  Self &
387  operator++();
388 
391  Self &
392  operator--();
393 
397  Self &
398  operator+=(const OffsetType &);
399 
403  Self &
404  operator-=(const OffsetType &);
405 
406 protected:
407  using Superclass::SetPixel;
408  using Superclass::SetCenterPixel;
409 
410  friend struct ConstIterator;
411 
414  // Superclass::SetPixel;
415  // Superclass::SetCenterPixel;
416 
422  ITK_ITERATOR_VIRTUAL void ActivateIndex(NeighborIndexType) ITK_ITERATOR_FINAL;
423 
424  ITK_ITERATOR_VIRTUAL void DeactivateIndex(NeighborIndexType) ITK_ITERATOR_FINAL;
425 
426 
427  bool m_CenterIsActive{ false };
429 };
430 } // namespace itk
431 
432 #ifndef ITK_MANUAL_INSTANTIATION
433 # include "itkConstShapedNeighborhoodIterator.hxx"
434 #endif
435 
436 #endif
itk::ConstShapedNeighborhoodIterator::ConstIterator::GetNeighborhoodIndex
IndexListType::value_type GetNeighborhoodIndex() const
Definition: itkConstShapedNeighborhoodIterator.h:216
itk::Index< Self::Dimension >
itk::ConstShapedNeighborhoodIterator::ConstIterator::ConstIterator
ConstIterator(const Self *s, const typename IndexListType::const_iterator &li)
Definition: itkConstShapedNeighborhoodIterator.h:224
itk::ConstShapedNeighborhoodIterator::ConstIterator::operator!=
bool operator!=(const ConstIterator &o) const
Definition: itkConstShapedNeighborhoodIterator.h:168
itk::ConstNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::RadiusType
typename Superclass::RadiusType RadiusType
Definition: itkConstNeighborhoodIterator.h:70
itk::ConstNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::NeighborIndexType
typename NeighborhoodType::NeighborIndexType NeighborIndexType
Definition: itkConstNeighborhoodIterator.h:88
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:56
itkNeighborhoodIterator.h
itk::ConstShapedNeighborhoodIterator::ConstIterator::ConstIterator
ConstIterator(Self *s)
Definition: itkConstShapedNeighborhoodIterator.h:118
itk::ConstShapedNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::IndexValueType
typename IndexType::IndexValueType IndexValueType
Definition: itkConstShapedNeighborhoodIterator.h:96
itk::ConstShapedNeighborhoodIterator::DeactivateOffset
ITK_ITERATOR_VIRTUAL void DeactivateOffset(const OffsetType &off) ITK_ITERATOR_FINAL
Definition: itkConstShapedNeighborhoodIterator.h:336
itk::ConstShapedNeighborhoodIterator::ConstIterator::m_ListIterator
IndexListType::const_iterator m_ListIterator
Definition: itkConstShapedNeighborhoodIterator.h:231
itk::ConstShapedNeighborhoodIterator::ConstIterator::GoToBegin
void GoToBegin()
Definition: itkConstShapedNeighborhoodIterator.h:192
itk::ConstShapedNeighborhoodIterator::m_ActiveIndexList
IndexListType m_ActiveIndexList
Definition: itkConstShapedNeighborhoodIterator.h:428
itk::ConstShapedNeighborhoodIterator::ConstShapedNeighborhoodIterator
ConstShapedNeighborhoodIterator(const SizeType &radius, const ImageType *ptr, const RegionType &region)
Definition: itkConstShapedNeighborhoodIterator.h:264
itk::ConstShapedNeighborhoodIterator::ConstIterator::Get
PixelType Get() const
Definition: itkConstShapedNeighborhoodIterator.h:204
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:331
itk::ConstShapedNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::SizeValueType
typename SizeType::SizeValueType SizeValueType
Definition: itkConstShapedNeighborhoodIterator.h:90
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ConstShapedNeighborhoodIterator::ConstIterator::GetNeighborhoodOffset
OffsetType GetNeighborhoodOffset() const
Definition: itkConstShapedNeighborhoodIterator.h:210
itk::ConstShapedNeighborhoodIterator::operator=
Self & operator=(const Self &orig)
Definition: itkConstShapedNeighborhoodIterator.h:311
itk::ConstShapedNeighborhoodIterator::ConstIterator::operator=
ConstIterator & operator=(const ConstIterator &o)
Definition: itkConstShapedNeighborhoodIterator.h:128
itk::ConstNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::ImageType
ImageType ImageType
Definition: itkConstNeighborhoodIterator.h:76
itk::ConstShapedNeighborhoodIterator::ConstIterator::Self
friend Self
Definition: itkConstShapedNeighborhoodIterator.h:222
itk::ImageBoundaryCondition< ImageType, OutputImageType >
itk::ConstNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::InternalPixelType
typename ImageType ::InternalPixelType InternalPixelType
Definition: itkConstNeighborhoodIterator.h:55
itk::ConstShapedNeighborhoodIterator::Begin
ConstIterator Begin() const
Definition: itkConstShapedNeighborhoodIterator.h:243
itk::ConstShapedNeighborhoodIterator::ConstIterator::m_NeighborhoodIterator
Self * m_NeighborhoodIterator
Definition: itkConstShapedNeighborhoodIterator.h:229
itk::ConstShapedNeighborhoodIterator::ClearActiveList
ITK_ITERATOR_VIRTUAL void ClearActiveList() ITK_ITERATOR_FINAL
Definition: itkConstShapedNeighborhoodIterator.h:357
itk::ConstShapedNeighborhoodIterator::ConstIterator::ProtectedSet
void ProtectedSet(const PixelType &v) const
Definition: itkConstShapedNeighborhoodIterator.h:234
itk::ConstShapedNeighborhoodIterator::ActivateOffsets
void ActivateOffsets(const TOffsets &offsets)
Definition: itkConstShapedNeighborhoodIterator.h:346
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::ConstShapedNeighborhoodIterator::ConstIterator::GoToEnd
void GoToEnd()
Definition: itkConstShapedNeighborhoodIterator.h:198
itk::ConstShapedNeighborhoodIterator::ConstIterator::operator++
void operator++(int)
Definition: itkConstShapedNeighborhoodIterator.h:142
itk::ConstShapedNeighborhoodIterator::ConstIterator::operator++
const ConstIterator & operator++()
Definition: itkConstShapedNeighborhoodIterator.h:154
itk::ConstShapedNeighborhoodIterator
Const version of ShapedNeighborhoodIterator, defining iteration of a local N-dimensional neighborhood...
Definition: itkConstShapedNeighborhoodIterator.h:71
itk::ConstShapedNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::IndexListConstIterator
typename IndexListType::const_iterator IndexListConstIterator
Definition: itkConstShapedNeighborhoodIterator.h:106
itk::ConstShapedNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::IndexListType
std::list< NeighborIndexType > IndexListType
Definition: itkConstShapedNeighborhoodIterator.h:103
itk::ConstShapedNeighborhoodIterator::GetActiveIndexListSize
IndexListType::size_type GetActiveIndexListSize() const
Definition: itkConstShapedNeighborhoodIterator.h:373
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:211
itk::ConstShapedNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::OffsetValueType
typename OffsetType::OffsetValueType OffsetValueType
Definition: itkConstShapedNeighborhoodIterator.h:87
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkArray.h:26
itk::ConstShapedNeighborhoodIterator::GetActiveIndexList
const IndexListType & GetActiveIndexList() const
Definition: itkConstShapedNeighborhoodIterator.h:366
itk::ConstNeighborhoodIterator
Const version of NeighborhoodIterator, defining iteration of a local N-dimensional neighborhood of pi...
Definition: itkConstNeighborhoodIterator.h:50
itk::ConstNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::RegionType
typename ImageType ::RegionType RegionType
Definition: itkConstNeighborhoodIterator.h:77
itk::OffsetValueType
signed long OffsetValueType
Definition: itkIntTypes.h:94
itk::ConstShapedNeighborhoodIterator::ConstIterator::ConstIterator
ConstIterator(const ConstIterator &o)
Definition: itkConstShapedNeighborhoodIterator.h:135
itk::ConstShapedNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::IndexListIterator
typename IndexListType::iterator IndexListIterator
Definition: itkConstShapedNeighborhoodIterator.h:105
itk::IndexValueType
signed long IndexValueType
Definition: itkIntTypes.h:90
itk::ConstNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::ConstIterator
typename Superclass::ConstIterator ConstIterator
Definition: itkConstNeighborhoodIterator.h:73
itk::ConstShapedNeighborhoodIterator::ConstIterator::ConstIterator
ConstIterator()
Definition: itkConstShapedNeighborhoodIterator.h:117
itk::ConstNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::OffsetType
typename Superclass::OffsetType OffsetType
Definition: itkConstNeighborhoodIterator.h:69
itk::ZeroFluxNeumannBoundaryCondition< ImageType >
itk::Neighborhood::NeighborIndexType
SizeValueType NeighborIndexType
Definition: itkNeighborhood.h:96
itk::ConstShapedNeighborhoodIterator::ConstIterator
Definition: itkConstShapedNeighborhoodIterator.h:115
itk::ConstShapedNeighborhoodIterator::ConstIterator::operator==
bool operator==(const ConstIterator &o) const
Definition: itkConstShapedNeighborhoodIterator.h:173
itk::GTest::TypedefsAndConstructors::Dimension2::Dimension
constexpr unsigned int Dimension
Definition: itkGTestTypedefsAndConstructors.h:44
itk::ConstShapedNeighborhoodIterator::ConstIterator::operator--
void operator--(int)
Definition: itkConstShapedNeighborhoodIterator.h:148
itk::ConstShapedNeighborhoodIterator::End
ConstIterator End() const
Definition: itkConstShapedNeighborhoodIterator.h:251
itk::ConstNeighborhoodIterator< ImageType, ZeroFluxNeumannBoundaryCondition< ImageType > >::SizeType
typename Superclass::SizeType SizeType
Definition: itkConstNeighborhoodIterator.h:71
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
itk::ConstShapedNeighborhoodIterator::ConstIterator::IsAtEnd
bool IsAtEnd() const
Definition: itkConstShapedNeighborhoodIterator.h:179
itk::ConstShapedNeighborhoodIterator::ConstIterator::operator--
const ConstIterator & operator--()
Definition: itkConstShapedNeighborhoodIterator.h:161