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
25{
26namespace Statistics
27{
55
56template <typename TSample>
57class ITK_TEMPLATE_EXPORT MembershipSample : public DataObject
58{
59public:
60 ITK_DISALLOW_COPY_AND_MOVE(MembershipSample);
61
67
69 itkOverrideGetNameOfClassMacro(MembershipSample);
70 itkNewMacro(Self);
72
75 using SampleType = TSample;
76 using MeasurementVectorType = typename SampleType::MeasurementVectorType;
77 using MeasurementType = typename SampleType::MeasurementType;
78 using InstanceIdentifier = typename SampleType::InstanceIdentifier;
79 using SampleConstPointer = typename SampleType::ConstPointer;
80
81 using AbsoluteFrequencyType = typename SampleType::AbsoluteFrequencyType;
82 using TotalAbsoluteFrequencyType = typename SampleType::TotalAbsoluteFrequencyType;
83
87 using UniqueClassLabelsType = std::vector<ClassLabelType>;
88
91 using ClassLabelHolderType = std::unordered_map<InstanceIdentifier, ClassLabelType>;
92
98
100 itkSetConstObjectMacro(Sample, SampleType);
101 itkGetConstObjectMacro(Sample, SampleType);
103
105 void
106 SetNumberOfClasses(unsigned int numberOfClasses);
107
109 itkGetConstMacro(NumberOfClasses, unsigned int);
110
115 void
116 AddInstance(const ClassLabelType & classLabel, const InstanceIdentifier & id);
117
120 unsigned int
122
125 const ClassSampleType *
126 GetClassSample(const ClassLabelType & classLabel) const;
127
132
137
141 GetMeasurement(const InstanceIdentifier & id, const unsigned int dimension);
142
146
150
152 void
153 Graft(const DataObject * thatObject) override;
154
155 // void PrintSelf(std::ostream& os, Indent indent) const;
156
158 {
159 friend class MembershipSample;
160
161 public:
162 ConstIterator(const Self * sample) { *this = sample->Begin(); }
163
170
173 {
174 m_Sample = iter.m_Sample;
177 return *this;
178 }
179
180 bool
181 operator==(const ConstIterator & it) const
182 {
184 }
185
187
190 {
192 return *this;
193 }
194
197 {
198 return m_Sample->GetFrequency(m_InstanceIdentifier);
199 }
200
203 {
204 return m_Sample->GetMeasurementVector(m_InstanceIdentifier);
205 }
206
209 {
211 }
212
213 unsigned int
215 {
216 return m_MembershipSample->GetClassLabel(m_InstanceIdentifier);
217 }
218
219 protected:
220 // Purposely not implemented
222
223 // Only to be called from the MembershipSample
224 ConstIterator(const Self * memberSample, InstanceIdentifier iid)
225 : m_Sample(memberSample->GetSample())
226 , m_MembershipSample(memberSample)
228 {}
229
230 // typename SampleType::ConstIterator m_Iter;
231 const TSample * m_Sample;
234 };
235
236 class Iterator : public ConstIterator
237 {
238 friend class MembershipSample;
239
240 public:
241 Iterator(Self * sample)
242 : ConstIterator(sample)
243 {}
244
245 Iterator(const Iterator & iter)
246 : ConstIterator(iter)
247 {}
248
249 Iterator &
250 operator=(const Iterator & iter)
251 {
252 this->ConstIterator::operator=(iter);
253 return *this;
254 }
255
256 protected:
257 // To ensure const-correctness these method must not be in the public API.
258 // The are purposely not implemented, since they should never be called.
260 Iterator(const Self * sample);
264
265 // Only to be called from the MembershipSample
266 Iterator(Self * memberSample, InstanceIdentifier iid)
267 : ConstIterator(memberSample, iid)
268 {}
269
270 private:
271 };
272
275 Iterator
277 {
278 const Iterator iter(this, 0);
279
280 return iter;
281 }
282
285 Iterator
287 {
288 const Iterator iter(this, m_Sample->Size());
289
290 return iter;
291 }
292
293 ConstIterator
294 Begin() const
295 {
296 const ConstIterator iter(this, 0);
297
298 return iter;
299 }
300
301 ConstIterator
302 End() const
303 {
304 const ConstIterator iter(this, m_Sample->Size());
305
306 return iter;
307 }
308
309protected:
311 ~MembershipSample() override = default;
312 void
313 PrintSelf(std::ostream & os, Indent indent) const override;
314
315private:
318 int
319 GetInternalClassLabel(const ClassLabelType classLabel) const;
320
323 std::vector<ClassSamplePointer> m_ClassSamples{};
325 unsigned int m_NumberOfClasses{};
326}; // end of class
327} // end of namespace Statistics
328} // end of namespace itk
329
330#ifndef ITK_MANUAL_INSTANTIATION
331# include "itkMembershipSample.hxx"
332#endif
333
334#endif
Control indentation during Print() invocation.
Definition itkIndent.h:50
Implements transparent reference counting.
bool operator==(const ConstIterator &it) const
ConstIterator & operator=(const ConstIterator &iter)
const MeasurementVectorType & GetMeasurementVector() const
ConstIterator(const Self *memberSample, InstanceIdentifier iid)
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:63
This class stores a subset of instance identifiers from another sample object. You can create a subsa...
SmartPointer< const Self > ConstPointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
SizeValueType IdentifierType
Definition itkIntTypes.h:90