42 #include <pcl/console/print.h>
49 template <
typename FloatVectorT>
inline float
81 PCL_ERROR (
"[pcl::selectNorm] For PF and K norms you have to explicitly call the method, as they need additional parameters\n");
87 template <
typename FloatVectorT>
inline float
88 L1_Norm (FloatVectorT a, FloatVectorT b,
int dim)
91 for (
int i = 0; i < dim; ++i)
92 norm += std::abs(a[i] - b[i]);
97 template <
typename FloatVectorT>
inline float
101 for (
int i = 0; i < dim; ++i)
103 float diff = a[i] - b[i];
110 template <
typename FloatVectorT>
inline float
111 L2_Norm (FloatVectorT a, FloatVectorT b,
int dim)
117 template <
typename FloatVectorT>
inline float
121 for (
int i = 0; i < dim; ++i)
122 norm = (std::max)(std::abs(a[i] - b[i]), norm);
127 template <
typename FloatVectorT>
inline float
128 JM_Norm (FloatVectorT a, FloatVectorT b,
int dim)
132 for (
int i = 0; i < dim; ++i)
133 norm += (std::sqrt (a[i]) - std::sqrt (b[i])) * (std::sqrt (a[i]) - std::sqrt (b[i]));
135 return std::sqrt (norm);
139 template <
typename FloatVectorT>
inline float
140 B_Norm (FloatVectorT a, FloatVectorT b,
int dim)
142 float norm = 0.0, result;
144 for (
int i = 0; i < dim; ++i)
145 norm += std::sqrt (a[i] * b[i]);
148 result = -std::log (norm);
156 template <
typename FloatVectorT>
inline float
161 for (
int i = 0; i < dim; ++i)
162 norm += std::sqrt (std::abs (a[i] - b[i]));
168 template <
typename FloatVectorT>
inline float
169 CS_Norm (FloatVectorT a, FloatVectorT b,
int dim)
173 for (
int i = 0; i < dim; ++i)
174 if ((a[i] + b[i]) != 0)
175 norm += (a[i] - b[i]) * (a[i] - b[i]) / (a[i] + b[i]);
182 template <
typename FloatVectorT>
inline float
187 for (
int i = 0; i < dim; ++i)
188 if ((a[i] / b[i]) > 0)
189 norm += (a[i] - b[i]) * std::log (a[i] / b[i]);
196 template <
typename FloatVectorT>
inline float
197 PF_Norm (FloatVectorT a, FloatVectorT b,
int dim,
float P1,
float P2)
201 for (
int i = 0; i < dim; ++i)
202 norm += (P1 * a[i] - P2 * b[i]) * (P1 * a[i] - P2 * b[i]);
203 return std::sqrt (norm);
207 template <
typename FloatVectorT>
inline float
208 K_Norm (FloatVectorT a, FloatVectorT b,
int dim,
float P1,
float P2)
212 for (
int i = 0; i < dim; ++i)
213 norm += std::abs (P1 * a[i] - P2 * b[i]);
218 template <
typename FloatVectorT>
inline float
219 KL_Norm (FloatVectorT a, FloatVectorT b,
int dim)
223 for (
int i = 0; i < dim; ++i)
224 if ( (b[i] != 0) && ((a[i] / b[i]) > 0) )
225 norm += a[i] * std::log (a[i] / b[i]);
232 template <
typename FloatVectorT>
inline float
236 for (
int i = 0; i < dim; ++i)
237 norm += (std::min)(a[i], b[i]);
float selectNorm(FloatVectorT a, FloatVectorT b, int dim, NormType norm_type)
Method that calculates any norm type available, based on the norm_type variable.
float B_Norm(FloatVectorT a, FloatVectorT b, int dim)
Compute the B norm of the vector between two points.
float KL_Norm(FloatVectorT a, FloatVectorT b, int dim)
Compute the KL between two discrete probability density functions.
float JM_Norm(FloatVectorT a, FloatVectorT b, int dim)
Compute the JM norm of the vector between two points.
float K_Norm(FloatVectorT a, FloatVectorT b, int dim, float P1, float P2)
Compute the K norm of the vector between two points.
float L1_Norm(FloatVectorT a, FloatVectorT b, int dim)
Compute the L1 norm of the vector between two points.
float Linf_Norm(FloatVectorT a, FloatVectorT b, int dim)
Compute the L-infinity norm of the vector between two points.
float L2_Norm(FloatVectorT a, FloatVectorT b, int dim)
Compute the L2 norm of the vector between two points.
float CS_Norm(FloatVectorT a, FloatVectorT b, int dim)
Compute the CS norm of the vector between two points.
float HIK_Norm(FloatVectorT a, FloatVectorT b, int dim)
Compute the HIK norm of the vector between two points.
NormType
Enum that defines all the types of norms available.
float Sublinear_Norm(FloatVectorT a, FloatVectorT b, int dim)
Compute the sublinear norm of the vector between two points.
float Div_Norm(FloatVectorT a, FloatVectorT b, int dim)
Compute the div norm of the vector between two points.
float L2_Norm_SQR(FloatVectorT a, FloatVectorT b, int dim)
Compute the squared L2 norm of the vector between two points.
float PF_Norm(FloatVectorT a, FloatVectorT b, int dim, float P1, float P2)
Compute the PF norm of the vector between two points.
Define standard C methods to calculate different norms.
Defines all the PCL and non-PCL macros used.