ITK  4.8.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  // This method is purposely not implemented
173  ConstIterator();
174 
175 private:
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:
202  // To ensure const-correctness these method must not be in the public API.
203  // The are purposly not implemented, since they should never be called.
204  Iterator();
205  Iterator(const Self *adaptor);
207  Iterator(const ConstIterator & it);
208  ConstIterator & operator=(const ConstIterator & it);
209 
212  InstanceIdentifier iid):ConstIterator(iter, iid)
213  {}
214 
215 private:
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 
260  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
261 
262 private:
263  PointSetToListSampleAdaptor(const Self &); //purposely not implemented
264  void operator=(const Self &); //purposely not implemented
265 
268 
272 
275 }; // end of class PointSetToListSampleAdaptor
276 } // end of namespace Statistics
277 } // end of namespace itk
278 
279 #ifndef ITK_MANUAL_INSTANTIATION
280 #include "itkPointSetToListSampleAdaptor.hxx"
281 #endif
282 
283 #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
Iterator(PointsContainerIteratorType iter, InstanceIdentifier iid)
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.