ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkConstNeighborhoodIteratorWithOnlyIndex.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 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:
61  public Neighborhood< char, TImage::ImageDimension >
62 {
63 public:
64 
66  using DimensionValueType = unsigned int;
67 
69  static constexpr DimensionValueType Dimension = TImage::ImageDimension;
70 
72 
76 
80  using SizeType = typename Superclass::SizeType;
81  using Iterator = typename Superclass::Iterator;
83 
85  using ImageType = TImage;
86  using RegionType = typename TImage::RegionType;
89 
92 
95 
97  ~ConstNeighborhoodIteratorWithOnlyIndex() override = default;
98 
101 
104  ConstNeighborhoodIteratorWithOnlyIndex(const SizeType & radius, const ImageType *ptr, const RegionType & region);
105 
107  Self & operator=(const Self & orig);
108 
110  void PrintSelf(std::ostream &, Indent) const override;
111 
114  OffsetType ComputeInternalIndex(NeighborIndexType n) const;
115 
118  {
119  return m_Bound;
120  }
121 
125  {
126  return m_Bound[n];
127  }
128 
130  const ImageType * GetImagePointer() const
131  {
132  return m_ConstImage;
133  }
134 
137  ITK_ITERATOR_VIRTUAL IndexType GetIndex() const ITK_ITERATOR_FINAL
138  {
139  return m_Loop;
140  }
141 
144  ITK_ITERATOR_VIRTUAL IndexType GetIndex(const OffsetType & o) const ITK_ITERATOR_FINAL
145  {
146  return ( this->GetIndex() + o );
147  }
148 
151  ITK_ITERATOR_VIRTUAL IndexType GetIndex(NeighborIndexType i) const ITK_ITERATOR_FINAL
152  {
153  return ( this->GetIndex() + this->GetOffset(i) );
154  }
155 
158  {
159  return m_Region;
160  }
161 
165  {
166  return m_BeginIndex;
167  }
168 
171  RegionType GetBoundingBoxAsImageRegion() const;
172 
174  ITK_ITERATOR_VIRTUAL void GoToBegin() ITK_ITERATOR_FINAL;
175 
178  ITK_ITERATOR_VIRTUAL void GoToEnd() ITK_ITERATOR_FINAL;
179 
182  ITK_ITERATOR_VIRTUAL void Initialize(const SizeType & radius, const ImageType *ptr, const RegionType & region) ITK_ITERATOR_FINAL;
183 
186  ITK_ITERATOR_VIRTUAL bool IsAtBegin() const ITK_ITERATOR_FINAL
187  {
188  return ( this->GetIndex() == m_BeginIndex );
189  }
190 
193  ITK_ITERATOR_VIRTUAL bool IsAtEnd() const ITK_ITERATOR_FINAL;
194 
199  Self & operator++();
200 
205  Self & operator--();
206 
210  bool operator==(const Self & it) const
211  {
212  return it.GetIndex() == this->GetIndex();
213  }
214 
218  bool operator!=(const Self & it) const
219  {
220  return it.GetIndex() != this->GetIndex();
221  }
222 
228  bool operator<(const Self & it) const;
229 
235  bool operator<=(const Self & it) const;
236 
242  bool operator>(const Self & it) const;
243 
249  bool operator>=(const Self & it) const;
250 
255  void SetLocation(const IndexType & position)
256  {
257  this->SetLoop(position);
258  }
259 
263  Self & operator+=(const OffsetType &);
264 
268  Self & operator-=(const OffsetType &);
269 
272  {
273  return m_Loop - b.m_Loop;
274  }
275 
279  bool InBounds() const;
280 
292  bool IndexInBounds(const NeighborIndexType n, OffsetType & internalIndex, OffsetType & offset ) const;
293 
296  {
297  this->SetNeedToUseBoundaryCondition(true);
298  }
299 
301  {
302  this->SetNeedToUseBoundaryCondition(false);
303  }
304 
306  {
307  m_NeedToUseBoundaryCondition = b;
308  }
309 
311  {
312  return m_NeedToUseBoundaryCondition;
313  }
314 
315 protected:
316 
319  ITK_ITERATOR_VIRTUAL void SetLoop(const IndexType & p) ITK_ITERATOR_FINAL
320  {
321  m_Loop = p; m_IsInBoundsValid = false;
322  }
323 
327  ITK_ITERATOR_VIRTUAL void SetBound(const SizeType &) ITK_ITERATOR_FINAL;
328 
331  ITK_ITERATOR_VIRTUAL void SetBeginIndex(const IndexType & start) ITK_ITERATOR_FINAL
332  {
333  m_BeginIndex = start;
334  }
335 
338  ITK_ITERATOR_VIRTUAL void SetEndIndex() ITK_ITERATOR_FINAL;
339 
342  IndexType m_BeginIndex;
343 
345  IndexType m_Bound;
346 
348  typename ImageType::ConstPointer m_ConstImage;
349 
352  IndexType m_EndIndex;
353 
355  IndexType m_Loop;
356 
358  RegionType m_Region;
359 
362  mutable bool m_InBounds[Dimension];
363 
365  mutable bool m_IsInBounds;
366 
370  mutable bool m_IsInBoundsValid;
371 
373  IndexType m_InnerBoundsLow;
374 
376  IndexType m_InnerBoundsHigh;
377 
379  bool m_NeedToUseBoundaryCondition;
380 };
381 
382 template< typename TImage >
384 operator+(const ConstNeighborhoodIteratorWithOnlyIndex< TImage > & it,
385  const typename ConstNeighborhoodIteratorWithOnlyIndex< TImage >
386  ::OffsetType & ind)
387 {
389  ret = it;
390  ret += ind;
391  return ret;
392 }
393 
394 template< typename TImage >
395 inline ConstNeighborhoodIteratorWithOnlyIndex< TImage >
397  ::OffsetType & ind,
399 { return ( it + ind ); }
400 
401 template< typename TImage >
402 inline ConstNeighborhoodIteratorWithOnlyIndex< TImage >
405  ::OffsetType & ind)
406 {
408  ret = it;
409  ret -= ind;
410  return ret;
411 }
412 } // namespace itk
413 
414 #ifndef ITK_MANUAL_INSTANTIATION
415 #include "itkConstNeighborhoodIteratorWithOnlyIndex.hxx"
416 #endif
417 
418 #endif
ConstNeighborhoodIterator< TImage > operator-(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
A light-weight container object for storing an N-dimensional neighborhood of values.
ITK_ITERATOR_VIRTUAL IndexType GetIndex() const ITK_ITERATOR_FINAL
Index-only version of ConstNeighborhoodIterator, defining iteration of a local N-dimensional neighbor...
bool operator>(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:507
SizeValueType NeighborIndexType
typename AllocatorType::iterator Iterator
ITK_ITERATOR_VIRTUAL IndexType GetIndex(const OffsetType &o) const ITK_ITERATOR_FINAL
typename AllocatorType::const_iterator ConstIterator
bool operator<=(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:514
ConstNeighborhoodIterator< TImage > operator+(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
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
bool operator<(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:499
Control indentation during Print() invocation.
Definition: itkIndent.h:49
ITK_ITERATOR_VIRTUAL void SetLoop(const IndexType &p) ITK_ITERATOR_FINAL
ITK_ITERATOR_VIRTUAL IndexType GetIndex(NeighborIndexType i) const ITK_ITERATOR_FINAL
bool operator>=(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:521
typename NeighborhoodType::NeighborIndexType NeighborIndexType