ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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::Statistics
28{
47
48template <typename TMeasurementVector>
49class ITK_TEMPLATE_EXPORT ListSample : public Sample<TMeasurementVector>
50{
51public:
52 ITK_DISALLOW_COPY_AND_MOVE(ListSample);
53
59
61 itkOverrideGetNameOfClassMacro(ListSample);
62
64 itkNewMacro(Self);
65
69 using typename Superclass::MeasurementType;
72 using typename Superclass::InstanceIdentifier;
73
77
79 using InternalDataContainerType = std::vector<MeasurementVectorType>;
80
88 void
90
92 void
94
96 void
98
101 Size() const override;
102
106 GetMeasurementVector(InstanceIdentifier instanceId) const override;
107
109 void
110 SetMeasurement(InstanceIdentifier instanceId, unsigned int dim, const MeasurementType & value);
111
113 void
115
119 GetFrequency(InstanceIdentifier instanceId) const override;
120
124 GetTotalFrequency() const override;
125
127 void
128 Graft(const DataObject * thatObject) override;
129
135 {
136 friend class ListSample;
137
138 public:
139 ConstIterator(const ListSample * sample) { *this = sample->Begin(); }
140
145
146 ConstIterator() = delete;
147
149 operator=(const ConstIterator & iter) = default;
150
151 [[nodiscard]] AbsoluteFrequencyType
153 {
154 return 1;
155 }
156
157 [[nodiscard]] const MeasurementVectorType &
159 {
160 return static_cast<const MeasurementVectorType &>(*m_Iter);
161 }
162
163 [[nodiscard]] InstanceIdentifier
165 {
167 }
168
171 {
172 ++m_Iter;
174 return *this;
175 }
176
177 bool
178 operator==(const ConstIterator & it) const
179 {
180 return (m_Iter == it.m_Iter);
181 }
182
184
185 protected:
186 // This method should only be available to the ListSample class
187 ConstIterator(typename InternalDataContainerType::const_iterator iter, InstanceIdentifier iid)
188 : m_Iter(iter)
190 {}
191
192 private:
193 using InternalIterator = typename InternalDataContainerType::const_iterator;
196 };
197
202 class Iterator : public ConstIterator
203 {
204 friend class ListSample;
205
206 public:
207 Iterator() = delete;
208 Iterator(const Self * sample) = delete;
209 Iterator(typename InternalDataContainerType::const_iterator iter, InstanceIdentifier iid) = delete;
210 Iterator(const ConstIterator & it) = delete;
212 operator=(const ConstIterator & it) = delete;
213
214 Iterator(Self * sample)
215 : ConstIterator(sample)
216 {}
217
218 Iterator(const Iterator & iter)
219 : ConstIterator(iter)
220 {}
221
222 Iterator &
223 operator=(const Iterator & iter)
224 {
225 this->ConstIterator::operator=(iter);
226 return *this;
227 }
228
229 protected:
230 Iterator(typename InternalDataContainerType::iterator iter, InstanceIdentifier iid)
231 : ConstIterator(iter, iid)
232 {}
233 };
234
236 Iterator
238 {
239 const Iterator iter(m_InternalContainer.begin(), 0);
240
241 return iter;
242 }
243
245 Iterator
247 {
248 const Iterator iter(m_InternalContainer.end(), static_cast<InstanceIdentifier>(m_InternalContainer.size()));
249
250 return iter;
251 }
252
254 ConstIterator
255 Begin() const
256 {
257 const ConstIterator iter(m_InternalContainer.begin(), 0);
258
259 return iter;
260 }
261
263 ConstIterator
264 End() const
265 {
266 const ConstIterator iter(m_InternalContainer.end(), static_cast<InstanceIdentifier>(m_InternalContainer.size()));
267
268 return iter;
269 }
270
271protected:
272 ListSample() = default;
273 ~ListSample() override = default;
274 void
275 PrintSelf(std::ostream & os, Indent indent) const override;
276
277private:
279};
280} // namespace itk::Statistics
281
282#ifndef ITK_MANUAL_INSTANTIATION
283# include "itkListSample.hxx"
284#endif
285
286#endif
Control indentation during Print() invocation.
Definition itkIndent.h:50
Implements transparent reference counting.
typename InternalDataContainerType::const_iterator InternalIterator
InstanceIdentifier GetInstanceIdentifier() const
AbsoluteFrequencyType GetFrequency() const
ConstIterator(typename InternalDataContainerType::const_iterator iter, InstanceIdentifier iid)
ConstIterator & operator=(const ConstIterator &iter)=default
ConstIterator(const ConstIterator &iter)
bool operator==(const ConstIterator &it) const
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
void PushBack(const MeasurementVectorType &mv)
ConstIterator End() const
~ListSample() override=default
void SetMeasurement(InstanceIdentifier instanceId, unsigned int dim, const MeasurementType &value)
ConstIterator Begin() const
typename MeasurementVectorPixelTraits< typename TImage::PixelType >::MeasurementVectorType MeasurementVectorType
Sample< typename MeasurementVectorPixelTraits< typename TImage::PixelType >::MeasurementVectorType > Superclass
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)
TMeasurementVector MeasurementVectorType
Definition itkSample.h:75
typename MeasurementVectorTraitsTypes< MeasurementVectorType >::ValueType MeasurementType
Definition itkSample.h:79
unsigned int MeasurementVectorSizeType
Definition itkSample.h:92
typename MeasurementVectorTraits::InstanceIdentifier InstanceIdentifier
Definition itkSample.h:89
NumericTraits< AbsoluteFrequencyType >::AccumulateType TotalAbsoluteFrequencyType
Definition itkSample.h:85
MeasurementVectorTraits::AbsoluteFrequencyType AbsoluteFrequencyType
Definition itkSample.h:82