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::Statistics
27{
58
59template <typename TMeasurementVector>
60class Sample : public DataObject
61{
62public:
63 ITK_DISALLOW_COPY_AND_MOVE(Sample);
64
66 using Self = Sample;
72 itkOverrideGetNameOfClassMacro(Sample);
73
75 using MeasurementVectorType = TMeasurementVector;
76
80
83
86
90
92 using MeasurementVectorSizeType = unsigned int;
93
95 virtual InstanceIdentifier
96 Size() const = 0;
97
100 virtual const MeasurementVectorType &
102
107
110 GetTotalFrequency() const = 0;
111
113 virtual void
115 {
116 // Test whether the vector type is resizable or not
118 {
119 // then this is a resizable vector type
120 //
121 // if the new size is the same as the previous size, just return
122 if (s == this->m_MeasurementVectorSize)
123 {
124 return;
125 }
126
127 // If the new size is different from the current size, then
128 // only change the measurement vector size if the container is empty.
129 if (this->Size())
130 {
131 itkExceptionMacro("Attempting to change the measurement vector size of a non-empty Sample");
132 }
133 else
134 {
135 this->m_MeasurementVectorSize = s;
136 this->Modified();
137 }
138 }
139 else
140 {
141 // If this is a non-resizable vector type
143 // and the new length is different from the default one, then throw an
144 // exception
145 if (defaultLength != s)
146 {
147 itkExceptionMacro("Attempting to change the measurement vector size of a non-resizable vector type");
148 }
149 }
150 }
151
153 itkGetConstMacro(MeasurementVectorSize, MeasurementVectorSizeType);
154
156 void
157 Graft(const DataObject * thatObject) override
158 {
159 this->Superclass::Graft(thatObject);
160
161 const auto * thatConst = dynamic_cast<const Self *>(thatObject);
162 if (thatConst)
163 {
164 this->SetMeasurementVectorSize(thatConst->GetMeasurementVectorSize());
165 }
166 }
167
168protected:
172
173 ~Sample() override = default;
174
175 void
176 PrintSelf(std::ostream & os, Indent indent) const override
177 {
178 Superclass::PrintSelf(os, indent);
179 os << indent << "Length of measurement vectors in the sample: " << m_MeasurementVectorSize << std::endl;
180 }
181
182private:
184}; // end of class
185} // namespace itk::Statistics
186
187#endif
virtual void Graft(const DataObject *)
void PrintSelf(std::ostream &os, Indent indent) const override
Control indentation during Print() invocation.
Definition itkIndent.h:50
Define additional traits for native types such as int or float.
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:114
virtual InstanceIdentifier Size() const =0
SmartPointer< const Self > ConstPointer
Definition itkSample.h:69
void PrintSelf(std::ostream &os, Indent indent) const override
Definition itkSample.h:176
typename MeasurementVectorTraitsTypes< MeasurementVectorType >::ValueType MeasurementType
Definition itkSample.h:79
virtual const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier id) const =0
typename MeasurementVectorTraits::InstanceIdentifier InstanceIdentifier
Definition itkSample.h:89
virtual AbsoluteFrequencyType GetFrequency(InstanceIdentifier id) const =0
void Graft(const DataObject *thatObject) override
Definition itkSample.h:157
NumericTraits< AbsoluteFrequencyType >::AccumulateType TotalAbsoluteFrequencyType
Definition itkSample.h:85
virtual TotalAbsoluteFrequencyType GetTotalFrequency() const =0
MeasurementVectorSizeType m_MeasurementVectorSize
Definition itkSample.h:183
~Sample() override=default
MeasurementVectorTraits::AbsoluteFrequencyType AbsoluteFrequencyType
Definition itkSample.h:82