ITK  4.9.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  ConstIterator() ITK_DELETE_FUNCTION;
170  private:
172  InstanceIdentifier m_InstanceIdentifier;
173  };
174 
178  class Iterator:public ConstIterator
179  {
181  public:
182 
183  Iterator(Self *adaptor):ConstIterator(adaptor)
184  {}
185 
186  Iterator(const Iterator & iter):ConstIterator(iter)
187  {}
188 
189  Iterator & operator=(const Iterator & iter)
190  {
191  this->ConstIterator::operator=(iter);
192  return *this;
193  }
194 
195  protected:
196  // To ensure const-correctness these method must not be in the public API.
197  // The are not implemented, since they should never be called.
198  Iterator() ITK_DELETE_FUNCTION;
199  Iterator( const Self *adaptor ) ITK_DELETE_FUNCTION;
200  Iterator( VectorContainerConstIterator iter, InstanceIdentifier iid ) ITK_DELETE_FUNCTION;
201  Iterator( const ConstIterator & it) ITK_DELETE_FUNCTION;
202  ConstIterator & operator=( const ConstIterator & it ) ITK_DELETE_FUNCTION;
203 
205  :ConstIterator( iter, iid )
206  {}
207 
208  private:
209  };
210 
213  {
214  VectorContainerPointer nonConstVectorDataContainer =
215  const_cast< VectorContainerType * >( this->m_VectorContainer.GetPointer() );
216  Iterator iter( nonConstVectorDataContainer->Begin(), 0 );
218 
219  return iter;
220  }
221 
224  {
225  VectorContainerPointer nonConstVectorDataContainer =
226  const_cast<VectorContainerType *>( this->m_VectorContainer.GetPointer() );
227 
228  Iterator iter( nonConstVectorDataContainer->End(),
229  this->m_VectorContainer->Size() );
230 
231  return iter;
232  }
233 
235  ConstIterator Begin() const
236  {
237  ConstIterator iter( this->m_VectorContainer->Begin(), 0 );
238 
239  return iter;
240  }
241 
243  ConstIterator End() const
244  {
245  ConstIterator iter( this->m_VectorContainer->End(),
246  this->m_VectorContainer->Size() );
247  return iter;
248  }
250 
251 protected:
253 
255  void PrintSelf( std::ostream & os, Indent indent ) const ITK_OVERRIDE;
256 
257 private:
258  VectorContainerToListSampleAdaptor( const Self & ) ITK_DELETE_FUNCTION;
259  void operator=( const Self & ) ITK_DELETE_FUNCTION;
260 
264 
266  mutable typename VectorContainerType::Element m_TempPoint;
267 }; // end of class VectorContainerToListSampleAdaptor
268 } // end of namespace Statistics
269 } // end of namespace itk
270 
271 #ifndef ITK_MANUAL_INSTANTIATION
272 #include "itkVectorContainerToListSampleAdaptor.hxx"
273 #endif
274 
275 #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.