ITK  5.1.0
Insight Toolkit
itkPointSetToListSampleAdaptor.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 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 {
45 template <typename TPointSet>
46 class ITK_TEMPLATE_EXPORT PointSetToListSampleAdaptor : public ListSample<typename TPointSet::PointType>
47 {
48 public:
49  ITK_DISALLOW_COPY_AND_ASSIGN(PointSetToListSampleAdaptor);
50 
56 
59 
61  itkNewMacro(Self);
62 
64  using PointSetType = TPointSet;
65  using PointSetPointer = typename TPointSet::Pointer;
66  using PointSetConstPointer = typename TPointSet::ConstPointer;
67  using PointsContainer = typename TPointSet::PointsContainer;
68  using PointsContainerPointer = typename TPointSet::PointsContainerPointer;
69  using PointsContainerConstPointer = typename TPointSet::PointsContainerConstPointer;
70  using PointsContainerIteratorType = typename TPointSet::PointsContainerIterator;
71  using PointsContainerConstIteratorType = typename TPointSet::PointsContainerConstIterator;
72  using PointType = typename TPointSet::PointType;
73 
76  using MeasurementType = typename Superclass::MeasurementType;
77  using MeasurementVectorType = typename Superclass::MeasurementVectorType;
78  using AbsoluteFrequencyType = typename Superclass::AbsoluteFrequencyType;
79  using TotalAbsoluteFrequencyType = typename Superclass::TotalAbsoluteFrequencyType;
80  using MeasurementVectorSizeType = typename Superclass::MeasurementVectorSizeType;
81  using InstanceIdentifier = typename Superclass::InstanceIdentifier;
82 
84 
86  void
87  SetPointSet(const TPointSet * pointSet);
88 
90  const TPointSet *
91  GetPointSet();
92 
95  Size() const override;
96 
99  const MeasurementVectorType &
100  GetMeasurementVector(InstanceIdentifier id) const override;
101 
104  GetFrequency(InstanceIdentifier id) const override;
105 
108  GetTotalFrequency() const override;
109 
114  {
116 
117  public:
118  ConstIterator(const PointSetToListSampleAdaptor * adaptor) { *this = adaptor->Begin(); }
119 
121  {
122  m_Iter = iter.m_Iter;
123  m_InstanceIdentifier = iter.m_InstanceIdentifier;
124  }
125 
126  ConstIterator &
127  operator=(const ConstIterator & iter)
128  {
129  m_Iter = iter.m_Iter;
130  m_InstanceIdentifier = iter.m_InstanceIdentifier;
131  return *this;
132  }
133 
135  GetFrequency() const
136  {
137  return 1;
138  }
139 
140  const MeasurementVectorType &
142  {
143  return (const MeasurementVectorType &)m_Iter.Value();
144  }
145 
148  {
149  return m_InstanceIdentifier;
150  }
151 
152  ConstIterator &
154  {
155  ++m_Iter;
156  ++m_InstanceIdentifier;
157  return *this;
158  }
159 
160  bool
162  {
163  return (m_Iter != it.m_Iter);
164  }
165 
166  bool
168  {
169  return (m_Iter == it.m_Iter);
170  }
171 
172  protected:
173  // This method should only be available to the ListSample class
175  {
176  m_Iter = iter;
177  m_InstanceIdentifier = iid;
178  }
179 
180  private:
181  ConstIterator() = delete;
184  };
185 
189  class Iterator : public ConstIterator
190  {
192 
193  public:
194  Iterator(Self * adaptor)
195  : ConstIterator(adaptor)
196  {}
197 
198  Iterator(const Iterator & iter)
199  : ConstIterator(iter)
200  {}
201 
202  Iterator &
203  operator=(const Iterator & iter)
204  {
205  this->ConstIterator::operator=(iter);
206  return *this;
207  }
208 
209  protected:
211  : ConstIterator(iter, iid)
212  {}
213 
214  private:
215  // To ensure const-correctness these method must not be in the public API.
216  // The are not implemented, since they should never be called.
217  Iterator() = delete;
218  Iterator(const Self * adaptor) = delete;
220  Iterator(const ConstIterator & it) = delete;
221  ConstIterator &
222  operator=(const ConstIterator & it) = delete;
223  };
224 
226  Iterator
228  {
229  PointsContainerPointer nonConstPointsDataContainer = const_cast<PointsContainer *>(m_PointsContainer.GetPointer());
230  Iterator iter(nonConstPointsDataContainer->Begin(), 0);
232 
233  return iter;
234  }
235 
237  Iterator
238  End()
239  {
240  PointsContainerPointer nonConstPointsDataContainer = const_cast<PointsContainer *>(m_PointsContainer.GetPointer());
241 
242  Iterator iter(nonConstPointsDataContainer->End(), m_PointsContainer->Size());
243 
244  return iter;
245  }
246 
248  ConstIterator
249  Begin() const
250  {
251  ConstIterator iter(m_PointsContainer->Begin(), 0);
252 
253  return iter;
254  }
255 
257  ConstIterator
258  End() const
259  {
260  ConstIterator iter(m_PointsContainer->End(), m_PointsContainer->Size());
261 
262  return iter;
263  }
264 
265 protected:
267 
268  ~PointSetToListSampleAdaptor() override = default;
269  void
270  PrintSelf(std::ostream & os, Indent indent) const override;
271 
272 private:
275 
279 
282 }; // end of class PointSetToListSampleAdaptor
283 } // end of namespace Statistics
284 } // end of namespace itk
285 
286 #ifndef ITK_MANUAL_INSTANTIATION
287 # include "itkPointSetToListSampleAdaptor.hxx"
288 #endif
289 
290 #endif
itk::Statistics::PointSetToListSampleAdaptor::PointType
typename TPointSet::PointType PointType
Definition: itkPointSetToListSampleAdaptor.h:72
itk::Statistics::PointSetToListSampleAdaptor::Iterator::Iterator
Iterator(Self *adaptor)
Definition: itkPointSetToListSampleAdaptor.h:194
itk::Statistics::PointSetToListSampleAdaptor::ConstIterator
Definition: itkPointSetToListSampleAdaptor.h:113
itk::Statistics::PointSetToListSampleAdaptor
This class provides ListSample interface to ITK PointSet.
Definition: itkPointSetToListSampleAdaptor.h:46
itk::Statistics::PointSetToListSampleAdaptor::Begin
Iterator Begin()
Definition: itkPointSetToListSampleAdaptor.h:227
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:238
itk::Statistics::PointSetToListSampleAdaptor::ConstIterator::GetFrequency
AbsoluteFrequencyType GetFrequency() const
Definition: itkPointSetToListSampleAdaptor.h:135
itk::Statistics::PointSetToListSampleAdaptor::PointSetConstPointer
typename TPointSet::ConstPointer PointSetConstPointer
Definition: itkPointSetToListSampleAdaptor.h:66
itk::Statistics::PointSetToListSampleAdaptor::ConstIterator::m_Iter
PointsContainerConstIteratorType m_Iter
Definition: itkPointSetToListSampleAdaptor.h:182
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::Statistics::PointSetToListSampleAdaptor::PointSetPointer
typename TPointSet::Pointer PointSetPointer
Definition: itkPointSetToListSampleAdaptor.h:65
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:141
itk::Statistics::PointSetToListSampleAdaptor::PointSetType
TPointSet PointSetType
Definition: itkPointSetToListSampleAdaptor.h:64
itk::Statistics::PointSetToListSampleAdaptor::Iterator::Iterator
Iterator(const Iterator &iter)
Definition: itkPointSetToListSampleAdaptor.h:198
itk::Statistics::PointSetToListSampleAdaptor::TotalAbsoluteFrequencyType
typename Superclass::TotalAbsoluteFrequencyType TotalAbsoluteFrequencyType
Definition: itkPointSetToListSampleAdaptor.h:79
itk::Statistics::PointSetToListSampleAdaptor::m_PointSet
PointSetConstPointer m_PointSet
Definition: itkPointSetToListSampleAdaptor.h:274
itk::Statistics::PointSetToListSampleAdaptor::Iterator::Iterator
Iterator(PointsContainerIteratorType iter, InstanceIdentifier iid)
Definition: itkPointSetToListSampleAdaptor.h:210
itk::Statistics::PointSetToListSampleAdaptor::MeasurementVectorType
typename Superclass::MeasurementVectorType MeasurementVectorType
Definition: itkPointSetToListSampleAdaptor.h:77
itk::Statistics::PointSetToListSampleAdaptor::AbsoluteFrequencyType
typename Superclass::AbsoluteFrequencyType AbsoluteFrequencyType
Definition: itkPointSetToListSampleAdaptor.h:78
itk::Statistics::PointSetToListSampleAdaptor::ConstIterator::operator!=
bool operator!=(const ConstIterator &it)
Definition: itkPointSetToListSampleAdaptor.h:161
itk::Statistics::PointSetToListSampleAdaptor::m_PointsContainer
PointsContainerConstPointer m_PointsContainer
Definition: itkPointSetToListSampleAdaptor.h:278
itk::Statistics::PointSetToListSampleAdaptor::ConstIterator::m_InstanceIdentifier
InstanceIdentifier m_InstanceIdentifier
Definition: itkPointSetToListSampleAdaptor.h:183
itk::Statistics::PointSetToListSampleAdaptor::PointsContainerIteratorType
typename TPointSet::PointsContainerIterator PointsContainerIteratorType
Definition: itkPointSetToListSampleAdaptor.h:70
itk::Statistics::PointSetToListSampleAdaptor::ConstIterator::ConstIterator
ConstIterator(const ConstIterator &iter)
Definition: itkPointSetToListSampleAdaptor.h:120
itkListSample.h
itk::Statistics::PointSetToListSampleAdaptor::ConstIterator::operator++
ConstIterator & operator++()
Definition: itkPointSetToListSampleAdaptor.h:153
itk::Statistics::PointSetToListSampleAdaptor::ConstIterator::GetInstanceIdentifier
InstanceIdentifier GetInstanceIdentifier() const
Definition: itkPointSetToListSampleAdaptor.h:147
itk::Statistics::PointSetToListSampleAdaptor::MeasurementType
typename Superclass::MeasurementType MeasurementType
Definition: itkPointSetToListSampleAdaptor.h:76
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkArray.h:26
itk::Statistics::PointSetToListSampleAdaptor::ConstIterator::operator==
bool operator==(const ConstIterator &it)
Definition: itkPointSetToListSampleAdaptor.h:167
itk::Statistics::PointSetToListSampleAdaptor::PointsContainerPointer
typename TPointSet::PointsContainerPointer PointsContainerPointer
Definition: itkPointSetToListSampleAdaptor.h:68
itk::Statistics::PointSetToListSampleAdaptor::PointsContainer
typename TPointSet::PointsContainer PointsContainer
Definition: itkPointSetToListSampleAdaptor.h:67
itk::Statistics::PointSetToListSampleAdaptor::PointsContainerConstIteratorType
typename TPointSet::PointsContainerConstIterator PointsContainerConstIteratorType
Definition: itkPointSetToListSampleAdaptor.h:71
itk::Statistics::PointSetToListSampleAdaptor::End
ConstIterator End() const
Definition: itkPointSetToListSampleAdaptor.h:258
itk::Statistics::PointSetToListSampleAdaptor::ValueType
MeasurementVectorType ValueType
Definition: itkPointSetToListSampleAdaptor.h:83
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:60
itkSmartPointer.h
itk::Statistics::PointSetToListSampleAdaptor::ConstIterator::ConstIterator
ConstIterator(const PointSetToListSampleAdaptor *adaptor)
Definition: itkPointSetToListSampleAdaptor.h:118
itk::Statistics::PointSetToListSampleAdaptor::MeasurementVectorSizeType
typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType
Definition: itkPointSetToListSampleAdaptor.h:80
itk::Statistics::PointSetToListSampleAdaptor::Iterator
Definition: itkPointSetToListSampleAdaptor.h:189
itkPointSet.h
itk::Statistics::PointSetToListSampleAdaptor::Begin
ConstIterator Begin() const
Definition: itkPointSetToListSampleAdaptor.h:249
itk::Statistics::PointSetToListSampleAdaptor::Iterator::operator=
Iterator & operator=(const Iterator &iter)
Definition: itkPointSetToListSampleAdaptor.h:203
itk::Statistics::PointSetToListSampleAdaptor::ConstIterator::operator=
ConstIterator & operator=(const ConstIterator &iter)
Definition: itkPointSetToListSampleAdaptor.h:127
itk::Statistics::PointSetToListSampleAdaptor::InstanceIdentifier
typename Superclass::InstanceIdentifier InstanceIdentifier
Definition: itkPointSetToListSampleAdaptor.h:81
itk::Statistics::PointSetToListSampleAdaptor::ConstIterator::ConstIterator
ConstIterator(PointsContainerConstIteratorType iter, InstanceIdentifier iid)
Definition: itkPointSetToListSampleAdaptor.h:174
itk::Statistics::PointSetToListSampleAdaptor::m_TempPoint
PointType m_TempPoint
Definition: itkPointSetToListSampleAdaptor.h:281
itk::Statistics::PointSetToListSampleAdaptor::PointsContainerConstPointer
typename TPointSet::PointsContainerConstPointer PointsContainerConstPointer
Definition: itkPointSetToListSampleAdaptor.h:69
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:288