ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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{
60
61template <typename TMeasurementVector>
62class Sample : public DataObject
63{
64public:
65 ITK_DISALLOW_COPY_AND_MOVE(Sample);
66
68 using Self = Sample;
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
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 }
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 else
143 {
144 // If this is a non-resizable vector type
146 // and the new length is different from the default one, then throw an
147 // exception
148 if (defaultLength != s)
149 {
150 itkExceptionMacro("Attempting to change the measurement vector size of a non-resizable vector type");
151 }
152 }
153 }
154
156 itkGetConstMacro(MeasurementVectorSize, MeasurementVectorSizeType);
157
159 void
160 Graft(const DataObject * thatObject) override
161 {
162 this->Superclass::Graft(thatObject);
163
164 const auto * thatConst = dynamic_cast<const Self *>(thatObject);
165 if (thatConst)
166 {
167 this->SetMeasurementVectorSize(thatConst->GetMeasurementVectorSize());
168 }
169 }
170
171protected:
173
174 ~Sample() override = default;
175
176 void
177 PrintSelf(std::ostream & os, Indent indent) const override
178 {
179 Superclass::PrintSelf(os, indent);
180 os << indent << "Length of measurement vectors in the sample: " << m_MeasurementVectorSize << std::endl;
181 }
182
183private:
185}; // end of class
186} // end of namespace Statistics
187} // end of namespace itk
188
189#endif
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()
virtual void Modified() const
Implements transparent reference counting.
Sample< typename MeasurementVectorPixelTraits< typename TImage::PixelType >::MeasurementVectorType > Superclass
typename TMeasurementVector::ValueType ValueType
virtual void SetMeasurementVectorSize(MeasurementVectorSizeType s)
Definition itkSample.h:116
virtual InstanceIdentifier Size() const =0
SmartPointer< const Self > ConstPointer
Definition itkSample.h:71
void PrintSelf(std::ostream &os, Indent indent) const override
Definition itkSample.h:177
typename MeasurementVectorTraitsTypes< MeasurementVectorType >::ValueType MeasurementType
Definition itkSample.h:81
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:160
NumericTraits< AbsoluteFrequencyType >::AccumulateType TotalAbsoluteFrequencyType
Definition itkSample.h:87
virtual TotalAbsoluteFrequencyType GetTotalFrequency() const =0
MeasurementVectorSizeType m_MeasurementVectorSize
Definition itkSample.h:184
~Sample() override=default
MeasurementVectorTraits::AbsoluteFrequencyType AbsoluteFrequencyType
Definition itkSample.h:84
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....