ITK  5.0.0
Insight Segmentation and Registration 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:
47  public ListSample< typename TPointSet::PointType >
48 {
49 public:
50  ITK_DISALLOW_COPY_AND_ASSIGN(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 SetPointSet(const TPointSet *pointSet);
88 
90  const TPointSet * GetPointSet();
91 
93  InstanceIdentifier Size() const override;
94 
97  const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier id) const override;
98 
100  AbsoluteFrequencyType GetFrequency(InstanceIdentifier id) const override;
101 
103  TotalAbsoluteFrequencyType GetTotalFrequency() const override;
104 
109  {
111 
112 public:
113 
115  {
116  *this = adaptor->Begin();
117  }
118 
120  {
121  m_Iter = iter.m_Iter;
122  m_InstanceIdentifier = iter.m_InstanceIdentifier;
123  }
124 
126  {
127  m_Iter = iter.m_Iter;
128  m_InstanceIdentifier = iter.m_InstanceIdentifier;
129  return *this;
130  }
131 
133  {
134  return 1;
135  }
136 
138  {
139  return ( const MeasurementVectorType & )m_Iter.Value();
140  }
141 
143  {
144  return m_InstanceIdentifier;
145  }
146 
148  {
149  ++m_Iter;
150  ++m_InstanceIdentifier;
151  return *this;
152  }
153 
154  bool operator!=(const ConstIterator & it)
155  {
156  return ( m_Iter != it.m_Iter );
157  }
158 
159  bool operator==(const ConstIterator & it)
160  {
161  return ( m_Iter == it.m_Iter );
162  }
163 
164 protected:
165  // This method should only be available to the ListSample class
168  InstanceIdentifier iid)
169  {
170  m_Iter = iter;
171  m_InstanceIdentifier = iid;
172  }
173 
174 private:
175  ConstIterator() = delete;
178  };
179 
183  class Iterator:public ConstIterator
184  {
186 
187 public:
188 
189  Iterator(Self *adaptor):ConstIterator(adaptor)
190  {}
191 
192  Iterator(const Iterator & iter):ConstIterator(iter)
193  {}
194 
195  Iterator & operator=(const Iterator & iter)
196  {
197  this->ConstIterator::operator=(iter);
198  return *this;
199  }
200 
201 protected:
204  InstanceIdentifier iid):ConstIterator(iter, iid)
205  {}
206 
207 private:
208  // To ensure const-correctness these method must not be in the public API.
209  // The are not implemented, since they should never be called.
210  Iterator() = delete;
211  Iterator(const Self *adaptor) = delete;
213  Iterator(const ConstIterator & it) = delete;
214  ConstIterator & operator=(const ConstIterator & it) = delete;
215 
216  };
217 
220  {
221  PointsContainerPointer nonConstPointsDataContainer =
222  const_cast< PointsContainer * >( m_PointsContainer.GetPointer() );
223  Iterator iter(nonConstPointsDataContainer->Begin(), 0);
225 
226  return iter;
227  }
228 
231  {
232  PointsContainerPointer nonConstPointsDataContainer =
233  const_cast< PointsContainer * >( m_PointsContainer.GetPointer() );
234 
235  Iterator iter( nonConstPointsDataContainer->End(), m_PointsContainer->Size() );
236 
237  return iter;
238  }
239 
242  {
243  ConstIterator iter(m_PointsContainer->Begin(), 0);
244 
245  return iter;
246  }
247 
250  {
251  ConstIterator iter( m_PointsContainer->End(), m_PointsContainer->Size() );
252 
253  return iter;
254  }
255 
256 protected:
258 
259  ~PointSetToListSampleAdaptor() override = default;
260  void PrintSelf(std::ostream & os, Indent indent) const override;
261 
262 private:
265 
269 
272 }; // end of class PointSetToListSampleAdaptor
273 } // end of namespace Statistics
274 } // end of namespace itk
275 
276 #ifndef ITK_MANUAL_INSTANTIATION
277 #include "itkPointSetToListSampleAdaptor.hxx"
278 #endif
279 
280 #endif
typename TPointSet::PointsContainerIterator PointsContainerIteratorType
typename TPointSet::PointsContainerConstPointer PointsContainerConstPointer
Iterator(PointsContainerIteratorType iter, InstanceIdentifier iid)
typename Superclass::TotalAbsoluteFrequencyType TotalAbsoluteFrequencyType
typename Superclass::MeasurementType MeasurementType
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:68
ConstIterator(PointsContainerConstIteratorType iter, InstanceIdentifier iid)
typename Superclass::MeasurementVectorType MeasurementVectorType
This class provides ListSample interface to ITK PointSet.
typename Superclass::InstanceIdentifier InstanceIdentifier
This class is the native implementation of the a Sample with an STL container.
Definition: itkListSample.h:51
Control indentation during Print() invocation.
Definition: itkIndent.h:49
typename TPointSet::PointsContainerConstIterator PointsContainerConstIteratorType
typename TPointSet::PointsContainerPointer PointsContainerPointer
Base class for most ITK classes.
Definition: itkObject.h:60
typename Superclass::AbsoluteFrequencyType AbsoluteFrequencyType
Base class for all data objects in ITK.
typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType