OTB  9.0.0
Orfeo Toolbox
otbEuclideanDistanceMetricWithMissingValuePow2.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
3  * Copyright (C) 2007-2012 Institut Mines Telecom / Telecom Bretagne
4  *
5  * This file is part of Orfeo Toolbox
6  *
7  * https://www.orfeo-toolbox.org/
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 
23 #ifndef otbEuclideanDistanceMetricWithMissingValuePow2_hxx
24 #define otbEuclideanDistanceMetricWithMissingValuePow2_hxx
25 
27 #include "itkMeasurementVectorTraits.h"
28 
29 namespace otb
30 {
31 
32 namespace Statistics
33 {
34 
35 template <class TVector>
36 inline double EuclideanDistanceMetricWithMissingValuePow2<TVector>::Evaluate(const TVector& x1, const TVector& x2) const
37 {
38  if (itk::NumericTraits<TVector>::GetLength(x1) != itk::NumericTraits<TVector>::GetLength(x2))
39  {
40  itkExceptionMacro(<< "Vector lengths must be equal.");
41  }
42 
43  double temp, distance = itk::NumericTraits<double>::Zero;
44 
45  for (unsigned int i = 0; i < x1.Size(); ++i)
46  {
47  if (!IsMissingValue(x1[i]) && !IsMissingValue(x2[i]))
48  {
49  temp = x1[i] - x2[i];
50  distance += temp * temp;
51  }
52  }
53 
54  return distance;
55 }
56 
57 template <class TVector>
59 {
60  MeasurementVectorSizeType measurementVectorSize = this->GetMeasurementVectorSize();
61  if (measurementVectorSize == 0)
62  {
63  itkExceptionMacro(<< "Please set the MeasurementVectorSize first");
64  }
65  itk::Statistics::MeasurementVectorTraits::Assert(this->GetOrigin(), measurementVectorSize,
66  "EuclideanDistanceMetric::Evaluate Origin and input vector have different lengths");
67 
68  double temp, distance = itk::NumericTraits<double>::Zero;
69 
70  for (unsigned int i = 0; i < measurementVectorSize; ++i)
71  {
72  if (!IsMissingValue(this->GetOrigin()[i]) && !IsMissingValue(x[i]))
73  {
74  temp = this->GetOrigin()[i] - x[i];
75  distance += temp * temp;
76  }
77  }
78 
79  return distance;
80 }
81 
82 template <class TVector>
84 {
85  // FIXME throw NaN exception ??
86  if (IsMissingValue(a) || IsMissingValue(b))
87  return 0.0;
88 
89  double temp = a - b;
90  return temp * temp;
91 }
92 
93 template <class TVector>
94 /*static */
96 {
97  return static_cast<bool>(vnl_math_isnan(static_cast<double>(v)));
98 }
99 
100 template <class TVector>
101 /* static */
103 {
104  v = std::numeric_limits<ValueType>::signaling_NaN();
105 }
106 
107 } // end namespace statistics
108 
109 } // end namespace otb
110 
111 #endif
otb::Statistics::EuclideanDistanceMetricWithMissingValuePow2::Evaluate
double Evaluate(const TVector &x) const override
Definition: otbEuclideanDistanceMetricWithMissingValuePow2.hxx:58
otb::Statistics::EuclideanDistanceMetricWithMissingValuePow2::MeasurementVectorSizeType
Superclass::MeasurementVectorSizeType MeasurementVectorSizeType
Definition: otbEuclideanDistanceMetricWithMissingValuePow2.h:61
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Statistics::EuclideanDistanceMetricWithMissingValuePow2::SetToMissingValue
static void SetToMissingValue(ValueType &v)
Definition: otbEuclideanDistanceMetricWithMissingValuePow2.hxx:102
otb::Statistics::EuclideanDistanceMetricWithMissingValuePow2::IsMissingValue
static bool IsMissingValue(const ValueType &v)
Definition: otbEuclideanDistanceMetricWithMissingValuePow2.hxx:95
otb::Statistics::EuclideanDistanceMetricWithMissingValuePow2::ValueType
TVector::ValueType ValueType
Definition: otbEuclideanDistanceMetricWithMissingValuePow2.h:67
otbEuclideanDistanceMetricWithMissingValuePow2.h