ITK  4.13.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:
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 
75  typedef typename Superclass::MeasurementType MeasurementType;
76  typedef typename Superclass::MeasurementVectorType MeasurementVectorType;
77  typedef typename Superclass::AbsoluteFrequencyType AbsoluteFrequencyType;
78  typedef typename Superclass::TotalAbsoluteFrequencyType TotalAbsoluteFrequencyType;
79  typedef typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType;
80  typedef typename Superclass::InstanceIdentifier InstanceIdentifier;
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 
98  AbsoluteFrequencyType GetFrequency(InstanceIdentifier id) const ITK_OVERRIDE;
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 private:
173  ConstIterator() ITK_DELETED_FUNCTION;
175  InstanceIdentifier m_InstanceIdentifier;
176  };
177 
181  class Iterator:public ConstIterator
182  {
184 
185 public:
186 
187  Iterator(Self *adaptor):ConstIterator(adaptor)
188  {}
189 
190  Iterator(const Iterator & iter):ConstIterator(iter)
191  {}
192 
193  Iterator & operator=(const Iterator & iter)
194  {
195  this->ConstIterator::operator=(iter);
196  return *this;
197  }
198 
199 protected:
202  InstanceIdentifier iid):ConstIterator(iter, iid)
203  {}
204 
205 private:
206  // To ensure const-correctness these method must not be in the public API.
207  // The are not implemented, since they should never be called.
208  Iterator() ITK_DELETED_FUNCTION;
209  Iterator(const Self *adaptor) ITK_DELETED_FUNCTION;
210  Iterator(PointsContainerConstIteratorType iter, InstanceIdentifier iid) ITK_DELETED_FUNCTION;
211  Iterator(const ConstIterator & it) ITK_DELETED_FUNCTION;
212  ConstIterator & operator=(const ConstIterator & it) ITK_DELETED_FUNCTION;
213 
214  };
215 
217  Iterator Begin()
218  {
219  PointsContainerPointer nonConstPointsDataContainer =
220  const_cast< PointsContainer * >( m_PointsContainer.GetPointer() );
221  Iterator iter(nonConstPointsDataContainer->Begin(), 0);
223 
224  return iter;
225  }
226 
229  {
230  PointsContainerPointer nonConstPointsDataContainer =
231  const_cast< PointsContainer * >( m_PointsContainer.GetPointer() );
232 
233  Iterator iter( nonConstPointsDataContainer->End(), m_PointsContainer->Size() );
234 
235  return iter;
236  }
237 
239  ConstIterator Begin() const
240  {
241  ConstIterator iter(m_PointsContainer->Begin(), 0);
242 
243  return iter;
244  }
245 
247  ConstIterator End() const
248  {
249  ConstIterator iter( m_PointsContainer->End(), m_PointsContainer->Size() );
250 
251  return iter;
252  }
253 
254 protected:
256 
257  virtual ~PointSetToListSampleAdaptor() ITK_OVERRIDE {}
258  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
259 
260 private:
261  ITK_DISALLOW_COPY_AND_ASSIGN(PointSetToListSampleAdaptor);
262 
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
ListSample< typename TPointSet::PointType > Superclass
TPointSet::PointsContainerConstIterator PointsContainerConstIteratorType
Represent the size (bounds) of a n-dimensional image.
Definition: itkSize.h:52
Iterator(PointsContainerIteratorType iter, InstanceIdentifier iid)
Superclass::TotalAbsoluteFrequencyType TotalAbsoluteFrequencyType
TPointSet::PointsContainerConstPointer PointsContainerConstPointer
TPointSet::PointsContainerIterator PointsContainerIteratorType
ConstIterator(PointsContainerConstIteratorType iter, InstanceIdentifier iid)
This class provides ListSample interface to ITK PointSet.
Superclass::MeasurementVectorSizeType MeasurementVectorSizeType
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
Base class for all data objects in ITK.