ITK  4.8.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< typename 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 
81 
83 
85  itkSetObjectMacro( VectorContainer, VectorContainerType );
86  itkGetConstObjectMacro(VectorContainer, VectorContainerType );
88 
90  InstanceIdentifier Size() const ITK_OVERRIDE;
91 
95 
98 
100  TotalAbsoluteFrequencyType GetTotalFrequency() const ITK_OVERRIDE;
101 
106  {
108  public:
109 
111  {
112  *this = adaptor->Begin();
113  }
114 
115  ConstIterator(const ConstIterator & iter)
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 
129  {
130  return 1;
131  }
132 
134  {
135  return ( const MeasurementVectorType & )m_Iter.Value();
136  }
137 
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 
214  {
215  VectorContainerPointer nonConstVectorDataContainer =
216  const_cast< VectorContainerType * >( this->m_VectorContainer.GetPointer() );
217  Iterator iter( nonConstVectorDataContainer->Begin(), 0 );
219 
220  return iter;
221  }
222 
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 
237  {
238  ConstIterator iter( this->m_VectorContainer->Begin(), 0 );
239 
240  return iter;
241  }
242 
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 ITK_OVERRIDE;
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
Superclass::MeasurementType MeasurementType
Definition: itkListSample.h:69
This class provides ListSample interface to ITK VectorContainer.
Superclass::MeasurementVectorType MeasurementVectorType
Definition: itkListSample.h:64
Superclass::TotalAbsoluteFrequencyType TotalAbsoluteFrequencyType
Definition: itkListSample.h:71
InstanceIdentifier Size() const override
ListSample< typename TVectorContainer::Element > Superclass
TotalAbsoluteFrequencyType GetTotalFrequency() const override
Superclass::AbsoluteFrequencyType AbsoluteFrequencyType
Definition: itkListSample.h:70
Superclass::InstanceIdentifier InstanceIdentifier
Definition: itkListSample.h:72
Superclass::MeasurementVectorSizeType MeasurementVectorSizeType
Definition: itkListSample.h:68
void PrintSelf(std::ostream &os, Indent indent) const override
AbsoluteFrequencyType GetFrequency(InstanceIdentifier) const override
This class is the native implementation of the a Sample with an STL container.
Definition: itkListSample.h:51
Define a front-end to the STL &quot;vector&quot; container that conforms to the IndexedContainerInterface.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier) const override
ConstIterator(VectorContainerConstIterator iter, InstanceIdentifier iid)
Base class for all data objects in ITK.