ITK  5.4.0
Insight Toolkit
itkDistanceMetric.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 itkDistanceMetric_h
19#define itkDistanceMetric_h
20
21#include "itkFunctionBase.h"
23
24namespace itk
25{
26namespace Statistics
27{
47template <typename TVector>
48class ITK_TEMPLATE_EXPORT DistanceMetric : public FunctionBase<TVector, double>
49{
50public:
56
58 using MeasurementVectorType = TVector;
59
64 using MeasurementVectorSizeType = unsigned int;
65
67 itkOverrideGetNameOfClassMacro(DistanceMetric);
68
70
77 void
79
80 itkGetConstReferenceMacro(Origin, OriginType);
81
84 double
85 Evaluate(const MeasurementVectorType & x) const override = 0;
86
92 virtual double
93 Evaluate(const MeasurementVectorType & x1, const MeasurementVectorType & x2) const = 0;
94
96 virtual void
98 {
99 // Test whether the vector type is resizable or not
100 if (MeasurementVectorTraits::IsResizable<MeasurementVectorType>({}))
101 {
102 // then this is a resizable vector type
103 //
104 // if the new size is the same as the previous size, just return
105 if (s == this->m_MeasurementVectorSize)
106 {
107 return;
108 }
109 else
110 {
111 this->m_MeasurementVectorSize = s;
112 this->Modified();
113 }
114 }
115 else
116 {
117 // If this is a non-resizable vector type
119 // and the new length is different from the default one, then throw an
120 // exception
121 if (defaultLength != s)
122 {
123 itkExceptionMacro("Attempting to change the measurement vector size of a non-resizable vector type");
124 }
125 }
126 }
130 itkGetConstMacro(MeasurementVectorSize, MeasurementVectorSizeType);
131
132protected:
134 ~DistanceMetric() override = default;
135 void
136 PrintSelf(std::ostream & os, Indent indent) const override;
137
138private:
139 OriginType m_Origin{};
140
142 MeasurementVectorSizeType m_MeasurementVectorSize{};
143}; // end of class
144} // end of namespace Statistics
145} // end of namespace itk
146
147#ifndef ITK_MANUAL_INSTANTIATION
148# include "itkDistanceMetric.hxx"
149#endif
150
151#endif
Base class for all ITK function objects.
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
static unsigned int GetLength()
this class declares common interfaces for distance functions.
virtual double Evaluate(const MeasurementVectorType &x1, const MeasurementVectorType &x2) const =0
void SetOrigin(const OriginType &x)
~DistanceMetric() override=default
virtual void SetMeasurementVectorSize(MeasurementVectorSizeType s)
double Evaluate(const MeasurementVectorType &x) const override=0
void PrintSelf(std::ostream &os, Indent indent) const override
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....