ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkMembershipSample.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 itkMembershipSample_h
19#define itkMembershipSample_h
20
21#include <unordered_map>
22#include "itkSubsample.h"
23
24namespace itk::Statistics
25{
53
54template <typename TSample>
55class ITK_TEMPLATE_EXPORT MembershipSample : public DataObject
56{
57public:
58 ITK_DISALLOW_COPY_AND_MOVE(MembershipSample);
59
65
68 itkOverrideGetNameOfClassMacro(MembershipSample);
69 itkNewMacro(Self);
73 using SampleType = TSample;
74 using MeasurementVectorType = typename SampleType::MeasurementVectorType;
75 using MeasurementType = typename SampleType::MeasurementType;
76 using InstanceIdentifier = typename SampleType::InstanceIdentifier;
77 using SampleConstPointer = typename SampleType::ConstPointer;
78
79 using AbsoluteFrequencyType = typename SampleType::AbsoluteFrequencyType;
80 using TotalAbsoluteFrequencyType = typename SampleType::TotalAbsoluteFrequencyType;
81
85 using UniqueClassLabelsType = std::vector<ClassLabelType>;
86
89 using ClassLabelHolderType = std::unordered_map<InstanceIdentifier, ClassLabelType>;
90
96
99 itkSetConstObjectMacro(Sample, SampleType);
100 itkGetConstObjectMacro(Sample, SampleType);
103 void
104 SetNumberOfClasses(unsigned int numberOfClasses);
105
107 itkGetConstMacro(NumberOfClasses, unsigned int);
108
113 void
114 AddInstance(const ClassLabelType & classLabel, const InstanceIdentifier & id);
115
118 unsigned int
120
123 const ClassSampleType *
124 GetClassSample(const ClassLabelType & classLabel) const;
125
130
135
139 GetMeasurement(const InstanceIdentifier & id, const unsigned int dimension);
140
144
148
150 void
151 Graft(const DataObject * thatObject) override;
152
153 // void PrintSelf(std::ostream& os, Indent indent) const;
154
156 {
157 friend class MembershipSample;
158
159 public:
160 ConstIterator(const Self * sample) { *this = sample->Begin(); }
161
167
169 operator=(const ConstIterator & iter) = default;
170
171 bool
172 operator==(const ConstIterator & it) const
173 {
175 }
176
178
181 {
183 return *this;
184 }
185
186 [[nodiscard]] AbsoluteFrequencyType
188 {
189 return m_Sample->GetFrequency(m_InstanceIdentifier);
190 }
191
192 [[nodiscard]] const MeasurementVectorType &
194 {
195 return m_Sample->GetMeasurementVector(m_InstanceIdentifier);
196 }
197
198 [[nodiscard]] InstanceIdentifier
200 {
202 }
203
204 [[nodiscard]] unsigned int
206 {
207 return m_MembershipSample->GetClassLabel(m_InstanceIdentifier);
208 }
209
210 protected:
211 // Purposely not implemented
213
214 // Only to be called from the MembershipSample
215 ConstIterator(const Self * memberSample, InstanceIdentifier iid)
216 : m_Sample(memberSample->GetSample())
217 , m_MembershipSample(memberSample)
219 {}
220
221 // typename SampleType::ConstIterator m_Iter;
222 const TSample * m_Sample;
225 };
226
227 class Iterator : public ConstIterator
228 {
229 friend class MembershipSample;
230
231 public:
232 Iterator(Self * sample)
233 : ConstIterator(sample)
234 {}
235
236 Iterator(const Iterator & iter)
237 : ConstIterator(iter)
238 {}
239
240 Iterator &
241 operator=(const Iterator & iter)
242 {
243 this->ConstIterator::operator=(iter);
244 return *this;
245 }
246
247 protected:
248 // To ensure const-correctness these method must not be in the public API.
249 // The are purposely not implemented, since they should never be called.
251 Iterator(const Self * sample);
255
256 // Only to be called from the MembershipSample
257 Iterator(Self * memberSample, InstanceIdentifier iid)
258 : ConstIterator(memberSample, iid)
259 {}
260
261 private:
262 };
263
266 Iterator
268 {
269 const Iterator iter(this, 0);
270
271 return iter;
272 }
273
276 Iterator
278 {
279 const Iterator iter(this, m_Sample->Size());
280
281 return iter;
282 }
283
284 ConstIterator
285 Begin() const
286 {
287 const ConstIterator iter(this, 0);
288
289 return iter;
290 }
291
292 ConstIterator
293 End() const
294 {
295 const ConstIterator iter(this, m_Sample->Size());
296
297 return iter;
298 }
299
300protected:
302 ~MembershipSample() override = default;
303 void
304 PrintSelf(std::ostream & os, Indent indent) const override;
305
306private:
309 int
310 GetInternalClassLabel(const ClassLabelType classLabel) const;
311
314 std::vector<ClassSamplePointer> m_ClassSamples{};
316 unsigned int m_NumberOfClasses{};
317}; // end of class
318} // namespace itk::Statistics
319
320#ifndef ITK_MANUAL_INSTANTIATION
321# include "itkMembershipSample.hxx"
322#endif
323
324#endif
Control indentation during Print() invocation.
Definition itkIndent.h:50
Implements transparent reference counting.
bool operator==(const ConstIterator &it) const
const MeasurementVectorType & GetMeasurementVector() const
ConstIterator(const Self *memberSample, InstanceIdentifier iid)
ConstIterator & operator=(const ConstIterator &iter)=default
ConstIterator & operator=(const ConstIterator &it)
Iterator & operator=(const Iterator &iter)
Iterator(Self *memberSample, InstanceIdentifier iid)
std::vector< ClassSamplePointer > m_ClassSamples
typename SampleType::ConstPointer SampleConstPointer
typename ClassSampleType::Pointer ClassSamplePointer
TotalAbsoluteFrequencyType GetTotalFrequency() const
typename SampleType::MeasurementType MeasurementType
const MeasurementVectorType & GetMeasurementVector(const InstanceIdentifier &id) const
~MembershipSample() override=default
void Graft(const DataObject *thatObject) override
unsigned int GetClassLabel(const InstanceIdentifier &id) const
typename SampleType::TotalAbsoluteFrequencyType TotalAbsoluteFrequencyType
const ClassSampleType * GetClassSample(const ClassLabelType &classLabel) const
typename SampleType::AbsoluteFrequencyType AbsoluteFrequencyType
std::vector< ClassLabelType > UniqueClassLabelsType
Subsample< SampleType > ClassSampleType
typename ClassSampleType::ConstPointer ClassSampleConstPointer
typename SampleType::MeasurementVectorType MeasurementVectorType
virtual const SampleType * GetSample() const
std::unordered_map< InstanceIdentifier, ClassLabelType > ClassLabelHolderType
typename SampleType::InstanceIdentifier InstanceIdentifier
SmartPointer< const Self > ConstPointer
void PrintSelf(std::ostream &os, Indent indent) const override
void SetNumberOfClasses(unsigned int numberOfClasses)
const ClassLabelHolderType GetClassLabelHolder() const
MeasurementType GetMeasurement(const InstanceIdentifier &id, const unsigned int dimension)
void AddInstance(const ClassLabelType &classLabel, const InstanceIdentifier &id)
int GetInternalClassLabel(const ClassLabelType classLabel) const
AbsoluteFrequencyType GetFrequency(const InstanceIdentifier &id) const
A collection of measurements for statistical analysis.
Definition itkSample.h:61
This class stores a subset of instance identifiers from another sample object. You can create a subsa...
SmartPointer< const Self > ConstPointer
SizeValueType IdentifierType
Definition itkIntTypes.h:90