ITK  5.1.0
Insight 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 : public ListSample<typename TVectorContainer::Element>
47 {
48 public:
49  ITK_DISALLOW_COPY_AND_ASSIGN(VectorContainerToListSampleAdaptor);
50 
56 
59 
61  itkNewMacro(Self);
62 
64  static constexpr unsigned int MeasurementVectorSize = TVectorContainer::Element::Dimension;
65 
67  using VectorContainerType = TVectorContainer;
68  using VectorContainerPointer = typename TVectorContainer::Pointer;
69  using VectorContainerConstPointer = typename TVectorContainer::ConstPointer;
70  using VectorContainerIterator = typename TVectorContainer::Iterator;
71  using VectorContainerConstIterator = typename TVectorContainer::ConstIterator;
72 
75  using MeasurementType = typename Superclass::MeasurementType;
76  using MeasurementVectorType = typename Superclass::MeasurementVectorType;
77  using AbsoluteFrequencyType = typename Superclass::AbsoluteFrequencyType;
78  using TotalAbsoluteFrequencyType = typename Superclass::TotalAbsoluteFrequencyType;
79  using MeasurementVectorSizeType = typename Superclass::MeasurementVectorSizeType;
80  using InstanceIdentifier = typename Superclass::InstanceIdentifier;
81 
83 
85  itkSetObjectMacro(VectorContainer, VectorContainerType);
86  itkGetConstObjectMacro(VectorContainer, VectorContainerType);
88 
91  Size() const override;
92 
95  const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier) const override;
96 
98  AbsoluteFrequencyType GetFrequency(InstanceIdentifier) const override;
99 
102  GetTotalFrequency() const override;
103 
108  {
110 
111  public:
112  ConstIterator(const VectorContainerToListSampleAdaptor * adaptor) { *this = adaptor->Begin(); }
113 
115  {
116  this->m_Iter = iter.m_Iter;
117  this->m_InstanceIdentifier = iter.m_InstanceIdentifier;
118  }
119 
120  ConstIterator &
121  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  GetFrequency() const
130  {
131  return 1;
132  }
133 
134  const MeasurementVectorType &
136  {
137  return (const MeasurementVectorType &)m_Iter.Value();
138  }
139 
142  {
143  return this->m_InstanceIdentifier;
144  }
145 
146  ConstIterator &
148  {
149  ++m_Iter;
150  ++m_InstanceIdentifier;
151  return *this;
152  }
153 
154  bool
156  {
157  return (this->m_Iter != it.m_Iter);
158  }
159 
160  bool
162  {
163  return (this->m_Iter == it.m_Iter);
164  }
165 
166  protected:
167  // This method should only be available to the ListSample class
169  {
170  this->m_Iter = iter;
171  this->m_InstanceIdentifier = iid;
172  }
173 
174  private:
175  ConstIterator() = delete;
178  };
179 
183  class Iterator : public ConstIterator
184  {
186 
187  public:
188  Iterator(Self * adaptor)
189  : ConstIterator(adaptor)
190  {}
191 
192  Iterator(const Iterator & iter)
193  : ConstIterator(iter)
194  {}
195 
196  Iterator &
197  operator=(const Iterator & iter)
198  {
199  this->ConstIterator::operator=(iter);
200  return *this;
201  }
202 
203  protected:
205  : ConstIterator(iter, iid)
206  {}
207 
208  private:
209  // To ensure const-correctness these method must not be in the public API.
210  // The are not implemented, since they should never be called.
211  Iterator() = delete;
212  Iterator(const Self * adaptor) = delete;
214  Iterator(const ConstIterator & it) = delete;
215  ConstIterator &
216  operator=(const ConstIterator & it) = delete;
217  };
218 
220  Iterator
222  {
223  VectorContainerPointer nonConstVectorDataContainer =
224  const_cast<VectorContainerType *>(this->m_VectorContainer.GetPointer());
225  Iterator iter(nonConstVectorDataContainer->Begin(), 0);
227 
228  return iter;
229  }
230 
232  Iterator
233  End()
234  {
235  VectorContainerPointer nonConstVectorDataContainer =
236  const_cast<VectorContainerType *>(this->m_VectorContainer.GetPointer());
237 
238  Iterator iter(nonConstVectorDataContainer->End(), this->m_VectorContainer->Size());
239 
240  return iter;
241  }
242 
244  ConstIterator
245  Begin() const
246  {
247  ConstIterator iter(this->m_VectorContainer->Begin(), 0);
248 
249  return iter;
250  }
251 
253  ConstIterator
254  End() const
255  {
256  ConstIterator iter(this->m_VectorContainer->End(), this->m_VectorContainer->Size());
257  return iter;
258  }
260 
261 protected:
263 
264  ~VectorContainerToListSampleAdaptor() override = default;
265  void
266  PrintSelf(std::ostream & os, Indent indent) const override;
267 
268 private:
272 }; // end of class VectorContainerToListSampleAdaptor
273 } // end of namespace Statistics
274 } // end of namespace itk
275 
276 #ifndef ITK_MANUAL_INSTANTIATION
277 # include "itkVectorContainerToListSampleAdaptor.hxx"
278 #endif
279 
280 #endif
itk::Statistics::VectorContainerToListSampleAdaptor::Iterator::operator=
Iterator & operator=(const Iterator &iter)
Definition: itkVectorContainerToListSampleAdaptor.h:197
itk::Statistics::VectorContainerToListSampleAdaptor::ConstIterator::GetInstanceIdentifier
InstanceIdentifier GetInstanceIdentifier() const
Definition: itkVectorContainerToListSampleAdaptor.h:141
itk::Statistics::VectorContainerToListSampleAdaptor::VectorContainerConstIterator
typename TVectorContainer::ConstIterator VectorContainerConstIterator
Definition: itkVectorContainerToListSampleAdaptor.h:71
itk::Statistics::VectorContainerToListSampleAdaptor::ConstIterator::GetMeasurementVector
const MeasurementVectorType & GetMeasurementVector() const
Definition: itkVectorContainerToListSampleAdaptor.h:135
itk::Statistics::VectorContainerToListSampleAdaptor::MeasurementVectorType
typename Superclass::MeasurementVectorType MeasurementVectorType
Definition: itkVectorContainerToListSampleAdaptor.h:76
itk::Size
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:69
itk::Statistics::VectorContainerToListSampleAdaptor::VectorContainerIterator
typename TVectorContainer::Iterator VectorContainerIterator
Definition: itkVectorContainerToListSampleAdaptor.h:70
itk::Statistics::VectorContainerToListSampleAdaptor::ConstIterator::ConstIterator
ConstIterator(VectorContainerConstIterator iter, InstanceIdentifier iid)
Definition: itkVectorContainerToListSampleAdaptor.h:168
itk::Statistics::VectorContainerToListSampleAdaptor::TotalAbsoluteFrequencyType
typename Superclass::TotalAbsoluteFrequencyType TotalAbsoluteFrequencyType
Definition: itkVectorContainerToListSampleAdaptor.h:78
itk::Statistics::VectorContainerToListSampleAdaptor::VectorContainerType
TVectorContainer VectorContainerType
Definition: itkVectorContainerToListSampleAdaptor.h:67
itk::Statistics::VectorContainerToListSampleAdaptor::ConstIterator::ConstIterator
ConstIterator(const VectorContainerToListSampleAdaptor *adaptor)
Definition: itkVectorContainerToListSampleAdaptor.h:112
itk::Statistics::VectorContainerToListSampleAdaptor::ConstIterator::operator++
ConstIterator & operator++()
Definition: itkVectorContainerToListSampleAdaptor.h:147
itk::Statistics::VectorContainerToListSampleAdaptor::InstanceIdentifier
typename Superclass::InstanceIdentifier InstanceIdentifier
Definition: itkVectorContainerToListSampleAdaptor.h:80
itk::Statistics::VectorContainerToListSampleAdaptor::MeasurementVectorSizeType
typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType
Definition: itkVectorContainerToListSampleAdaptor.h:79
itk::Statistics::VectorContainerToListSampleAdaptor::Begin
Iterator Begin()
Definition: itkVectorContainerToListSampleAdaptor.h:221
itk::Statistics::ListSample
This class is the native implementation of the a Sample with an STL container.
Definition: itkListSample.h:51
itk::Statistics::VectorContainerToListSampleAdaptor::ConstIterator::GetFrequency
AbsoluteFrequencyType GetFrequency() const
Definition: itkVectorContainerToListSampleAdaptor.h:129
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::Statistics::VectorContainerToListSampleAdaptor::AbsoluteFrequencyType
typename Superclass::AbsoluteFrequencyType AbsoluteFrequencyType
Definition: itkVectorContainerToListSampleAdaptor.h:77
itk::Statistics::VectorContainerToListSampleAdaptor
This class provides ListSample interface to ITK VectorContainer.
Definition: itkVectorContainerToListSampleAdaptor.h:46
itk::Statistics::VectorContainerToListSampleAdaptor::Iterator
Definition: itkVectorContainerToListSampleAdaptor.h:183
itk::Statistics::VectorContainerToListSampleAdaptor::VectorContainerPointer
typename TVectorContainer::Pointer VectorContainerPointer
Definition: itkVectorContainerToListSampleAdaptor.h:68
itk::Statistics::VectorContainerToListSampleAdaptor::ConstIterator::ConstIterator
ConstIterator(const ConstIterator &iter)
Definition: itkVectorContainerToListSampleAdaptor.h:114
itk::Statistics::VectorContainerToListSampleAdaptor::MeasurementType
typename Superclass::MeasurementType MeasurementType
Definition: itkVectorContainerToListSampleAdaptor.h:75
itk::Statistics::VectorContainerToListSampleAdaptor::ConstIterator::operator==
bool operator==(const ConstIterator &it)
Definition: itkVectorContainerToListSampleAdaptor.h:161
itk::Statistics::VectorContainerToListSampleAdaptor::ConstIterator::operator!=
bool operator!=(const ConstIterator &it)
Definition: itkVectorContainerToListSampleAdaptor.h:155
itk::Statistics::VectorContainerToListSampleAdaptor::Iterator::Iterator
Iterator(Self *adaptor)
Definition: itkVectorContainerToListSampleAdaptor.h:188
itk::Statistics::VectorContainerToListSampleAdaptor::ValueType
MeasurementVectorType ValueType
Definition: itkVectorContainerToListSampleAdaptor.h:82
itkListSample.h
itk::Statistics::VectorContainerToListSampleAdaptor::VectorContainerConstPointer
typename TVectorContainer::ConstPointer VectorContainerConstPointer
Definition: itkVectorContainerToListSampleAdaptor.h:69
itk::Statistics::VectorContainerToListSampleAdaptor::End
Iterator End()
Definition: itkVectorContainerToListSampleAdaptor.h:233
itk::Statistics::VectorContainerToListSampleAdaptor::Iterator::Iterator
Iterator(VectorContainerIterator iter, InstanceIdentifier iid)
Definition: itkVectorContainerToListSampleAdaptor.h:204
itkVectorContainer.h
itk::Statistics::VectorContainerToListSampleAdaptor::Begin
ConstIterator Begin() const
Definition: itkVectorContainerToListSampleAdaptor.h:245
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkArray.h:26
itk::Statistics::VectorContainerToListSampleAdaptor::m_VectorContainer
VectorContainerConstPointer m_VectorContainer
Definition: itkVectorContainerToListSampleAdaptor.h:271
itk::Statistics::VectorContainerToListSampleAdaptor::ConstIterator
Definition: itkVectorContainerToListSampleAdaptor.h:107
itk::Statistics::VectorContainerToListSampleAdaptor::ConstIterator::m_InstanceIdentifier
InstanceIdentifier m_InstanceIdentifier
Definition: itkVectorContainerToListSampleAdaptor.h:177
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:60
itkSmartPointer.h
itk::Statistics::VectorContainerToListSampleAdaptor::ConstIterator::operator=
ConstIterator & operator=(const ConstIterator &iter)
Definition: itkVectorContainerToListSampleAdaptor.h:121
itk::Statistics::VectorContainerToListSampleAdaptor::Iterator::Iterator
Iterator(const Iterator &iter)
Definition: itkVectorContainerToListSampleAdaptor.h:192
itk::Statistics::VectorContainerToListSampleAdaptor::ConstIterator::m_Iter
VectorContainerConstIterator m_Iter
Definition: itkVectorContainerToListSampleAdaptor.h:176
itk::Statistics::VectorContainerToListSampleAdaptor::End
ConstIterator End() const
Definition: itkVectorContainerToListSampleAdaptor.h:254
itk::GTest::TypedefsAndConstructors::Dimension2::Dimension
constexpr unsigned int Dimension
Definition: itkGTestTypedefsAndConstructors.h:44
itk::VectorContainer
Define a front-end to the STL "vector" container that conforms to the IndexedContainerInterface.
Definition: itkVectorContainer.h:48
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:288