ITK  5.2.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_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() = delete;
121 
122  ConstIterator &
123  operator=(const ConstIterator & iter)
124  {
125  this->m_Iter = iter.m_Iter;
126  this->m_InstanceIdentifier = iter.m_InstanceIdentifier;
127  return *this;
128  }
129 
131  GetFrequency() const
132  {
133  return 1;
134  }
135 
136  const MeasurementVectorType &
138  {
139  return (const MeasurementVectorType &)m_Iter.Value();
140  }
141 
144  {
145  return this->m_InstanceIdentifier;
146  }
147 
148  ConstIterator &
150  {
151  ++m_Iter;
152  ++m_InstanceIdentifier;
153  return *this;
154  }
155 
156  bool
158  {
159  return (this->m_Iter != it.m_Iter);
160  }
161 
162  bool
164  {
165  return (this->m_Iter == it.m_Iter);
166  }
167 
168  protected:
169  // This method should only be available to the ListSample class
171  {
172  this->m_Iter = iter;
173  this->m_InstanceIdentifier = iid;
174  }
175 
176  private:
179  };
180 
184  class Iterator : public ConstIterator
185  {
187 
188  public:
189  Iterator() = delete;
190  Iterator(const Self * adaptor) = delete;
192  Iterator(const ConstIterator & it) = delete;
193  ConstIterator &
194  operator=(const ConstIterator & it) = delete;
195 
196  Iterator(Self * adaptor)
197  : ConstIterator(adaptor)
198  {}
199 
200  Iterator(const Iterator & iter)
201  : ConstIterator(iter)
202  {}
203 
204  Iterator &
205  operator=(const Iterator & iter)
206  {
207  this->ConstIterator::operator=(iter);
208  return *this;
209  }
210 
211  protected:
213  : ConstIterator(iter, iid)
214  {}
215  };
216 
218  Iterator
220  {
221  VectorContainerPointer nonConstVectorDataContainer =
222  const_cast<VectorContainerType *>(this->m_VectorContainer.GetPointer());
223  Iterator iter(nonConstVectorDataContainer->Begin(), 0);
225 
226  return iter;
227  }
228 
230  Iterator
231  End()
232  {
233  VectorContainerPointer nonConstVectorDataContainer =
234  const_cast<VectorContainerType *>(this->m_VectorContainer.GetPointer());
235 
236  Iterator iter(nonConstVectorDataContainer->End(), this->m_VectorContainer->Size());
237 
238  return iter;
239  }
240 
242  ConstIterator
243  Begin() const
244  {
245  ConstIterator iter(this->m_VectorContainer->Begin(), 0);
246 
247  return iter;
248  }
249 
251  ConstIterator
252  End() const
253  {
254  ConstIterator iter(this->m_VectorContainer->End(), this->m_VectorContainer->Size());
255  return iter;
256  }
258 
259 protected:
261 
262  ~VectorContainerToListSampleAdaptor() override = default;
263  void
264  PrintSelf(std::ostream & os, Indent indent) const override;
265 
266 private:
270 }; // end of class VectorContainerToListSampleAdaptor
271 } // end of namespace Statistics
272 } // end of namespace itk
273 
274 #ifndef ITK_MANUAL_INSTANTIATION
275 # include "itkVectorContainerToListSampleAdaptor.hxx"
276 #endif
277 
278 #endif
itk::Statistics::VectorContainerToListSampleAdaptor::Iterator::operator=
Iterator & operator=(const Iterator &iter)
Definition: itkVectorContainerToListSampleAdaptor.h:205
itk::Statistics::VectorContainerToListSampleAdaptor::ConstIterator::GetInstanceIdentifier
InstanceIdentifier GetInstanceIdentifier() const
Definition: itkVectorContainerToListSampleAdaptor.h:143
itk::Statistics::VectorContainerToListSampleAdaptor::VectorContainerConstIterator
typename TVectorContainer::ConstIterator VectorContainerConstIterator
Definition: itkVectorContainerToListSampleAdaptor.h:71
itk::Statistics::VectorContainerToListSampleAdaptor::ConstIterator::GetMeasurementVector
const MeasurementVectorType & GetMeasurementVector() const
Definition: itkVectorContainerToListSampleAdaptor.h:137
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:170
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:149
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:219
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:131
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:184
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:163
itk::Statistics::VectorContainerToListSampleAdaptor::ConstIterator::operator!=
bool operator!=(const ConstIterator &it)
Definition: itkVectorContainerToListSampleAdaptor.h:157
itk::Statistics::VectorContainerToListSampleAdaptor::Iterator::Iterator
Iterator(Self *adaptor)
Definition: itkVectorContainerToListSampleAdaptor.h:196
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:231
itk::Statistics::VectorContainerToListSampleAdaptor::Iterator::Iterator
Iterator(VectorContainerIterator iter, InstanceIdentifier iid)
Definition: itkVectorContainerToListSampleAdaptor.h:212
itkVectorContainer.h
itk::Statistics::VectorContainerToListSampleAdaptor::Begin
ConstIterator Begin() const
Definition: itkVectorContainerToListSampleAdaptor.h:243
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:269
itk::Statistics::VectorContainerToListSampleAdaptor::ConstIterator
Definition: itkVectorContainerToListSampleAdaptor.h:107
itk::Statistics::VectorContainerToListSampleAdaptor::ConstIterator::m_InstanceIdentifier
InstanceIdentifier m_InstanceIdentifier
Definition: itkVectorContainerToListSampleAdaptor.h:178
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:123
itk::Statistics::VectorContainerToListSampleAdaptor::Iterator::Iterator
Iterator(const Iterator &iter)
Definition: itkVectorContainerToListSampleAdaptor.h:200
itk::Statistics::VectorContainerToListSampleAdaptor::ConstIterator::m_Iter
VectorContainerConstIterator m_Iter
Definition: itkVectorContainerToListSampleAdaptor.h:177
itk::Statistics::VectorContainerToListSampleAdaptor::End
ConstIterator End() const
Definition: itkVectorContainerToListSampleAdaptor.h:252
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