ITK  4.2.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 public:
114 
116  {
117  *this = adaptor->Begin();
118  }
119 
121  {
122  m_Iter = iter.m_Iter;
123  m_InstanceIdentifier = iter.m_InstanceIdentifier;
124  }
125 
126  ConstIterator & operator=(const ConstIterator & iter)
127  {
128  m_Iter = iter.m_Iter;
129  m_InstanceIdentifier = iter.m_InstanceIdentifier;
130  return *this;
131  }
132 
133  AbsoluteFrequencyType GetFrequency() const
134  {
135  return 1;
136  }
137 
138  const MeasurementVectorType & GetMeasurementVector() const
139  {
140  return ( const MeasurementVectorType & )m_Iter.Value();
141  }
142 
143  InstanceIdentifier GetInstanceIdentifier() const
144  {
145  return m_InstanceIdentifier;
146  }
147 
148  ConstIterator & operator++()
149  {
150  ++m_Iter;
151  ++m_InstanceIdentifier;
152  return *this;
153  }
154 
155  bool operator!=(const ConstIterator & it)
156  {
157  return ( m_Iter != it.m_Iter );
158  }
159 
160  bool operator==(const ConstIterator & it)
161  {
162  return ( m_Iter == it.m_Iter );
163  }
164 
165 protected:
166  // This method should only be available to the ListSample class
169  InstanceIdentifier iid)
170  {
171  m_Iter = iter;
172  m_InstanceIdentifier = iid;
173  }
174 
175  // This method is purposely not implemented
176  ConstIterator();
177 private:
180  };
181 
185  class Iterator:public ConstIterator
186  {
188 public:
189 
190  Iterator(Self *adaptor):ConstIterator(adaptor)
191  {}
192 
193  Iterator(const Iterator & iter):ConstIterator(iter)
194  {}
195 
196  Iterator & operator=(const Iterator & iter)
197  {
198  this->ConstIterator::operator=(iter);
199  return *this;
200  }
201 
202 protected:
203  // To ensure const-correctness these method must not be in the public API.
204  // The are purposly not implemented, since they should never be called.
205  Iterator();
206  Iterator(const Self *adaptor);
208  Iterator(const ConstIterator & it);
209  ConstIterator & operator=(const ConstIterator & it);
210 
213  InstanceIdentifier iid):ConstIterator(iter, iid)
214  {}
215 
216 private:
217  };
218 
220  Iterator Begin()
221  {
222  PointsContainerPointer nonConstPointsDataContainer =
223  const_cast< PointsContainer * >( m_PointsContainer.GetPointer() );
224  Iterator iter(nonConstPointsDataContainer->Begin(), 0);
226 
227  return iter;
228  }
229 
231  Iterator End()
232  {
233  PointsContainerPointer nonConstPointsDataContainer =
234  const_cast< PointsContainer * >( m_PointsContainer.GetPointer() );
235 
236  Iterator iter( nonConstPointsDataContainer->End(), m_PointsContainer->Size() );
237 
238  return iter;
239  }
240 
242  ConstIterator Begin() const
243  {
244  ConstIterator iter(m_PointsContainer->Begin(), 0);
245 
246  return iter;
247  }
248 
250  ConstIterator End() const
251  {
252  ConstIterator iter( m_PointsContainer->End(), m_PointsContainer->Size() );
253 
254  return iter;
255  }
256 
257 protected:
259 
261  void PrintSelf(std::ostream & os, Indent indent) const;
262 
263 private:
264  PointSetToListSampleAdaptor(const Self &); //purposely not implemented
265  void operator=(const Self &); //purposely not implemented
266 
269 
273 
276 }; // end of class PointSetToListSampleAdaptor
277 } // end of namespace Statistics
278 } // end of namespace itk
279 
280 #ifndef ITK_MANUAL_INSTANTIATION
281 #include "itkPointSetToListSampleAdaptor.hxx"
282 #endif
283 
284 #endif
285