ITK  4.4.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  itkGetConstObjectMacro(VectorContainer, VectorContainerType );
88 
90  InstanceIdentifier Size() const;
91 
94  const MeasurementVectorType & GetMeasurementVector( InstanceIdentifier ) const;
95 
97  AbsoluteFrequencyType GetFrequency( InstanceIdentifier ) const;
98 
100  TotalAbsoluteFrequencyType GetTotalFrequency() const;
101 
106  {
108  public:
109 
111  {
112  *this = adaptor->Begin();
113  }
114 
116  {
117  this->m_Iter = iter.m_Iter;
118  this->m_InstanceIdentifier = iter.m_InstanceIdentifier;
119  }
120 
121  ConstIterator & operator=(const ConstIterator & iter)
122  {
123  this->m_Iter = iter.m_Iter;
124  this->m_InstanceIdentifier = iter.m_InstanceIdentifier;
125  return *this;
126  }
127 
128  AbsoluteFrequencyType GetFrequency() const
129  {
130  return 1;
131  }
132 
133  const MeasurementVectorType & GetMeasurementVector() const
134  {
135  return ( const MeasurementVectorType & )m_Iter.Value();
136  }
137 
138  InstanceIdentifier GetInstanceIdentifier() const
139  {
140  return this->m_InstanceIdentifier;
141  }
142 
143  ConstIterator & operator++()
144  {
145  ++m_Iter;
146  ++m_InstanceIdentifier;
147  return *this;
148  }
149 
150  bool operator!=( const ConstIterator & it )
151  {
152  return ( this->m_Iter != it.m_Iter );
153  }
154 
155  bool operator==( const ConstIterator & it )
156  {
157  return ( this->m_Iter == it.m_Iter );
158  }
159 
160  protected:
161  // This method should only be available to the ListSample class
163  InstanceIdentifier iid )
164  {
165  this->m_Iter = iter;
166  this->m_InstanceIdentifier = iid;
167  }
168 
169  // This method is purposely not implemented
170  ConstIterator();
171  private:
174  };
175 
179  class Iterator:public ConstIterator
180  {
182  public:
183 
184  Iterator(Self *adaptor):ConstIterator(adaptor)
185  {}
186 
187  Iterator(const Iterator & iter):ConstIterator(iter)
188  {}
189 
190  Iterator & operator=(const Iterator & iter)
191  {
192  this->ConstIterator::operator=(iter);
193  return *this;
194  }
195 
196  protected:
197  // To ensure const-correctness these method must not be in the public API.
198  // The are purposly not implemented, since they should never be called.
199  Iterator();
200  Iterator( const Self *adaptor );
202  Iterator( const ConstIterator & it);
203  ConstIterator & operator=( const ConstIterator & it );
204 
206  :ConstIterator( iter, iid )
207  {}
208 
209  private:
210  };
211 
213  Iterator Begin()
214  {
215  VectorContainerPointer nonConstVectorDataContainer =
216  const_cast< VectorContainerType * >( this->m_VectorContainer.GetPointer() );
217  Iterator iter( nonConstVectorDataContainer->Begin(), 0 );
219 
220  return iter;
221  }
222 
224  Iterator End()
225  {
226  VectorContainerPointer nonConstVectorDataContainer =
227  const_cast<VectorContainerType *>( this->m_VectorContainer.GetPointer() );
228 
229  Iterator iter( nonConstVectorDataContainer->End(),
230  this->m_VectorContainer->Size() );
231 
232  return iter;
233  }
234 
236  ConstIterator Begin() const
237  {
238  ConstIterator iter( this->m_VectorContainer->Begin(), 0 );
239 
240  return iter;
241  }
242 
244  ConstIterator End() const
245  {
246  ConstIterator iter( this->m_VectorContainer->End(),
247  this->m_VectorContainer->Size() );
248  return iter;
249  }
251 
252 protected:
254 
256  void PrintSelf( std::ostream & os, Indent indent ) const;
257 
258 private:
259  VectorContainerToListSampleAdaptor( const Self & ); //purposely not implemented
260  void operator=( const Self & ); //purposely not implemented
261 
265 
267  mutable typename VectorContainerType::Element m_TempPoint;
268 }; // end of class VectorContainerToListSampleAdaptor
269 } // end of namespace Statistics
270 } // end of namespace itk
271 
272 #ifndef ITK_MANUAL_INSTANTIATION
273 #include "itkVectorContainerToListSampleAdaptor.hxx"
274 #endif
275 
276 #endif
277