ITK  5.3.0
Insight Toolkit
itkPointSetToListSampleAdaptor.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 itkPointSetToListSampleAdaptor_h
19 #define itkPointSetToListSampleAdaptor_h
20 
21 #include <typeinfo>
22 
23 #include "itkPointSet.h"
24 #include "itkListSample.h"
25 #include "itkSmartPointer.h"
26 
27 namespace itk
28 {
29 namespace Statistics
30 {
46 template <typename TPointSet>
47 class ITK_TEMPLATE_EXPORT PointSetToListSampleAdaptor : public ListSample<typename TPointSet::PointType>
48 {
49 public:
50  ITK_DISALLOW_COPY_AND_MOVE(PointSetToListSampleAdaptor);
51 
57 
60 
62  itkNewMacro(Self);
63 
65  using PointSetType = TPointSet;
66  using PointSetPointer = typename TPointSet::Pointer;
67  using PointSetConstPointer = typename TPointSet::ConstPointer;
68  using PointsContainer = typename TPointSet::PointsContainer;
69  using PointsContainerPointer = typename TPointSet::PointsContainerPointer;
70  using PointsContainerConstPointer = typename TPointSet::PointsContainerConstPointer;
71  using PointsContainerIteratorType = typename TPointSet::PointsContainerIterator;
72  using PointsContainerConstIteratorType = typename TPointSet::PointsContainerConstIterator;
73  using PointType = typename TPointSet::PointType;
74 
77  using MeasurementType = typename Superclass::MeasurementType;
78  using MeasurementVectorType = typename Superclass::MeasurementVectorType;
79  using AbsoluteFrequencyType = typename Superclass::AbsoluteFrequencyType;
80  using TotalAbsoluteFrequencyType = typename Superclass::TotalAbsoluteFrequencyType;
81  using MeasurementVectorSizeType = typename Superclass::MeasurementVectorSizeType;
82  using InstanceIdentifier = typename Superclass::InstanceIdentifier;
83 
85 
87  void
88  SetPointSet(const TPointSet * pointSet);
89 
91  const TPointSet *
92  GetPointSet();
93 
96  Size() const override;
97 
100  const MeasurementVectorType &
101  GetMeasurementVector(InstanceIdentifier identifier) const override;
102 
105  GetFrequency(InstanceIdentifier id) const override;
106 
109  GetTotalFrequency() const override;
110 
116  {
118 
119  public:
120  ConstIterator(const PointSetToListSampleAdaptor * adaptor) { *this = adaptor->Begin(); }
121 
123  {
124  m_Iter = iter.m_Iter;
125  m_InstanceIdentifier = iter.m_InstanceIdentifier;
126  }
127 
128  ConstIterator &
129  operator=(const ConstIterator & iter)
130  {
131  m_Iter = iter.m_Iter;
132  m_InstanceIdentifier = iter.m_InstanceIdentifier;
133  return *this;
134  }
135 
137  GetFrequency() const
138  {
139  return 1;
140  }
141 
142  const MeasurementVectorType &
144  {
145  return (const MeasurementVectorType &)m_Iter.Value();
146  }
147 
150  {
151  return m_InstanceIdentifier;
152  }
153 
154  ConstIterator &
156  {
157  ++m_Iter;
158  ++m_InstanceIdentifier;
159  return *this;
160  }
161 
162  bool
163  operator==(const ConstIterator & it) const
164  {
165  return (m_Iter == it.m_Iter);
166  }
167 
168  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(ConstIterator);
169 
170  protected:
171  // This method should only be available to the ListSample class
173  {
174  m_Iter = iter;
175  m_InstanceIdentifier = iid;
176  }
177 
178  private:
179  ConstIterator() = delete;
182  };
183 
188  class Iterator : public ConstIterator
189  {
191 
192  public:
193  Iterator(Self * adaptor)
194  : ConstIterator(adaptor)
195  {}
196 
197  Iterator(const Iterator & iter)
198  : ConstIterator(iter)
199  {}
200 
201  Iterator &
202  operator=(const Iterator & iter)
203  {
204  this->ConstIterator::operator=(iter);
205  return *this;
206  }
207 
208  Iterator() = delete;
209  Iterator(const Self * adaptor) = delete;
211  Iterator(const ConstIterator & it) = delete;
212  ConstIterator &
213  operator=(const ConstIterator & it) = delete;
214 
215  protected:
217  : ConstIterator(iter, iid)
218  {}
219  };
220 
222  Iterator
224  {
225  PointsContainerPointer nonConstPointsDataContainer = const_cast<PointsContainer *>(m_PointsContainer.GetPointer());
226  Iterator iter(nonConstPointsDataContainer->Begin(), 0);
228 
229  return iter;
230  }
231 
233  Iterator
234  End()
235  {
236  PointsContainerPointer nonConstPointsDataContainer = const_cast<PointsContainer *>(m_PointsContainer.GetPointer());
237 
238  Iterator iter(nonConstPointsDataContainer->End(), m_PointsContainer->Size());
239 
240  return iter;
241  }
242 
244  ConstIterator
245  Begin() const
246  {
247  ConstIterator iter(m_PointsContainer->Begin(), 0);
248 
249  return iter;
250  }
251 
253  ConstIterator
254  End() const
255  {
256  ConstIterator iter(m_PointsContainer->End(), m_PointsContainer->Size());
257 
258  return iter;
259  }
260 
261 protected:
263 
264  ~PointSetToListSampleAdaptor() override = default;
265  void
266  PrintSelf(std::ostream & os, Indent indent) const override;
267 
268 private:
271 
275 
278 }; // end of class PointSetToListSampleAdaptor
279 } // end of namespace Statistics
280 } // end of namespace itk
281 
282 #ifndef ITK_MANUAL_INSTANTIATION
283 # include "itkPointSetToListSampleAdaptor.hxx"
284 #endif
285 
286 #endif
itk::Statistics::PointSetToListSampleAdaptor::PointType
typename TPointSet::PointType PointType
Definition: itkPointSetToListSampleAdaptor.h:73
itk::Statistics::PointSetToListSampleAdaptor::Iterator::Iterator
Iterator(Self *adaptor)
Definition: itkPointSetToListSampleAdaptor.h:193
itk::Statistics::PointSetToListSampleAdaptor::ConstIterator
Definition: itkPointSetToListSampleAdaptor.h:115
itk::Statistics::PointSetToListSampleAdaptor
This class provides ListSample interface to ITK PointSet.
Definition: itkPointSetToListSampleAdaptor.h:47
itk::Statistics::PointSetToListSampleAdaptor::Begin
Iterator Begin()
Definition: itkPointSetToListSampleAdaptor.h:223
itk::Size
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:69
itk::Statistics::PointSetToListSampleAdaptor::End
Iterator End()
Definition: itkPointSetToListSampleAdaptor.h:234
itk::Statistics::PointSetToListSampleAdaptor::ConstIterator::GetFrequency
AbsoluteFrequencyType GetFrequency() const
Definition: itkPointSetToListSampleAdaptor.h:137
itk::Statistics::PointSetToListSampleAdaptor::PointSetConstPointer
typename TPointSet::ConstPointer PointSetConstPointer
Definition: itkPointSetToListSampleAdaptor.h:67
itk::Statistics::PointSetToListSampleAdaptor::ConstIterator::m_Iter
PointsContainerConstIteratorType m_Iter
Definition: itkPointSetToListSampleAdaptor.h:180
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::Statistics::PointSetToListSampleAdaptor::PointSetPointer
typename TPointSet::Pointer PointSetPointer
Definition: itkPointSetToListSampleAdaptor.h:66
itk::Statistics::ListSample
This class is the native implementation of the a Sample with an STL container.
Definition: itkListSample.h:51
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::Statistics::PointSetToListSampleAdaptor::ConstIterator::GetMeasurementVector
const MeasurementVectorType & GetMeasurementVector() const
Definition: itkPointSetToListSampleAdaptor.h:143
itk::Statistics::PointSetToListSampleAdaptor::PointSetType
TPointSet PointSetType
Definition: itkPointSetToListSampleAdaptor.h:65
itk::Statistics::PointSetToListSampleAdaptor::Iterator::Iterator
Iterator(const Iterator &iter)
Definition: itkPointSetToListSampleAdaptor.h:197
itk::Statistics::PointSetToListSampleAdaptor::TotalAbsoluteFrequencyType
typename Superclass::TotalAbsoluteFrequencyType TotalAbsoluteFrequencyType
Definition: itkPointSetToListSampleAdaptor.h:80
itk::Statistics::PointSetToListSampleAdaptor::m_PointSet
PointSetConstPointer m_PointSet
Definition: itkPointSetToListSampleAdaptor.h:270
itk::Statistics::PointSetToListSampleAdaptor::Iterator::Iterator
Iterator(PointsContainerIteratorType iter, InstanceIdentifier iid)
Definition: itkPointSetToListSampleAdaptor.h:216
itk::Statistics::PointSetToListSampleAdaptor::MeasurementVectorType
typename Superclass::MeasurementVectorType MeasurementVectorType
Definition: itkPointSetToListSampleAdaptor.h:78
itk::Statistics::PointSetToListSampleAdaptor::AbsoluteFrequencyType
typename Superclass::AbsoluteFrequencyType AbsoluteFrequencyType
Definition: itkPointSetToListSampleAdaptor.h:79
itk::Statistics::PointSetToListSampleAdaptor::m_PointsContainer
PointsContainerConstPointer m_PointsContainer
Definition: itkPointSetToListSampleAdaptor.h:274
itk::Statistics::PointSetToListSampleAdaptor::ConstIterator::m_InstanceIdentifier
InstanceIdentifier m_InstanceIdentifier
Definition: itkPointSetToListSampleAdaptor.h:181
itk::Statistics::PointSetToListSampleAdaptor::PointsContainerIteratorType
typename TPointSet::PointsContainerIterator PointsContainerIteratorType
Definition: itkPointSetToListSampleAdaptor.h:71
itk::Statistics::PointSetToListSampleAdaptor::ConstIterator::operator==
bool operator==(const ConstIterator &it) const
Definition: itkPointSetToListSampleAdaptor.h:163
itk::Statistics::PointSetToListSampleAdaptor::ConstIterator::ConstIterator
ConstIterator(const ConstIterator &iter)
Definition: itkPointSetToListSampleAdaptor.h:122
itkListSample.h
itk::Statistics::PointSetToListSampleAdaptor::ConstIterator::operator++
ConstIterator & operator++()
Definition: itkPointSetToListSampleAdaptor.h:155
itk::Statistics::PointSetToListSampleAdaptor::ConstIterator::GetInstanceIdentifier
InstanceIdentifier GetInstanceIdentifier() const
Definition: itkPointSetToListSampleAdaptor.h:149
itk::Statistics::PointSetToListSampleAdaptor::MeasurementType
typename Superclass::MeasurementType MeasurementType
Definition: itkPointSetToListSampleAdaptor.h:77
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::Statistics::PointSetToListSampleAdaptor::PointsContainerPointer
typename TPointSet::PointsContainerPointer PointsContainerPointer
Definition: itkPointSetToListSampleAdaptor.h:69
itk::Statistics::PointSetToListSampleAdaptor::PointsContainer
typename TPointSet::PointsContainer PointsContainer
Definition: itkPointSetToListSampleAdaptor.h:68
itk::Statistics::PointSetToListSampleAdaptor::PointsContainerConstIteratorType
typename TPointSet::PointsContainerConstIterator PointsContainerConstIteratorType
Definition: itkPointSetToListSampleAdaptor.h:72
itk::Statistics::PointSetToListSampleAdaptor::End
ConstIterator End() const
Definition: itkPointSetToListSampleAdaptor.h:254
itk::Statistics::PointSetToListSampleAdaptor::ValueType
MeasurementVectorType ValueType
Definition: itkPointSetToListSampleAdaptor.h:84
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itkSmartPointer.h
itk::Statistics::PointSetToListSampleAdaptor::ConstIterator::ConstIterator
ConstIterator(const PointSetToListSampleAdaptor *adaptor)
Definition: itkPointSetToListSampleAdaptor.h:120
itk::Statistics::PointSetToListSampleAdaptor::MeasurementVectorSizeType
typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType
Definition: itkPointSetToListSampleAdaptor.h:81
itk::Statistics::PointSetToListSampleAdaptor::Iterator
Definition: itkPointSetToListSampleAdaptor.h:188
itkPointSet.h
itk::Statistics::PointSetToListSampleAdaptor::Begin
ConstIterator Begin() const
Definition: itkPointSetToListSampleAdaptor.h:245
itk::Statistics::PointSetToListSampleAdaptor::Iterator::operator=
Iterator & operator=(const Iterator &iter)
Definition: itkPointSetToListSampleAdaptor.h:202
itk::Statistics::PointSetToListSampleAdaptor::ConstIterator::operator=
ConstIterator & operator=(const ConstIterator &iter)
Definition: itkPointSetToListSampleAdaptor.h:129
itk::Statistics::PointSetToListSampleAdaptor::InstanceIdentifier
typename Superclass::InstanceIdentifier InstanceIdentifier
Definition: itkPointSetToListSampleAdaptor.h:82
itk::Statistics::PointSetToListSampleAdaptor::ConstIterator::ConstIterator
ConstIterator(PointsContainerConstIteratorType iter, InstanceIdentifier iid)
Definition: itkPointSetToListSampleAdaptor.h:172
itk::Statistics::PointSetToListSampleAdaptor::m_TempPoint
PointType m_TempPoint
Definition: itkPointSetToListSampleAdaptor.h:277
itk::Statistics::PointSetToListSampleAdaptor::PointsContainerConstPointer
typename TPointSet::PointsContainerConstPointer PointsContainerConstPointer
Definition: itkPointSetToListSampleAdaptor.h:70
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:293