ITK  6.0.0
Insight Toolkit
itkListSample.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 itkListSample_h
19#define itkListSample_h
20
21#include "itkObjectFactory.h"
22#include "itkFixedArray.h"
23#include "itkSample.h"
24
25#include <vector>
26
27namespace itk
28{
29namespace Statistics
30{
50template <typename TMeasurementVector>
51class ITK_TEMPLATE_EXPORT ListSample : public Sample<TMeasurementVector>
52{
53public:
54 ITK_DISALLOW_COPY_AND_MOVE(ListSample);
55
61
63 itkOverrideGetNameOfClassMacro(ListSample);
64
66 itkNewMacro(Self);
67
69 using typename Superclass::MeasurementVectorType;
70 using typename Superclass::MeasurementVectorSizeType;
71 using typename Superclass::MeasurementType;
72 using typename Superclass::AbsoluteFrequencyType;
73 using typename Superclass::TotalAbsoluteFrequencyType;
74 using typename Superclass::InstanceIdentifier;
75
79
81 using InternalDataContainerType = std::vector<MeasurementVectorType>;
82
90 void
92
94 void
96
98 void
100
103 Size() const override;
104
108 GetMeasurementVector(InstanceIdentifier instanceId) const override;
109
111 void
112 SetMeasurement(InstanceIdentifier instanceId, unsigned int dim, const MeasurementType & value);
113
115 void
117
121 GetFrequency(InstanceIdentifier instanceId) const override;
122
126 GetTotalFrequency() const override;
127
129 void
130 Graft(const DataObject * thatObject) override;
131
137 {
138 friend class ListSample;
139
140 public:
141 ConstIterator(const ListSample * sample) { *this = sample->Begin(); }
142
144 {
145 m_Iter = iter.m_Iter;
146 m_InstanceIdentifier = iter.m_InstanceIdentifier;
147 }
148
149 ConstIterator() = delete;
150
153 {
154 m_Iter = iter.m_Iter;
155 m_InstanceIdentifier = iter.m_InstanceIdentifier;
156 return *this;
157 }
158
161 {
162 return 1;
163 }
164
167 {
168 return static_cast<const MeasurementVectorType &>(*m_Iter);
169 }
170
173 {
174 return m_InstanceIdentifier;
175 }
176
179 {
180 ++m_Iter;
181 ++m_InstanceIdentifier;
182 return *this;
183 }
184
185 bool
186 operator==(const ConstIterator & it) const
187 {
188 return (m_Iter == it.m_Iter);
189 }
190
192
193 protected:
194 // This method should only be available to the ListSample class
195 ConstIterator(typename InternalDataContainerType::const_iterator iter, InstanceIdentifier iid)
196 {
197 m_Iter = iter;
198 m_InstanceIdentifier = iid;
199 }
200
201 private:
202 using InternalIterator = typename InternalDataContainerType::const_iterator;
205 };
206
211 class Iterator : public ConstIterator
212 {
213 friend class ListSample;
214
215 public:
216 Iterator() = delete;
217 Iterator(const Self * sample) = delete;
218 Iterator(typename InternalDataContainerType::const_iterator iter, InstanceIdentifier iid) = delete;
219 Iterator(const ConstIterator & it) = delete;
221 operator=(const ConstIterator & it) = delete;
222
223 Iterator(Self * sample)
224 : ConstIterator(sample)
225 {}
226
227 Iterator(const Iterator & iter)
228 : ConstIterator(iter)
229 {}
230
231 Iterator &
232 operator=(const Iterator & iter)
233 {
234 this->ConstIterator::operator=(iter);
235 return *this;
236 }
237
238 protected:
239 Iterator(typename InternalDataContainerType::iterator iter, InstanceIdentifier iid)
240 : ConstIterator(iter, iid)
241 {}
242 };
243
245 Iterator
247 {
248 Iterator iter(m_InternalContainer.begin(), 0);
249
250 return iter;
251 }
252
254 Iterator
256 {
257 Iterator iter(m_InternalContainer.end(), static_cast<InstanceIdentifier>(m_InternalContainer.size()));
258
259 return iter;
260 }
261
263 ConstIterator
264 Begin() const
265 {
266 ConstIterator iter(m_InternalContainer.begin(), 0);
267
268 return iter;
269 }
270
272 ConstIterator
273 End() const
274 {
275 ConstIterator iter(m_InternalContainer.end(), static_cast<InstanceIdentifier>(m_InternalContainer.size()));
276
277 return iter;
278 }
279
280protected:
281 ListSample() = default;
282 ~ListSample() override = default;
283 void
284 PrintSelf(std::ostream & os, Indent indent) const override;
285
286private:
287 InternalDataContainerType m_InternalContainer{};
288};
289} // end of namespace Statistics
290} // end of namespace itk
291
292#ifndef ITK_MANUAL_INSTANTIATION
293# include "itkListSample.hxx"
294#endif
295
296#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
typename InternalDataContainerType::const_iterator InternalIterator
InstanceIdentifier GetInstanceIdentifier() const
AbsoluteFrequencyType GetFrequency() const
ConstIterator(typename InternalDataContainerType::const_iterator iter, InstanceIdentifier iid)
ConstIterator(const ConstIterator &iter)
bool operator==(const ConstIterator &it) const
ConstIterator(const ListSample *sample)
ConstIterator & operator=(const ConstIterator &iter)
const MeasurementVectorType & GetMeasurementVector() const
ConstIterator & operator=(const ConstIterator &it)=delete
Iterator & operator=(const Iterator &iter)
Iterator(typename InternalDataContainerType::const_iterator iter, InstanceIdentifier iid)=delete
Iterator(const Self *sample)=delete
Iterator(typename InternalDataContainerType::iterator iter, InstanceIdentifier iid)
Iterator(const ConstIterator &it)=delete
This class is the native implementation of the a Sample with an STL container.
Definition: itkListSample.h:52
void PushBack(const MeasurementVectorType &mv)
ConstIterator End() const
~ListSample() override=default
void SetMeasurement(InstanceIdentifier instanceId, unsigned int dim, const MeasurementType &value)
ConstIterator Begin() const
MeasurementVectorType ValueType
Definition: itkListSample.h:78
std::vector< MeasurementVectorType > InternalDataContainerType
Definition: itkListSample.h:81
void PrintSelf(std::ostream &os, Indent indent) const override
TotalAbsoluteFrequencyType GetTotalFrequency() const override
InstanceIdentifier Size() const override
void SetMeasurementVector(InstanceIdentifier instanceId, const MeasurementVectorType &mv)
void Graft(const DataObject *thatObject) override
const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier instanceId) const override
AbsoluteFrequencyType GetFrequency(InstanceIdentifier instanceId) const override
void Resize(InstanceIdentifier newsize)
A collection of measurements for statistical analysis.
Definition: itkSample.h:63
TMeasurementVector MeasurementVectorType
Definition: itkSample.h:77
typename MeasurementVectorTraitsTypes< MeasurementVectorType >::ValueType MeasurementType
Definition: itkSample.h:81
typename MeasurementVectorTraits::InstanceIdentifier InstanceIdentifier
Definition: itkSample.h:91
NumericTraits< AbsoluteFrequencyType >::AccumulateType TotalAbsoluteFrequencyType
Definition: itkSample.h:87
MeasurementVectorTraits::AbsoluteFrequencyType AbsoluteFrequencyType
Definition: itkSample.h:84
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....