ITK  5.3.0
Insight Toolkit
itkVectorContainerToListSampleAdaptor.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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_MOVE(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 typename Superclass::MeasurementType;
76  using typename Superclass::MeasurementVectorType;
77  using typename Superclass::AbsoluteFrequencyType;
78  using typename Superclass::TotalAbsoluteFrequencyType;
79  using typename Superclass::MeasurementVectorSizeType;
80  using typename Superclass::InstanceIdentifier;
81 
83 
86  itkSetObjectMacro(VectorContainer, VectorContainerType);
87  itkGetConstObjectMacro(VectorContainer, VectorContainerType);
89 
92  Size() const override;
93 
96  const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier) const override;
97 
99  AbsoluteFrequencyType GetFrequency(InstanceIdentifier) const override;
100 
103  GetTotalFrequency() const override;
104 
109  {
111 
112  public:
113  ConstIterator(const VectorContainerToListSampleAdaptor * adaptor) { *this = adaptor->Begin(); }
114 
116  {
117  this->m_Iter = iter.m_Iter;
118  this->m_InstanceIdentifier = iter.m_InstanceIdentifier;
119  }
120 
121  ConstIterator() = delete;
122 
123  ConstIterator &
124  operator=(const ConstIterator & iter)
125  {
126  this->m_Iter = iter.m_Iter;
127  this->m_InstanceIdentifier = iter.m_InstanceIdentifier;
128  return *this;
129  }
130 
132  GetFrequency() const
133  {
134  return 1;
135  }
136 
137  const MeasurementVectorType &
139  {
140  return (const MeasurementVectorType &)m_Iter.Value();
141  }
142 
145  {
146  return this->m_InstanceIdentifier;
147  }
148 
149  ConstIterator &
151  {
152  ++m_Iter;
153  ++m_InstanceIdentifier;
154  return *this;
155  }
156 
157  bool
158  operator==(const ConstIterator & it) const
159  {
160  return (this->m_Iter == it.m_Iter);
161  }
162 
163  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(ConstIterator);
164 
165  protected:
166  // This method should only be available to the ListSample class
167  ConstIterator(VectorContainerConstIterator iter, InstanceIdentifier iid)
168  {
169  this->m_Iter = iter;
170  this->m_InstanceIdentifier = iid;
171  }
172 
173  private:
175  InstanceIdentifier m_InstanceIdentifier;
176  };
177 
181  class Iterator : public ConstIterator
182  {
184 
185  public:
186  Iterator() = delete;
187  Iterator(const Self * adaptor) = delete;
189  Iterator(const ConstIterator & it) = delete;
190  ConstIterator &
191  operator=(const ConstIterator & it) = delete;
192 
193  Iterator(Self * adaptor)
194  : ConstIterator(adaptor)
195  {}
196 
197  Iterator(const Iterator & iter)
198  : ConstIterator(iter)
199  {}
200 
201  Iterator &
202  operator=(const Iterator & iter)
203  {
204  this->ConstIterator::operator=(iter);
205  return *this;
206  }
207 
208  protected:
210  : ConstIterator(iter, iid)
211  {}
212  };
213 
215  Iterator
217  {
218  VectorContainerPointer nonConstVectorDataContainer =
219  const_cast<VectorContainerType *>(this->m_VectorContainer.GetPointer());
220  Iterator iter(nonConstVectorDataContainer->Begin(), 0);
222 
223  return iter;
224  }
225 
227  Iterator
228  End()
229  {
230  VectorContainerPointer nonConstVectorDataContainer =
231  const_cast<VectorContainerType *>(this->m_VectorContainer.GetPointer());
232 
233  Iterator iter(nonConstVectorDataContainer->End(), this->m_VectorContainer->Size());
234 
235  return iter;
236  }
237 
239  ConstIterator
240  Begin() const
241  {
242  ConstIterator iter(this->m_VectorContainer->Begin(), 0);
243 
244  return iter;
245  }
246 
248  ConstIterator
249  End() const
250  {
251  ConstIterator iter(this->m_VectorContainer->End(), this->m_VectorContainer->Size());
252  return iter;
253  }
255 
256 protected:
258 
259  ~VectorContainerToListSampleAdaptor() override = default;
260  void
261  PrintSelf(std::ostream & os, Indent indent) const override;
262 
263 private:
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
itk::Statistics::VectorContainerToListSampleAdaptor::Iterator::operator=
Iterator & operator=(const Iterator &iter)
Definition: itkVectorContainerToListSampleAdaptor.h:202
itk::Statistics::VectorContainerToListSampleAdaptor::ConstIterator::GetInstanceIdentifier
InstanceIdentifier GetInstanceIdentifier() const
Definition: itkVectorContainerToListSampleAdaptor.h:144
itk::Statistics::VectorContainerToListSampleAdaptor::VectorContainerConstIterator
typename TVectorContainer::ConstIterator VectorContainerConstIterator
Definition: itkVectorContainerToListSampleAdaptor.h:71
itk::Statistics::VectorContainerToListSampleAdaptor::ConstIterator::GetMeasurementVector
const MeasurementVectorType & GetMeasurementVector() const
Definition: itkVectorContainerToListSampleAdaptor.h:138
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:167
itk::Statistics::Sample< TVectorContainer::Element >::MeasurementVectorType
TVectorContainer::Element MeasurementVectorType
Definition: itkSample.h:77
itk::Statistics::VectorContainerToListSampleAdaptor::VectorContainerType
TVectorContainer VectorContainerType
Definition: itkVectorContainerToListSampleAdaptor.h:67
itk::Statistics::VectorContainerToListSampleAdaptor::ConstIterator::ConstIterator
ConstIterator(const VectorContainerToListSampleAdaptor *adaptor)
Definition: itkVectorContainerToListSampleAdaptor.h:113
itk::Statistics::VectorContainerToListSampleAdaptor::ConstIterator::operator==
bool operator==(const ConstIterator &it) const
Definition: itkVectorContainerToListSampleAdaptor.h:158
itk::Statistics::VectorContainerToListSampleAdaptor::ConstIterator::operator++
ConstIterator & operator++()
Definition: itkVectorContainerToListSampleAdaptor.h:150
itk::Statistics::Sample< TVectorContainer::Element >::TotalAbsoluteFrequencyType
NumericTraits< AbsoluteFrequencyType >::AccumulateType TotalAbsoluteFrequencyType
Definition: itkSample.h:87
itk::Statistics::VectorContainerToListSampleAdaptor::Begin
Iterator Begin()
Definition: itkVectorContainerToListSampleAdaptor.h:216
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:132
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::Statistics::Sample< TVectorContainer::Element >::InstanceIdentifier
typename MeasurementVectorTraits::InstanceIdentifier InstanceIdentifier
Definition: itkSample.h:91
itk::Statistics::VectorContainerToListSampleAdaptor
This class provides ListSample interface to ITK VectorContainer.
Definition: itkVectorContainerToListSampleAdaptor.h:46
itk::Statistics::VectorContainerToListSampleAdaptor::Iterator
Definition: itkVectorContainerToListSampleAdaptor.h:181
itk::Statistics::VectorContainerToListSampleAdaptor::VectorContainerPointer
typename TVectorContainer::Pointer VectorContainerPointer
Definition: itkVectorContainerToListSampleAdaptor.h:68
itk::Statistics::VectorContainerToListSampleAdaptor::ConstIterator::ConstIterator
ConstIterator(const ConstIterator &iter)
Definition: itkVectorContainerToListSampleAdaptor.h:115
itk::Statistics::Sample< TVectorContainer::Element >::AbsoluteFrequencyType
MeasurementVectorTraits::AbsoluteFrequencyType AbsoluteFrequencyType
Definition: itkSample.h:84
itk::Statistics::VectorContainerToListSampleAdaptor::Iterator::Iterator
Iterator(Self *adaptor)
Definition: itkVectorContainerToListSampleAdaptor.h:193
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:228
itk::Statistics::VectorContainerToListSampleAdaptor::Iterator::Iterator
Iterator(VectorContainerIterator iter, InstanceIdentifier iid)
Definition: itkVectorContainerToListSampleAdaptor.h:209
itkVectorContainer.h
itk::Statistics::VectorContainerToListSampleAdaptor::Begin
ConstIterator Begin() const
Definition: itkVectorContainerToListSampleAdaptor.h:240
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::Statistics::VectorContainerToListSampleAdaptor::m_VectorContainer
VectorContainerConstPointer m_VectorContainer
Definition: itkVectorContainerToListSampleAdaptor.h:264
itk::Statistics::VectorContainerToListSampleAdaptor::ConstIterator
Definition: itkVectorContainerToListSampleAdaptor.h:108
itk::Statistics::VectorContainerToListSampleAdaptor::ConstIterator::m_InstanceIdentifier
InstanceIdentifier m_InstanceIdentifier
Definition: itkVectorContainerToListSampleAdaptor.h:175
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itkSmartPointer.h
itk::Statistics::VectorContainerToListSampleAdaptor::ConstIterator::operator=
ConstIterator & operator=(const ConstIterator &iter)
Definition: itkVectorContainerToListSampleAdaptor.h:124
itk::Statistics::VectorContainerToListSampleAdaptor::Iterator::Iterator
Iterator(const Iterator &iter)
Definition: itkVectorContainerToListSampleAdaptor.h:197
itk::Statistics::VectorContainerToListSampleAdaptor::ConstIterator::m_Iter
VectorContainerConstIterator m_Iter
Definition: itkVectorContainerToListSampleAdaptor.h:174
itk::Statistics::VectorContainerToListSampleAdaptor::End
ConstIterator End() const
Definition: itkVectorContainerToListSampleAdaptor.h:249
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:293