ITK  6.0.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 * https://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
27namespace itk
28{
29namespace Statistics
30{
45template <typename TVectorContainer>
46class ITK_TEMPLATE_EXPORT VectorContainerToListSampleAdaptor : public ListSample<typename TVectorContainer::Element>
47{
48public:
49 ITK_DISALLOW_COPY_AND_MOVE(VectorContainerToListSampleAdaptor);
50
56
58 itkOverrideGetNameOfClassMacro(VectorContainerToListSampleAdaptor);
59
61 itkNewMacro(Self);
62
64 static constexpr unsigned int MeasurementVectorSize = TVectorContainer::Element::Dimension;
65
67 using VectorContainerType = TVectorContainer;
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
87 itkGetConstObjectMacro(VectorContainer, VectorContainerType);
92 Size() const override;
93
97
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
125 {
126 this->m_Iter = iter.m_Iter;
127 this->m_InstanceIdentifier = iter.m_InstanceIdentifier;
128 return *this;
129 }
130
133 {
134 return 1;
135 }
136
139 {
140 return (const MeasurementVectorType &)m_Iter.Value();
141 }
142
145 {
146 return this->m_InstanceIdentifier;
147 }
148
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
164
165 protected:
166 // This method should only be available to the ListSample class
168 {
169 this->m_Iter = iter;
170 this->m_InstanceIdentifier = iid;
171 }
172
173 private:
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;
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);
223 return iter;
224 }
225
227 Iterator
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 }
256protected:
258
260 void
261 PrintSelf(std::ostream & os, Indent indent) const override;
262
263private:
264 VectorContainerConstPointer m_VectorContainer{};
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
Base class for all data objects in ITK.
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Base class for most ITK classes.
Definition: itkObject.h:62
This class is the native implementation of the a Sample with an STL container.
Definition: itkListSample.h:52
typename MeasurementVectorTraits::InstanceIdentifier InstanceIdentifier
Definition: itkSample.h:91
NumericTraits< AbsoluteFrequencyType >::AccumulateType TotalAbsoluteFrequencyType
Definition: itkSample.h:87
MeasurementVectorTraits::AbsoluteFrequencyType AbsoluteFrequencyType
Definition: itkSample.h:84
ConstIterator(VectorContainerConstIterator iter, InstanceIdentifier iid)
Iterator(VectorContainerConstIterator iter, InstanceIdentifier iid)=delete
ConstIterator & operator=(const ConstIterator &it)=delete
This class provides ListSample interface to ITK VectorContainer.
void PrintSelf(std::ostream &os, Indent indent) const override
TotalAbsoluteFrequencyType GetTotalFrequency() const override
InstanceIdentifier Size() const override
AbsoluteFrequencyType GetFrequency(InstanceIdentifier) const override
const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier) const override
Define a front-end to the STL "vector" container that conforms to the IndexedContainerInterface.
SmartPointer< const Self > ConstPointer
SmartPointer< Self > Pointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....