ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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{
44
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;
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;
80 using typename Superclass::InstanceIdentifier;
81
83
88 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;
119 }
120
121 ConstIterator() = delete;
122
125 {
126 this->m_Iter = iter.m_Iter;
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;
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:
212 };
213
215 Iterator
217 {
218 VectorContainerPointer nonConstVectorDataContainer =
219 const_cast<VectorContainerType *>(this->m_VectorContainer.GetPointer());
220 Iterator iter(nonConstVectorDataContainer->Begin(), 0);
221
222 return iter;
223 }
224
226 Iterator
228 {
229 VectorContainerPointer nonConstVectorDataContainer =
230 const_cast<VectorContainerType *>(this->m_VectorContainer.GetPointer());
231
232 Iterator iter(nonConstVectorDataContainer->End(), this->m_VectorContainer->Size());
233
234 return iter;
235 }
236
238 ConstIterator
239 Begin() const
240 {
241 const ConstIterator iter(this->m_VectorContainer->Begin(), 0);
242
243 return iter;
244 }
245
247 ConstIterator
248 End() const
249 {
250 const ConstIterator iter(this->m_VectorContainer->End(), this->m_VectorContainer->Size());
251 return iter;
252 }
253
254protected:
256
258 void
259 PrintSelf(std::ostream & os, Indent indent) const override;
260
261private:
263}; // end of class VectorContainerToListSampleAdaptor
264} // end of namespace Statistics
265} // end of namespace itk
266
267#ifndef ITK_MANUAL_INSTANTIATION
268# include "itkVectorContainerToListSampleAdaptor.hxx"
269#endif
270
271#endif
Control indentation during Print() invocation.
Definition itkIndent.h:50
Implements transparent reference counting.
typename MeasurementVectorTraitsTypes< MeasurementVectorType >::ValueType MeasurementType
typename MeasurementVectorTraits::InstanceIdentifier InstanceIdentifier
NumericTraits< AbsoluteFrequencyType >::AccumulateType TotalAbsoluteFrequencyType
MeasurementVectorTraits::AbsoluteFrequencyType AbsoluteFrequencyType
ConstIterator(VectorContainerConstIterator iter, InstanceIdentifier iid)
Iterator(VectorContainerConstIterator iter, InstanceIdentifier iid)=delete
ConstIterator & operator=(const ConstIterator &it)=delete
void PrintSelf(std::ostream &os, Indent indent) const override
ListSample< typename TVectorContainer::Element > Superclass
TotalAbsoluteFrequencyType GetTotalFrequency() const override
typename MeasurementVectorTraits::InstanceIdentifier InstanceIdentifier
MeasurementVectorTraits::AbsoluteFrequencyType AbsoluteFrequencyType
typename TVectorContainer::Element MeasurementVectorType
NumericTraits< AbsoluteFrequencyType >::AccumulateType TotalAbsoluteFrequencyType
InstanceIdentifier Size() const override
AbsoluteFrequencyType GetFrequency(InstanceIdentifier) const override
const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier) const override
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
detail::VectorContainer< std::conditional_t< std::is_void_v< T2 >, SizeValueType, T1 >, std::conditional_t< std::is_void_v< T2 >, T1, T2 > > VectorContainer