ITK  4.9.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 >
47  public ListSample< typename TPointSet::PointType >
48 {
49 public:
55 
58 
60  itkNewMacro(Self);
61 
63  typedef TPointSet PointSetType;
64  typedef typename TPointSet::Pointer PointSetPointer;
65  typedef typename TPointSet::ConstPointer PointSetConstPointer;
66  typedef typename TPointSet::PointsContainer PointsContainer;
67  typedef typename TPointSet::PointsContainerPointer PointsContainerPointer;
68  typedef typename TPointSet::PointsContainerConstPointer PointsContainerConstPointer;
69  typedef typename TPointSet::PointsContainerIterator PointsContainerIteratorType;
70  typedef typename TPointSet::PointsContainerConstIterator PointsContainerConstIteratorType;
71  typedef typename TPointSet::PointType PointType;
72 
81 
83 
85  void SetPointSet(const TPointSet *pointSet);
86 
88  const TPointSet * GetPointSet();
89 
91  InstanceIdentifier Size() const ITK_OVERRIDE;
92 
95  const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier id) const ITK_OVERRIDE;
96 
99 
101  TotalAbsoluteFrequencyType GetTotalFrequency() const ITK_OVERRIDE;
102 
107  {
109 
110 public:
111 
113  {
114  *this = adaptor->Begin();
115  }
116 
117  ConstIterator(const ConstIterator & iter)
118  {
119  m_Iter = iter.m_Iter;
120  m_InstanceIdentifier = iter.m_InstanceIdentifier;
121  }
122 
123  ConstIterator & operator=(const ConstIterator & iter)
124  {
125  m_Iter = iter.m_Iter;
126  m_InstanceIdentifier = iter.m_InstanceIdentifier;
127  return *this;
128  }
129 
131  {
132  return 1;
133  }
134 
136  {
137  return ( const MeasurementVectorType & )m_Iter.Value();
138  }
139 
141  {
142  return m_InstanceIdentifier;
143  }
144 
145  ConstIterator & operator++()
146  {
147  ++m_Iter;
148  ++m_InstanceIdentifier;
149  return *this;
150  }
151 
152  bool operator!=(const ConstIterator & it)
153  {
154  return ( m_Iter != it.m_Iter );
155  }
156 
157  bool operator==(const ConstIterator & it)
158  {
159  return ( m_Iter == it.m_Iter );
160  }
161 
162 protected:
163  // This method should only be available to the ListSample class
166  InstanceIdentifier iid)
167  {
168  m_Iter = iter;
169  m_InstanceIdentifier = iid;
170  }
171 
172  ConstIterator() ITK_DELETE_FUNCTION;
173 
174 private:
176  InstanceIdentifier m_InstanceIdentifier;
177  };
178 
182  class Iterator:public ConstIterator
183  {
185 
186 public:
187 
188  Iterator(Self *adaptor):ConstIterator(adaptor)
189  {}
190 
191  Iterator(const Iterator & iter):ConstIterator(iter)
192  {}
193 
194  Iterator & operator=(const Iterator & iter)
195  {
196  this->ConstIterator::operator=(iter);
197  return *this;
198  }
199 
200 protected:
201  // To ensure const-correctness these method must not be in the public API.
202  // The are not implemented, since they should never be called.
203  Iterator() ITK_DELETE_FUNCTION;
204  Iterator(const Self *adaptor) ITK_DELETE_FUNCTION;
205  Iterator(PointsContainerConstIteratorType iter, InstanceIdentifier iid) ITK_DELETE_FUNCTION;
206  Iterator(const ConstIterator & it) ITK_DELETE_FUNCTION;
207  ConstIterator & operator=(const ConstIterator & it) ITK_DELETE_FUNCTION;
208 
211  InstanceIdentifier iid):ConstIterator(iter, iid)
212  {}
213 
214 private:
215  };
216 
219  {
220  PointsContainerPointer nonConstPointsDataContainer =
221  const_cast< PointsContainer * >( m_PointsContainer.GetPointer() );
222  Iterator iter(nonConstPointsDataContainer->Begin(), 0);
224 
225  return iter;
226  }
227 
230  {
231  PointsContainerPointer nonConstPointsDataContainer =
232  const_cast< PointsContainer * >( m_PointsContainer.GetPointer() );
233 
234  Iterator iter( nonConstPointsDataContainer->End(), m_PointsContainer->Size() );
235 
236  return iter;
237  }
238 
240  ConstIterator Begin() const
241  {
242  ConstIterator iter(m_PointsContainer->Begin(), 0);
243 
244  return iter;
245  }
246 
248  ConstIterator End() const
249  {
250  ConstIterator iter( m_PointsContainer->End(), m_PointsContainer->Size() );
251 
252  return iter;
253  }
254 
255 protected:
257 
259  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
260 
261 private:
262  PointSetToListSampleAdaptor(const Self &) ITK_DELETE_FUNCTION;
263  void operator=(const Self &) ITK_DELETE_FUNCTION;
264 
267 
271 
274 }; // end of class PointSetToListSampleAdaptor
275 } // end of namespace Statistics
276 } // end of namespace itk
277 
278 #ifndef ITK_MANUAL_INSTANTIATION
279 #include "itkPointSetToListSampleAdaptor.hxx"
280 #endif
281 
282 #endif
ListSample< typename TPointSet::PointType > Superclass
TPointSet::PointsContainerConstIterator PointsContainerConstIteratorType
Superclass::MeasurementType MeasurementType
Definition: itkListSample.h:69
AbsoluteFrequencyType GetFrequency(InstanceIdentifier id) const override
Superclass::MeasurementVectorType MeasurementVectorType
Definition: itkListSample.h:64
Superclass::TotalAbsoluteFrequencyType TotalAbsoluteFrequencyType
Definition: itkListSample.h:71
Superclass::TotalAbsoluteFrequencyType TotalAbsoluteFrequencyType
Superclass::AbsoluteFrequencyType AbsoluteFrequencyType
Definition: itkListSample.h:70
void PrintSelf(std::ostream &os, Indent indent) const override
TPointSet::PointsContainerConstPointer PointsContainerConstPointer
Superclass::InstanceIdentifier InstanceIdentifier
Definition: itkListSample.h:72
TPointSet::PointsContainerIterator PointsContainerIteratorType
const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier id) const override
ConstIterator(PointsContainerConstIteratorType iter, InstanceIdentifier iid)
void SetPointSet(const TPointSet *pointSet)
This class provides ListSample interface to ITK PointSet.
Superclass::MeasurementVectorSizeType MeasurementVectorSizeType
Definition: itkListSample.h:68
Superclass::MeasurementVectorSizeType MeasurementVectorSizeType
This class is the native implementation of the a Sample with an STL container.
Definition: itkListSample.h:51
InstanceIdentifier Size() const override
Control indentation during Print() invocation.
Definition: itkIndent.h:49
TotalAbsoluteFrequencyType GetTotalFrequency() const override
Base class for all data objects in ITK.