ITK  4.4.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< class TPointSet >
46 class ITK_EXPORT PointSetToListSampleAdaptor:
47  public ListSample< typename TPointSet::PointType >
48 {
49 public:
55 
58 
60  itkNewMacro(Self);
61 
63  itkStaticConstMacro(MeasurementVectorSize, unsigned int,
64  TPointSet::PointDimension);
65 
67  typedef TPointSet PointSetType;
68  typedef typename TPointSet::Pointer PointSetPointer;
69  typedef typename TPointSet::ConstPointer PointSetConstPointer;
70  typedef typename TPointSet::PointsContainer PointsContainer;
71  typedef typename TPointSet::PointsContainerPointer PointsContainerPointer;
72  typedef typename TPointSet::PointsContainerConstPointer PointsContainerConstPointer;
73  typedef typename TPointSet::PointsContainerIterator PointsContainerIteratorType;
74  typedef typename TPointSet::PointsContainerConstIterator PointsContainerConstIteratorType;
75  typedef typename TPointSet::PointType PointType;
76 
79  typedef typename Superclass::MeasurementType MeasurementType;
80  typedef typename Superclass::MeasurementVectorType MeasurementVectorType;
81  typedef typename Superclass::AbsoluteFrequencyType AbsoluteFrequencyType;
82  typedef typename Superclass::TotalAbsoluteFrequencyType TotalAbsoluteFrequencyType;
83  typedef typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType;
84  typedef typename Superclass::InstanceIdentifier InstanceIdentifier;
85 
87 
89  void SetPointSet(const TPointSet *pointSet);
90 
92  const TPointSet * GetPointSet();
93 
95  InstanceIdentifier Size() const;
96 
99  const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier id) const;
100 
102  AbsoluteFrequencyType GetFrequency(InstanceIdentifier id) const;
103 
105  TotalAbsoluteFrequencyType GetTotalFrequency() const;
106 
111  {
113 
114 public:
115 
117  {
118  *this = adaptor->Begin();
119  }
120 
122  {
123  m_Iter = iter.m_Iter;
124  m_InstanceIdentifier = iter.m_InstanceIdentifier;
125  }
126 
127  ConstIterator & operator=(const ConstIterator & iter)
128  {
129  m_Iter = iter.m_Iter;
130  m_InstanceIdentifier = iter.m_InstanceIdentifier;
131  return *this;
132  }
133 
134  AbsoluteFrequencyType GetFrequency() const
135  {
136  return 1;
137  }
138 
139  const MeasurementVectorType & GetMeasurementVector() const
140  {
141  return ( const MeasurementVectorType & )m_Iter.Value();
142  }
143 
144  InstanceIdentifier GetInstanceIdentifier() const
145  {
146  return m_InstanceIdentifier;
147  }
148 
149  ConstIterator & operator++()
150  {
151  ++m_Iter;
152  ++m_InstanceIdentifier;
153  return *this;
154  }
155 
156  bool operator!=(const ConstIterator & it)
157  {
158  return ( m_Iter != it.m_Iter );
159  }
160 
161  bool operator==(const ConstIterator & it)
162  {
163  return ( m_Iter == it.m_Iter );
164  }
165 
166 protected:
167  // This method should only be available to the ListSample class
170  InstanceIdentifier iid)
171  {
172  m_Iter = iter;
173  m_InstanceIdentifier = iid;
174  }
175 
176  // This method is purposely not implemented
177  ConstIterator();
178 
179 private:
182  };
183 
187  class Iterator:public ConstIterator
188  {
190 
191 public:
192 
193  Iterator(Self *adaptor):ConstIterator(adaptor)
194  {}
195 
196  Iterator(const Iterator & iter):ConstIterator(iter)
197  {}
198 
199  Iterator & operator=(const Iterator & iter)
200  {
201  this->ConstIterator::operator=(iter);
202  return *this;
203  }
204 
205 protected:
206  // To ensure const-correctness these method must not be in the public API.
207  // The are purposly not implemented, since they should never be called.
208  Iterator();
209  Iterator(const Self *adaptor);
211  Iterator(const ConstIterator & it);
212  ConstIterator & operator=(const ConstIterator & it);
213 
216  InstanceIdentifier iid):ConstIterator(iter, iid)
217  {}
218 
219 private:
220  };
221 
223  Iterator Begin()
224  {
225  PointsContainerPointer nonConstPointsDataContainer =
226  const_cast< PointsContainer * >( m_PointsContainer.GetPointer() );
227  Iterator iter(nonConstPointsDataContainer->Begin(), 0);
229 
230  return iter;
231  }
232 
234  Iterator End()
235  {
236  PointsContainerPointer nonConstPointsDataContainer =
237  const_cast< PointsContainer * >( m_PointsContainer.GetPointer() );
238 
239  Iterator iter( nonConstPointsDataContainer->End(), m_PointsContainer->Size() );
240 
241  return iter;
242  }
243 
245  ConstIterator Begin() const
246  {
247  ConstIterator iter(m_PointsContainer->Begin(), 0);
248 
249  return iter;
250  }
251 
253  ConstIterator End() const
254  {
255  ConstIterator iter( m_PointsContainer->End(), m_PointsContainer->Size() );
256 
257  return iter;
258  }
259 
260 protected:
262 
264  void PrintSelf(std::ostream & os, Indent indent) const;
265 
266 private:
267  PointSetToListSampleAdaptor(const Self &); //purposely not implemented
268  void operator=(const Self &); //purposely not implemented
269 
272 
276 
279 }; // end of class PointSetToListSampleAdaptor
280 } // end of namespace Statistics
281 } // end of namespace itk
282 
283 #ifndef ITK_MANUAL_INSTANTIATION
284 #include "itkPointSetToListSampleAdaptor.hxx"
285 #endif
286 
287 #endif
288