ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkConstShapedNeighborhoodIterator.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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,
71  typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition< TImage >
72  >
73 class ITK_TEMPLATE_EXPORT ConstShapedNeighborhoodIterator:
74  private NeighborhoodIterator< TImage, TBoundaryCondition >
75 {
76 public:
77 
79  using InternalPixelType = typename TImage::InternalPixelType;
80  using PixelType = typename TImage::PixelType;
81 
83  static constexpr unsigned int Dimension = TImage::ImageDimension;
84 
88 
93  using SizeType = typename Superclass::SizeType;
95 
97  using ImageType = TImage;
98  using RegionType = typename TImage::RegionType;
102 
104 
107  using IndexListType = std::list< NeighborIndexType >;
108 
109  using IndexListIterator = typename IndexListType::iterator;
110  using IndexListConstIterator = typename IndexListType::const_iterator;
111 
113  using BoundaryConditionType = TBoundaryCondition;
114 
117 
119  struct ConstIterator {
120  ConstIterator() { m_NeighborhoodIterator = nullptr; }
122  {
123  m_NeighborhoodIterator = s;
124  this->GoToBegin();
125  }
127 
128  ITK_ITERATOR_VIRTUAL ~ConstIterator() = default;
129 
131  {
132  m_NeighborhoodIterator = o.m_NeighborhoodIterator;
133  m_ListIterator = o.m_ListIterator;
134  return *this;
135  }
136 
138  {
139  m_NeighborhoodIterator = o.m_NeighborhoodIterator;
140  m_ListIterator = o.m_ListIterator;
141  }
142 
143  void operator++(int)
144  { m_ListIterator++; }
145 
146  void operator--(int)
147  { m_ListIterator--; }
148 
150  {
151  m_ListIterator++;
152  return *this;
153  }
154 
156  {
157  m_ListIterator--;
158  return *this;
159  }
160 
161  bool operator!=(const ConstIterator & o) const
162  { return m_ListIterator != o.m_ListIterator; }
163  bool operator==(const ConstIterator & o) const
164  { return m_ListIterator == o.m_ListIterator; }
165 
166  bool IsAtEnd() const
167  {
168  if ( m_ListIterator == m_NeighborhoodIterator->GetActiveIndexList().end() )
169  {
170  return true;
171  }
172  else
173  {
174  return false;
175  }
176  }
177 
178  void GoToBegin()
179  {
180  m_ListIterator = m_NeighborhoodIterator->GetActiveIndexList().begin();
181  }
182 
183  void GoToEnd()
184  {
185  m_ListIterator = m_NeighborhoodIterator->GetActiveIndexList().end();
186  }
187 
188  PixelType Get() const
189  { return m_NeighborhoodIterator->GetPixel(*m_ListIterator); }
190 
192  { return m_NeighborhoodIterator->GetOffset(*m_ListIterator); }
193 
194  typename IndexListType::value_type GetNeighborhoodIndex() const
195  { return *m_ListIterator; }
196 
197  protected:
198 
199  friend Self;
200 
201  ConstIterator( const Self *s, const typename IndexListType::const_iterator &li )
202  : m_NeighborhoodIterator(const_cast<Self*>(s)),
203  m_ListIterator(li)
204  { }
205 
207 
208  typename IndexListType::const_iterator m_ListIterator;
209 
210  void ProtectedSet(const PixelType & v) const
211  { m_NeighborhoodIterator->SetPixel(*m_ListIterator, v); }
212  };
213 
217  { return ConstIterator(this, this->m_ActiveIndexList.begin()); }
218 
222  { return ConstIterator(this, this->m_ActiveIndexList.end()); }
223 
226 
228  ~ConstShapedNeighborhoodIterator() override = default;
229 
233  const ImageType *ptr,
234  const RegionType & region):
235  Superclass (radius, const_cast< ImageType * >( ptr ), region)
236  {
237  }
238 
239  // Expose the following methods from the superclass. This is a
240  // restricted subset of the methods available for
241  // ConstNeighborhoodIterator.
242  using Superclass::GetImagePointer;
243  using Superclass::GetRadius;
244  using Superclass::GetIndex;
245  using Superclass::GetNeighborhoodIndex;
246  using Superclass::GetCenterNeighborhoodIndex;
247  using Superclass::GetRegion;
248  using Superclass::GetBeginIndex;
249  using Superclass::GoToBegin;
250  using Superclass::GoToEnd;
251  using Superclass::IsAtBegin;
252  using Superclass::IsAtEnd;
253  using Superclass::GetOffset;
254  using Superclass::operator==;
255  using Superclass::operator!=;
256  using Superclass::operator<;
257  using Superclass::operator>;
258  using Superclass::operator>=;
259  using Superclass::operator<=;
260  using Superclass::operator[];
261  using Superclass::GetElement;
262  using Superclass::SetLocation;
263  using Superclass::GetCenterPointer;
264  using Superclass::GetCenterPixel;
265  using Superclass::OverrideBoundaryCondition;
266  using Superclass::ResetBoundaryCondition;
267  using Superclass::GetBoundaryCondition;
268  using Superclass::GetNeedToUseBoundaryCondition;
269  using Superclass::SetNeedToUseBoundaryCondition;
270  using Superclass::NeedToUseBoundaryConditionOn;
271  using Superclass::NeedToUseBoundaryConditionOff;
272  using Superclass::Print;
273  using Superclass::operator-;
274  using Superclass::GetPixel;
275  using Superclass::SetRegion;
276 
278  Self & operator=(const Self & orig)
279  {
280  if(this != &orig)
281  {
282  Superclass::operator=(orig);
283  m_ActiveIndexList = orig.m_ActiveIndexList;
284  m_CenterIsActive = orig.m_CenterIsActive;
286 
287  }
288  return *this;
289  }
290 
292  void PrintSelf(std::ostream &, Indent) const override;
293 
297  ITK_ITERATOR_VIRTUAL void ActivateOffset(const OffsetType & off) ITK_ITERATOR_FINAL
298  { this->ActivateIndex( Superclass::GetNeighborhoodIndex(off) ); }
299  ITK_ITERATOR_VIRTUAL void DeactivateOffset(const OffsetType & off) ITK_ITERATOR_FINAL
300  { this->DeactivateIndex( Superclass::GetNeighborhoodIndex(off) ); }
302 
305  template <typename TOffsets>
306  void ActivateOffsets(const TOffsets& offsets)
307  {
308  for (const auto& offset: offsets)
309  {
310  this->ActivateOffset(offset);
311  }
312  }
314 
316  ITK_ITERATOR_VIRTUAL void ClearActiveList() ITK_ITERATOR_FINAL
317  {
318  m_ActiveIndexList.clear();
319  m_CenterIsActive = false;
320  }
322 
325  { return m_ActiveIndexList; }
326 
328  typename IndexListType::size_type GetActiveIndexListSize() const
329  { return m_ActiveIndexList.size(); }
330 
334  void CreateActiveListFromNeighborhood(const NeighborhoodType &);
335 
338  Self & operator++();
339 
342  Self & operator--();
343 
347  Self & operator+=(const OffsetType &);
348 
352  Self & operator-=(const OffsetType &);
353 
354 protected:
355  using Superclass::SetPixel;
356  using Superclass::SetCenterPixel;
357 
358  friend struct ConstIterator;
359 
362  // Superclass::SetPixel;
363  // Superclass::SetCenterPixel;
364 
370  ITK_ITERATOR_VIRTUAL void ActivateIndex( NeighborIndexType ) ITK_ITERATOR_FINAL;
371 
372  ITK_ITERATOR_VIRTUAL void DeactivateIndex( NeighborIndexType ) ITK_ITERATOR_FINAL;
373 
374 
375  bool m_CenterIsActive{ false };
377 
378 private:
381 };
382 } // namespace itk
383 
384 #ifndef ITK_MANUAL_INSTANTIATION
385 #include "itkConstShapedNeighborhoodIterator.hxx"
386 #endif
387 
388 #endif
Const version of ShapedNeighborhoodIterator, defining iteration of a local N-dimensional neighborhood...
ITK_ITERATOR_VIRTUAL void ActivateOffset(const OffsetType &off) ITK_ITERATOR_FINAL
unsigned long SizeValueType
Definition: itkIntTypes.h:83
A light-weight container object for storing an N-dimensional neighborhood of values.
SizeValueType NeighborIndexType
ITK_ITERATOR_VIRTUAL void ClearActiveList() ITK_ITERATOR_FINAL
Const version of NeighborhoodIterator, defining iteration of a local N-dimensional neighborhood of pi...
IndexListType::size_type GetActiveIndexListSize() const
signed long IndexValueType
Definition: itkIntTypes.h:90
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:68
Represent a n-dimensional offset between two n-dimensional indexes of n-dimensional image...
Definition: itkOffset.h:67
ConstShapedNeighborhoodIterator(const SizeType &radius, const ImageType *ptr, const RegionType &region)
ConstIterator(const Self *s, const typename IndexListType::const_iterator &li)
ITK_ITERATOR_VIRTUAL void DeactivateOffset(const OffsetType &off) ITK_ITERATOR_FINAL
Control indentation during Print() invocation.
Definition: itkIndent.h:49
signed long OffsetValueType
Definition: itkIntTypes.h:94
Defines iteration of a local N-dimensional neighborhood of pixels across an itk::Image.