ITK  5.0.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:
50  ITK_DISALLOW_COPY_AND_ASSIGN(VectorContainerToListSampleAdaptor);
51 
57 
60 
62  itkNewMacro( Self );
63 
65  static constexpr unsigned int MeasurementVectorSize = TVectorContainer::Element::Dimension;
66 
68  using VectorContainerType = TVectorContainer;
69  using VectorContainerPointer = typename TVectorContainer::Pointer;
70  using VectorContainerConstPointer = typename TVectorContainer::ConstPointer;
71  using VectorContainerIterator = typename TVectorContainer::Iterator;
72  using VectorContainerConstIterator = typename TVectorContainer::ConstIterator;
73 
76  using MeasurementType = typename Superclass::MeasurementType;
77  using MeasurementVectorType = typename Superclass::MeasurementVectorType;
78  using AbsoluteFrequencyType = typename Superclass::AbsoluteFrequencyType;
79  using TotalAbsoluteFrequencyType = typename Superclass::TotalAbsoluteFrequencyType;
80  using MeasurementVectorSizeType = typename Superclass::MeasurementVectorSizeType;
81  using InstanceIdentifier = typename Superclass::InstanceIdentifier;
82 
84 
86  itkSetObjectMacro( VectorContainer, VectorContainerType );
87  itkGetConstObjectMacro(VectorContainer, VectorContainerType );
89 
91  InstanceIdentifier Size() const override;
92 
95  const MeasurementVectorType & GetMeasurementVector( InstanceIdentifier ) const override;
96 
98  AbsoluteFrequencyType GetFrequency( InstanceIdentifier ) const override;
99 
101  TotalAbsoluteFrequencyType GetTotalFrequency() const override;
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 
123  {
124  this->m_Iter = iter.m_Iter;
125  this->m_InstanceIdentifier = iter.m_InstanceIdentifier;
126  return *this;
127  }
128 
130  {
131  return 1;
132  }
133 
135  {
136  return ( const MeasurementVectorType & )m_Iter.Value();
137  }
138 
140  {
141  return this->m_InstanceIdentifier;
142  }
143 
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  private:
171  ConstIterator() = delete;
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:
198  :ConstIterator( iter, iid )
199  {}
200 
201  private:
202  // To ensure const-correctness these method must not be in the public API.
203  // The are not implemented, since they should never be called.
204  Iterator() = delete;
205  Iterator( const Self *adaptor ) = delete;
207  Iterator( const ConstIterator & it) = delete;
208  ConstIterator & operator=( const ConstIterator & it ) = delete;
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 
236  {
237  ConstIterator iter( this->m_VectorContainer->Begin(), 0 );
238 
239  return iter;
240  }
241 
244  {
245  ConstIterator iter( this->m_VectorContainer->End(),
246  this->m_VectorContainer->Size() );
247  return iter;
248  }
250 
251 protected:
253 
254  ~VectorContainerToListSampleAdaptor() override = default;
255  void PrintSelf( std::ostream & os, Indent indent ) const override;
256 
257 private:
261 
263  mutable typename VectorContainerType::Element m_TempPoint;
264 }; // end of class VectorContainerToListSampleAdaptor
265 } // end of namespace Statistics
266 } // end of namespace itk
267 
268 #ifndef ITK_MANUAL_INSTANTIATION
269 #include "itkVectorContainerToListSampleAdaptor.hxx"
270 #endif
271 
272 #endif
This class provides ListSample interface to ITK VectorContainer.
typename Superclass::TotalAbsoluteFrequencyType TotalAbsoluteFrequencyType
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:68
typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType
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 most ITK classes.
Definition: itkObject.h:60
Base class for all data objects in ITK.