ITK  4.13.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 >
46 class ITK_TEMPLATE_EXPORT VectorContainerToListSampleAdaptor:
47  public ListSample< typename TVectorContainer::Element >
48 {
49 public:
55 
58 
60  itkNewMacro( Self );
61 
63  itkStaticConstMacro( MeasurementVectorSize, unsigned int,
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 ITK_OVERRIDE;
91 
94  const MeasurementVectorType & GetMeasurementVector( InstanceIdentifier ) const ITK_OVERRIDE;
95 
97  AbsoluteFrequencyType GetFrequency( InstanceIdentifier ) const ITK_OVERRIDE;
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  private:
170  ConstIterator() ITK_DELETED_FUNCTION;
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:
197  :ConstIterator( iter, iid )
198  {}
199 
200  private:
201  // To ensure const-correctness these method must not be in the public API.
202  // The are not implemented, since they should never be called.
203  Iterator() ITK_DELETED_FUNCTION;
204  Iterator( const Self *adaptor ) ITK_DELETED_FUNCTION;
205  Iterator( VectorContainerConstIterator iter, InstanceIdentifier iid ) ITK_DELETED_FUNCTION;
206  Iterator( const ConstIterator & it) ITK_DELETED_FUNCTION;
207  ConstIterator & operator=( const ConstIterator & it ) ITK_DELETED_FUNCTION;
208  };
209 
211  Iterator Begin()
212  {
213  VectorContainerPointer nonConstVectorDataContainer =
214  const_cast< VectorContainerType * >( this->m_VectorContainer.GetPointer() );
215  Iterator iter( nonConstVectorDataContainer->Begin(), 0 );
217 
218  return iter;
219  }
220 
223  {
224  VectorContainerPointer nonConstVectorDataContainer =
225  const_cast<VectorContainerType *>( this->m_VectorContainer.GetPointer() );
226 
227  Iterator iter( nonConstVectorDataContainer->End(),
228  this->m_VectorContainer->Size() );
229 
230  return iter;
231  }
232 
234  ConstIterator Begin() const
235  {
236  ConstIterator iter( this->m_VectorContainer->Begin(), 0 );
237 
238  return iter;
239  }
240 
242  ConstIterator End() const
243  {
244  ConstIterator iter( this->m_VectorContainer->End(),
245  this->m_VectorContainer->Size() );
246  return iter;
247  }
249 
250 protected:
252 
253  virtual ~VectorContainerToListSampleAdaptor() ITK_OVERRIDE {}
254  void PrintSelf( std::ostream & os, Indent indent ) const ITK_OVERRIDE;
255 
256 private:
257  ITK_DISALLOW_COPY_AND_ASSIGN(VectorContainerToListSampleAdaptor);
258 
262 
264  mutable typename VectorContainerType::Element m_TempPoint;
265 }; // end of class VectorContainerToListSampleAdaptor
266 } // end of namespace Statistics
267 } // end of namespace itk
268 
269 #ifndef ITK_MANUAL_INSTANTIATION
270 #include "itkVectorContainerToListSampleAdaptor.hxx"
271 #endif
272 
273 #endif
This class provides ListSample interface to ITK VectorContainer.
Represent the size (bounds) of a n-dimensional image.
Definition: itkSize.h:52
ListSample< typename TVectorContainer::Element > Superclass
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
ConstIterator(VectorContainerConstIterator iter, InstanceIdentifier iid)
Base class for all data objects in ITK.