ITK  6.0.0
Insight Toolkit
itkSample.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 itkSample_h
19#define itkSample_h
20
21#include "itkPoint.h"
22#include "itkDataObject.h"
24#include <vector> // for the size_type declaration
25
26namespace itk
27{
28namespace Statistics
29{
61template <typename TMeasurementVector>
62class Sample : public DataObject
63{
64public:
65 ITK_DISALLOW_COPY_AND_MOVE(Sample);
66
68 using Self = Sample;
72
74 itkOverrideGetNameOfClassMacro(Sample);
75
77 using MeasurementVectorType = TMeasurementVector;
78
82
85
88
92
94 using MeasurementVectorSizeType = unsigned int;
95
97 virtual InstanceIdentifier
98 Size() const = 0;
99
102 virtual const MeasurementVectorType &
104
109
112 GetTotalFrequency() const = 0;
113
115 virtual void
117 {
118 // Test whether the vector type is resizable or not
119 if (MeasurementVectorTraits::IsResizable<MeasurementVectorType>({}))
120 {
121 // then this is a resizable vector type
122 //
123 // if the new size is the same as the previous size, just return
124 if (s == this->m_MeasurementVectorSize)
125 {
126 return;
127 }
128 else
129 {
130 // If the new size is different from the current size, then
131 // only change the measurement vector size if the container is empty.
132 if (this->Size())
133 {
134 itkExceptionMacro("Attempting to change the measurement vector size of a non-empty Sample");
135 }
136 else
137 {
138 this->m_MeasurementVectorSize = s;
139 this->Modified();
140 }
141 }
142 }
143 else
144 {
145 // If this is a non-resizable vector type
147 // and the new length is different from the default one, then throw an
148 // exception
149 if (defaultLength != s)
150 {
151 itkExceptionMacro("Attempting to change the measurement vector size of a non-resizable vector type");
152 }
153 }
154 }
158 itkGetConstMacro(MeasurementVectorSize, MeasurementVectorSizeType);
159
161 void
162 Graft(const DataObject * thatObject) override
163 {
164 this->Superclass::Graft(thatObject);
165
166 const auto * thatConst = dynamic_cast<const Self *>(thatObject);
167 if (thatConst)
168 {
169 this->SetMeasurementVectorSize(thatConst->GetMeasurementVectorSize());
170 }
171 }
172
173protected:
175
176 ~Sample() override = default;
177
178 void
179 PrintSelf(std::ostream & os, Indent indent) const override
180 {
181 Superclass::PrintSelf(os, indent);
182 os << indent << "Length of measurement vectors in the sample: " << m_MeasurementVectorSize << std::endl;
183 }
184
185private:
187}; // end of class
188} // end of namespace Statistics
189} // end of namespace itk
190
191#endif
Base class for all data objects in ITK.
virtual void Graft(const DataObject *)
void PrintSelf(std::ostream &os, Indent indent) const override
Control indentation during Print() invocation.
Definition: itkIndent.h:50
static unsigned int GetLength()
Base class for most ITK classes.
Definition: itkObject.h:62
virtual void Modified() const
typename TMeasurementVector::ValueType ValueType
A collection of measurements for statistical analysis.
Definition: itkSample.h:63
virtual void SetMeasurementVectorSize(MeasurementVectorSizeType s)
Definition: itkSample.h:116
virtual InstanceIdentifier Size() const =0
void PrintSelf(std::ostream &os, Indent indent) const override
Definition: itkSample.h:179
TMeasurementVector MeasurementVectorType
Definition: itkSample.h:77
typename MeasurementVectorTraitsTypes< MeasurementVectorType >::ValueType MeasurementType
Definition: itkSample.h:81
unsigned int MeasurementVectorSizeType
Definition: itkSample.h:94
virtual const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier id) const =0
typename MeasurementVectorTraits::InstanceIdentifier InstanceIdentifier
Definition: itkSample.h:91
virtual AbsoluteFrequencyType GetFrequency(InstanceIdentifier id) const =0
void Graft(const DataObject *thatObject) override
Definition: itkSample.h:162
NumericTraits< AbsoluteFrequencyType >::AccumulateType TotalAbsoluteFrequencyType
Definition: itkSample.h:87
virtual TotalAbsoluteFrequencyType GetTotalFrequency() const =0
MeasurementVectorSizeType m_MeasurementVectorSize
Definition: itkSample.h:186
~Sample() override=default
MeasurementVectorTraits::AbsoluteFrequencyType AbsoluteFrequencyType
Definition: itkSample.h:84
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....