ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkVectorContainerToListSampleAdaptor.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 __itkVectorContainerToListSampleAdaptor_h
19 #define __itkVectorContainerToListSampleAdaptor_h
20 
21 #include <typeinfo>
22 
23 #include "itkListSample.h"
24 #include "itkSmartPointer.h"
25 #include "itkVectorContainer.h"
26 
27 namespace itk
28 {
29 namespace Statistics
30 {
45 template< class TVectorContainer >
47  public ListSample< typename TVectorContainer::Element >
48 {
49 public:
55 
58 
60  itkNewMacro( Self );
61 
63  itkStaticConstMacro( MeasurementVectorSize, unsigned int,
64  TVectorContainer::Element::Dimension );
65 
67  typedef TVectorContainer VectorContainerType;
68  typedef typename TVectorContainer::Pointer VectorContainerPointer;
69  typedef typename TVectorContainer::ConstPointer VectorContainerConstPointer;
70  typedef typename TVectorContainer::Iterator VectorContainerIterator;
71  typedef typename TVectorContainer::ConstIterator VectorContainerConstIterator;
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  itkSetObjectMacro( VectorContainer, VectorContainerType );
86 
88  itkGetConstObjectMacro( VectorContainer, VectorContainerType );
89 
91  InstanceIdentifier Size() const;
92 
95  const MeasurementVectorType & GetMeasurementVector( InstanceIdentifier ) const;
96 
98  AbsoluteFrequencyType GetFrequency( InstanceIdentifier ) const;
99 
101  TotalAbsoluteFrequencyType GetTotalFrequency() const;
102 
107  {
109  public:
110 
112  {
113  *this = adaptor->Begin();
114  }
115 
117  {
118  this->m_Iter = iter.m_Iter;
119  this->m_InstanceIdentifier = iter.m_InstanceIdentifier;
120  }
121 
122  ConstIterator & operator=(const ConstIterator & iter)
123  {
124  this->m_Iter = iter.m_Iter;
125  this->m_InstanceIdentifier = iter.m_InstanceIdentifier;
126  return *this;
127  }
128 
129  AbsoluteFrequencyType GetFrequency() const
130  {
131  return 1;
132  }
133 
134  const MeasurementVectorType & GetMeasurementVector() const
135  {
136  return ( const MeasurementVectorType & )m_Iter.Value();
137  }
138 
139  InstanceIdentifier GetInstanceIdentifier() const
140  {
141  return this->m_InstanceIdentifier;
142  }
143 
144  ConstIterator & operator++()
145  {
146  ++m_Iter;
147  ++m_InstanceIdentifier;
148  return *this;
149  }
150 
151  bool operator!=( const ConstIterator & it )
152  {
153  return ( this->m_Iter != it.m_Iter );
154  }
155 
156  bool operator==( const ConstIterator & it )
157  {
158  return ( this->m_Iter == it.m_Iter );
159  }
160 
161  protected:
162  // This method should only be available to the ListSample class
164  InstanceIdentifier iid )
165  {
166  this->m_Iter = iter;
167  this->m_InstanceIdentifier = iid;
168  }
169 
170  // This method is purposely not implemented
171  ConstIterator();
172  private:
175  };
176 
180  class Iterator:public ConstIterator
181  {
183  public:
184 
185  Iterator(Self *adaptor):ConstIterator(adaptor)
186  {}
187 
188  Iterator(const Iterator & iter):ConstIterator(iter)
189  {}
190 
191  Iterator & operator=(const Iterator & iter)
192  {
193  this->ConstIterator::operator=(iter);
194  return *this;
195  }
196 
197  protected:
198  // To ensure const-correctness these method must not be in the public API.
199  // The are purposly not implemented, since they should never be called.
200  Iterator();
201  Iterator( const Self *adaptor );
203  Iterator( const ConstIterator & it);
204  ConstIterator & operator=( const ConstIterator & it );
205 
207  :ConstIterator( iter, iid )
208  {}
209 
210  private:
211  };
212 
214  Iterator Begin()
215  {
216  VectorContainerPointer nonConstVectorDataContainer =
217  const_cast< VectorContainerType * >( this->m_VectorContainer.GetPointer() );
218  Iterator iter( nonConstVectorDataContainer->Begin(), 0 );
220 
221  return iter;
222  }
223 
225  Iterator End()
226  {
227  VectorContainerPointer nonConstVectorDataContainer =
228  const_cast<VectorContainerType *>( this->m_VectorContainer.GetPointer() );
229 
230  Iterator iter( nonConstVectorDataContainer->End(),
231  this->m_VectorContainer->Size() );
232 
233  return iter;
234  }
235 
237  ConstIterator Begin() const
238  {
239  ConstIterator iter( this->m_VectorContainer->Begin(), 0 );
240 
241  return iter;
242  }
243 
245  ConstIterator End() const
246  {
247  ConstIterator iter( this->m_VectorContainer->End(),
248  this->m_VectorContainer->Size() );
249  return iter;
250  }
252 
253 protected:
255 
257  void PrintSelf( std::ostream & os, Indent indent ) const;
258 
259 private:
260  VectorContainerToListSampleAdaptor( const Self & ); //purposely not implemented
261  void operator=( const Self & ); //purposely not implemented
262 
266 
268  mutable typename VectorContainerType::Element m_TempPoint;
269 }; // end of class VectorContainerToListSampleAdaptor
270 } // end of namespace Statistics
271 } // end of namespace itk
272 
273 #ifndef ITK_MANUAL_INSTANTIATION
274 #include "itkVectorContainerToListSampleAdaptor.hxx"
275 #endif
276 
277 #endif
278