ITK  5.2.0
Insight Toolkit
itkImageToNeighborhoodSampleAdaptor.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 itkImageToNeighborhoodSampleAdaptor_h
19 #define itkImageToNeighborhoodSampleAdaptor_h
20 
21 #include <typeinfo>
22 #include <vector>
23 #include <iostream>
24 
25 #include "itkImage.h"
26 #include "itkListSample.h"
27 #include "itkSmartPointer.h"
29 #include "itkMacro.h"
32 
33 namespace itk
34 {
35 namespace Statistics
36 {
37 
54 template <typename TImage, typename TBoundaryCondition>
55 class ITK_TEMPLATE_EXPORT ImageToNeighborhoodSampleAdaptor
56  : public ListSample<std::vector<ConstNeighborhoodIterator<TImage, TBoundaryCondition>>>
57 {
58 public:
59  ITK_DISALLOW_COPY_AND_MOVE(ImageToNeighborhoodSampleAdaptor);
60 
63 
65 
68 
71 
73  itkNewMacro(Self);
74 
76  using ImageType = TImage;
77  using ImagePointer = typename ImageType::Pointer;
78  using ImageConstPointer = typename ImageType::ConstPointer;
79  using IndexType = typename ImageType::IndexType;
80  using OffsetType = typename ImageType::OffsetType;
82  using PixelType = typename ImageType::PixelType;
83  using PixelContainerConstPointer = typename ImageType::PixelContainerConstPointer;
85  using OffsetTableType = typename RegionType::OffsetTableType;
86  using SizeType = typename ImageType::SizeType;
88 
96 
99  using MeasurementVectorType = typename std::vector<ConstNeighborhoodIterator<TImage, TBoundaryCondition>>;
100  using ValueType = typename MeasurementVectorType::value_type;
102 
103  using AbsoluteFrequencyType = typename Superclass::AbsoluteFrequencyType;
104  using TotalAbsoluteFrequencyType = typename Superclass::TotalAbsoluteFrequencyType;
105  using MeasurementVectorSizeType = typename Superclass::MeasurementVectorSizeType;
107 
109  void
110  SetImage(const TImage * image);
111 
113  const TImage *
114  GetImage() const;
115 
117  void
118  SetRadius(const NeighborhoodRadiusType & radius);
119 
122  GetRadius() const;
123 
125  void
126  SetRegion(const RegionType & region);
127 
129  RegionType
130  GetRegion() const;
131 
132  void
133  SetUseImageRegion(const bool & flag);
134 
136  itkGetConstMacro(UseImageRegion, bool);
137 
139  itkBooleanMacro(UseImageRegion);
140 
141 
144  Size() const override;
145 
147  const MeasurementVectorType &
148  GetMeasurementVector(InstanceIdentifier id) const override;
149 
152  GetFrequency(InstanceIdentifier id) const override;
153 
156  GetTotalFrequency() const override;
157 
164  {
166 
167  public:
168  ConstIterator() = delete;
169 
170  ConstIterator(const ImageToNeighborhoodSampleAdaptor * adaptor) { *this = adaptor->Begin(); }
171 
173  {
174  m_MeasurementVectorCache = iter.m_MeasurementVectorCache;
175  m_InstanceIdentifier = iter.m_InstanceIdentifier;
176  }
177 
178  ConstIterator &
179  operator=(const ConstIterator & iter)
180  {
181  m_MeasurementVectorCache = iter.m_MeasurementVectorCache;
182  m_InstanceIdentifier = iter.m_InstanceIdentifier;
183  return *this;
184  }
185 
187  GetFrequency() const
188  {
189  return 1;
190  }
191 
192  const MeasurementVectorType &
194  {
195  return this->m_MeasurementVectorCache;
196  }
197 
200  {
201  return m_InstanceIdentifier;
202  }
203 
204  ConstIterator &
206  {
207  ++(m_MeasurementVectorCache[0]);
208  ++m_InstanceIdentifier;
209  return *this;
210  }
211 
212  bool
213  operator!=(const ConstIterator & it) const
214  {
215  return (m_MeasurementVectorCache[0] != it.m_MeasurementVectorCache[0]);
216  }
217 
218  bool
219  operator==(const ConstIterator & it) const
220  {
221  return (m_MeasurementVectorCache[0] == it.m_MeasurementVectorCache[0]);
222  }
223 
224  protected:
225  // This method should only be available to the ListSample class
227  {
228  this->m_MeasurementVectorCache.clear();
229  this->m_MeasurementVectorCache.push_back(iter);
230  m_InstanceIdentifier = iid;
231  }
232 
233  private:
236  };
237 
243  class Iterator : public ConstIterator
244  {
245 
247 
248  public:
249  Iterator() = delete;
250  Iterator(const Self * adaptor) = delete;
251  Iterator(const ConstIterator & it) = delete;
252  ConstIterator &
253  operator=(const ConstIterator & it) = delete;
254 
255  Iterator(Self * adaptor)
256  : ConstIterator(adaptor)
257  {}
258 
259  Iterator(const Iterator & iter)
260  : ConstIterator(iter)
261  {}
262 
263  Iterator &
264  operator=(const Iterator & iter)
265  {
266  this->ConstIterator::operator=(iter);
267  return *this;
268  }
269 
270  protected:
271  // This copy constructor is actually used in Iterator Begin()!
273  : ConstIterator(iter, iid)
274  {}
275  };
276 
278  Iterator
280  {
281  NeighborhoodIteratorType nIterator(m_Radius, m_Image, m_Region);
282  nIterator.GoToBegin();
283  Iterator iter(nIterator, 0);
284  return iter;
285  }
287 
289  Iterator
290  End()
291  {
292  NeighborhoodIteratorType nIterator(m_Radius, m_Image, m_Region);
293  nIterator.GoToEnd();
294  Iterator iter(nIterator, m_Region.GetNumberOfPixels());
295  return iter;
296  }
298 
299 
301  ConstIterator
302  Begin() const
303  {
304  NeighborhoodIteratorType nIterator(m_Radius, m_Image, m_Region);
305  nIterator.GoToBegin();
306  ConstIterator iter(nIterator, 0);
307  return iter;
308  }
310 
312  ConstIterator
313  End() const
314  {
315  NeighborhoodIteratorType nIterator(m_Radius, m_Image, m_Region);
316  nIterator.GoToEnd();
317  ConstIterator iter(nIterator, m_Region.GetNumberOfPixels());
318  return iter;
319  }
321 
322 protected:
324  ~ImageToNeighborhoodSampleAdaptor() override = default;
325  void
326  PrintSelf(std::ostream & os, Indent indent) const override;
327 
328 private:
335  bool m_UseImageRegion{ true };
337 
338 }; // end of class ImageToNeighborhoodSampleAdaptor
339 
340 } // end of namespace Statistics
341 
342 template <typename TImage, typename TBoundaryCondition>
343 std::ostream &
344 operator<<(std::ostream & os, const std::vector<itk::ConstNeighborhoodIterator<TImage, TBoundaryCondition>> & mv);
345 
346 } // end of namespace itk
347 
348 #ifndef ITK_MANUAL_INSTANTIATION
349 # include "itkImageToNeighborhoodSampleAdaptor.hxx"
350 #endif
351 
352 #endif
itk::Statistics::ImageToNeighborhoodSampleAdaptor::OffsetType
typename ImageType::OffsetType OffsetType
Definition: itkImageToNeighborhoodSampleAdaptor.h:80
itk::Statistics::ImageToNeighborhoodSampleAdaptor::ConstIterator::operator=
ConstIterator & operator=(const ConstIterator &iter)
Definition: itkImageToNeighborhoodSampleAdaptor.h:179
itk::Statistics::ImageToNeighborhoodSampleAdaptor::ImageType
TImage ImageType
Definition: itkImageToNeighborhoodSampleAdaptor.h:76
itk::Statistics::ImageToNeighborhoodSampleAdaptor::Iterator::operator=
Iterator & operator=(const Iterator &iter)
Definition: itkImageToNeighborhoodSampleAdaptor.h:264
itk::ConstNeighborhoodIterator::RadiusType
typename Superclass::RadiusType RadiusType
Definition: itkConstNeighborhoodIterator.h:71
itkConstNeighborhoodIterator.h
itk::Statistics::ImageToNeighborhoodSampleAdaptor::PixelType
typename ImageType::PixelType PixelType
Definition: itkImageToNeighborhoodSampleAdaptor.h:82
itk::Size
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:69
itk::Statistics::ImageToNeighborhoodSampleAdaptor::End
ConstIterator End() const
Definition: itkImageToNeighborhoodSampleAdaptor.h:313
itk::Statistics::ImageToNeighborhoodSampleAdaptor::AbsoluteFrequencyType
typename Superclass::AbsoluteFrequencyType AbsoluteFrequencyType
Definition: itkImageToNeighborhoodSampleAdaptor.h:103
itkNeighborhoodIterator.h
itk::operator<<
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:218
itk::Statistics::ImageToNeighborhoodSampleAdaptor::ConstIterator::operator==
bool operator==(const ConstIterator &it) const
Definition: itkImageToNeighborhoodSampleAdaptor.h:219
itk::Statistics::ImageToNeighborhoodSampleAdaptor::ConstIterator::ConstIterator
ConstIterator(const ConstIterator &iter)
Definition: itkImageToNeighborhoodSampleAdaptor.h:172
itk::Statistics::ImageToNeighborhoodSampleAdaptor::ValueType
typename MeasurementVectorType::value_type ValueType
Definition: itkImageToNeighborhoodSampleAdaptor.h:100
itk::Statistics::ImageToNeighborhoodSampleAdaptor::MeasurementVectorSizeType
typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType
Definition: itkImageToNeighborhoodSampleAdaptor.h:105
itk::Statistics::ImageToNeighborhoodSampleAdaptor::Iterator::Iterator
Iterator(const Iterator &iter)
Definition: itkImageToNeighborhoodSampleAdaptor.h:259
itk::Statistics::ImageToNeighborhoodSampleAdaptor::m_InstanceIdentifierInternal
InstanceIdentifier m_InstanceIdentifierInternal
Definition: itkImageToNeighborhoodSampleAdaptor.h:331
itk::Statistics::ImageToNeighborhoodSampleAdaptor::NeighborhoodType
typename NeighborhoodIteratorType::NeighborhoodType NeighborhoodType
Definition: itkImageToNeighborhoodSampleAdaptor.h:92
itk::Statistics::ImageToNeighborhoodSampleAdaptor::SizeType
typename ImageType::SizeType SizeType
Definition: itkImageToNeighborhoodSampleAdaptor.h:86
itk::Statistics::ImageToNeighborhoodSampleAdaptor::Iterator::Iterator
Iterator(Self *adaptor)
Definition: itkImageToNeighborhoodSampleAdaptor.h:255
itk::Statistics::ImageToNeighborhoodSampleAdaptor::PixelContainerConstPointer
typename ImageType::PixelContainerConstPointer PixelContainerConstPointer
Definition: itkImageToNeighborhoodSampleAdaptor.h:83
itk::Statistics::ImageToNeighborhoodSampleAdaptor::InstanceIdentifier
typename Superclass::InstanceIdentifier InstanceIdentifier
Definition: itkImageToNeighborhoodSampleAdaptor.h:106
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::Statistics::ImageToNeighborhoodSampleAdaptor::ImagePointer
typename ImageType::Pointer ImagePointer
Definition: itkImageToNeighborhoodSampleAdaptor.h:77
itk::Statistics::ListSample
This class is the native implementation of the a Sample with an STL container.
Definition: itkListSample.h:51
itk::Statistics::ImageToNeighborhoodSampleAdaptor::ConstIterator::GetFrequency
AbsoluteFrequencyType GetFrequency() const
Definition: itkImageToNeighborhoodSampleAdaptor.h:187
itkImage.h
itk::SmartPointer< Self >
itk::Statistics::ImageToNeighborhoodSampleAdaptor::NeighborhoodRadiusType
typename NeighborhoodIteratorType::RadiusType NeighborhoodRadiusType
Definition: itkImageToNeighborhoodSampleAdaptor.h:93
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itkImageRegionIteratorWithIndex.h
itk::Statistics::ImageToNeighborhoodSampleAdaptor::m_MeasurementVectorInternal
MeasurementVectorType m_MeasurementVectorInternal
Definition: itkImageToNeighborhoodSampleAdaptor.h:330
itk::Statistics::ImageToNeighborhoodSampleAdaptor::NeighborhoodIndexType
typename NeighborhoodIteratorType::IndexType NeighborhoodIndexType
Definition: itkImageToNeighborhoodSampleAdaptor.h:94
itk::Statistics::ImageToNeighborhoodSampleAdaptor::m_Region
RegionType m_Region
Definition: itkImageToNeighborhoodSampleAdaptor.h:334
itk::Statistics::ListSample::InstanceIdentifier
typename Superclass::InstanceIdentifier InstanceIdentifier
Definition: itkListSample.h:74
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::Statistics::ImageToNeighborhoodSampleAdaptor
This class provides ListSample interface to ITK Image.
Definition: itkImageToNeighborhoodSampleAdaptor.h:55
itk::Statistics::ImageToNeighborhoodSampleAdaptor::OffsetTableType
typename RegionType::OffsetTableType OffsetTableType
Definition: itkImageToNeighborhoodSampleAdaptor.h:85
itk::Statistics::ImageToNeighborhoodSampleAdaptor::ConstIterator::ConstIterator
ConstIterator(const ImageToNeighborhoodSampleAdaptor *adaptor)
Definition: itkImageToNeighborhoodSampleAdaptor.h:170
itk::Statistics::ImageToNeighborhoodSampleAdaptor::TotalAbsoluteFrequencyType
typename Superclass::TotalAbsoluteFrequencyType TotalAbsoluteFrequencyType
Definition: itkImageToNeighborhoodSampleAdaptor.h:104
itkMacro.h
itk::Statistics::ImageToNeighborhoodSampleAdaptor::m_Radius
NeighborhoodRadiusType m_Radius
Definition: itkImageToNeighborhoodSampleAdaptor.h:333
itk::Statistics::ImageToNeighborhoodSampleAdaptor::MeasurementType
ValueType MeasurementType
Definition: itkImageToNeighborhoodSampleAdaptor.h:101
itk::Statistics::ImageToNeighborhoodSampleAdaptor::MeasurementVectorType
typename std::vector< ConstNeighborhoodIterator< TImage, TBoundaryCondition > > MeasurementVectorType
Definition: itkImageToNeighborhoodSampleAdaptor.h:99
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::Statistics::ImageToNeighborhoodSampleAdaptor::Iterator
Iterator.
Definition: itkImageToNeighborhoodSampleAdaptor.h:243
itk::Statistics::ImageToNeighborhoodSampleAdaptor::ConstIterator::m_InstanceIdentifier
InstanceIdentifier m_InstanceIdentifier
Definition: itkImageToNeighborhoodSampleAdaptor.h:235
itk::Statistics::ImageToNeighborhoodSampleAdaptor::End
Iterator End()
Definition: itkImageToNeighborhoodSampleAdaptor.h:290
itk::Statistics::ImageToNeighborhoodSampleAdaptor::ConstIterator::operator!=
bool operator!=(const ConstIterator &it) const
Definition: itkImageToNeighborhoodSampleAdaptor.h:213
itkListSample.h
itk::Statistics::ImageToNeighborhoodSampleAdaptor::ConstIterator::GetInstanceIdentifier
InstanceIdentifier GetInstanceIdentifier() const
Definition: itkImageToNeighborhoodSampleAdaptor.h:199
itk::ImageRegionIteratorWithIndex
A multi-dimensional iterator templated over image type that walks pixels within a region and is speci...
Definition: itkImageRegionIteratorWithIndex.h:73
itk::Statistics::ImageToNeighborhoodSampleAdaptor::m_Image
ImageConstPointer m_Image
Definition: itkImageToNeighborhoodSampleAdaptor.h:329
itk::Statistics::ImageToNeighborhoodSampleAdaptor::ConstIterator::m_MeasurementVectorCache
MeasurementVectorType m_MeasurementVectorCache
Definition: itkImageToNeighborhoodSampleAdaptor.h:234
itk::Statistics::ImageToNeighborhoodSampleAdaptor::ConstIterator::operator++
ConstIterator & operator++()
Definition: itkImageToNeighborhoodSampleAdaptor.h:205
itk::Statistics::ImageToNeighborhoodSampleAdaptor::IndexType
typename ImageType::IndexType IndexType
Definition: itkImageToNeighborhoodSampleAdaptor.h:79
itk::Statistics::ImageToNeighborhoodSampleAdaptor::ConstIterator::GetMeasurementVector
const MeasurementVectorType & GetMeasurementVector() const
Definition: itkImageToNeighborhoodSampleAdaptor.h:193
itk::NeighborhoodIterator
Defines iteration of a local N-dimensional neighborhood of pixels across an itk::Image.
Definition: itkNeighborhoodIterator.h:212
itk::Statistics::ImageToNeighborhoodSampleAdaptor::NeighborhoodSizeType
typename NeighborhoodIteratorType::SizeType NeighborhoodSizeType
Definition: itkImageToNeighborhoodSampleAdaptor.h:95
itk::Statistics::ImageToNeighborhoodSampleAdaptor::ConstIterator
Const Iterator.
Definition: itkImageToNeighborhoodSampleAdaptor.h:163
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ConstNeighborhoodIterator
Const version of NeighborhoodIterator, defining iteration of a local N-dimensional neighborhood of pi...
Definition: itkConstNeighborhoodIterator.h:51
itk::OffsetValueType
signed long OffsetValueType
Definition: itkIntTypes.h:94
itk::Statistics::ImageToNeighborhoodSampleAdaptor::OffsetValueType
typename ImageType::OffsetValueType OffsetValueType
Definition: itkImageToNeighborhoodSampleAdaptor.h:81
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itk::Statistics::ImageToNeighborhoodSampleAdaptor::Begin
Iterator Begin()
Definition: itkImageToNeighborhoodSampleAdaptor.h:279
itkSmartPointer.h
itk::Statistics::ImageToNeighborhoodSampleAdaptor::RegionType
typename ImageType::RegionType RegionType
Definition: itkImageToNeighborhoodSampleAdaptor.h:84
itk::Statistics::ImageToNeighborhoodSampleAdaptor::ConstIterator::ConstIterator
ConstIterator(NeighborhoodIteratorType iter, InstanceIdentifier iid)
Definition: itkImageToNeighborhoodSampleAdaptor.h:226
itk::ConstNeighborhoodIterator::GoToEnd
ITK_ITERATOR_VIRTUAL void GoToEnd() ITK_ITERATOR_FINAL
itk::Statistics::ImageToNeighborhoodSampleAdaptor::ImageConstPointer
typename ImageType::ConstPointer ImageConstPointer
Definition: itkImageToNeighborhoodSampleAdaptor.h:78
itk::Statistics::ImageToNeighborhoodSampleAdaptor::Begin
ConstIterator Begin() const
Definition: itkImageToNeighborhoodSampleAdaptor.h:302
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:293
itk::Statistics::ImageToNeighborhoodSampleAdaptor::m_NeighborIndexInternal
IndexType m_NeighborIndexInternal
Definition: itkImageToNeighborhoodSampleAdaptor.h:332
itk::Statistics::ImageToNeighborhoodSampleAdaptor::m_OffsetTable
OffsetTableType m_OffsetTable
Definition: itkImageToNeighborhoodSampleAdaptor.h:336
itk::ConstNeighborhoodIterator::GoToBegin
ITK_ITERATOR_VIRTUAL void GoToBegin() ITK_ITERATOR_FINAL
itk::Statistics::ImageToNeighborhoodSampleAdaptor::Iterator::Iterator
Iterator(NeighborhoodIteratorType iter, InstanceIdentifier iid)
Definition: itkImageToNeighborhoodSampleAdaptor.h:272