L1Norm.h
Go to the documentation of this file.
1#ifndef GfxTL__L1NORM_HEADER__
2#define GfxTL__L1NORM_HEADER__
3#include <GfxTL/MathHelper.h>
6
7namespace GfxTL
8{
9 template <class VectorKernelT>
10 struct L1Norm : public VectorKernelT
11 {
12 template <class ScalarAT, class ScalarBT>
17
18 template <class PointAT, class PointBT>
21 Distance(const PointAT& p, const PointBT& v) const
22 {
25 DistType;
26 DistType d = p[0] - v[0], di;
28 for (unsigned int i = 1; i < m_dim; ++i)
29 {
30 di = p[i] - v[i];
31 d += Math<DistType>::Abs(di);
32 }
33 return d;
34 }
35
36 template <class PointAT, class PointBT>
37 typename DistanceType<typename ScalarTypeDeferer<PointAT>::ScalarType,
39 SqrDistance(const PointAT& p, const PointBT& v) const
40 {
41 return Distance(p, v);
42 }
43
44 template <class ScalarT>
45 ScalarT
46 RootOfDistance(ScalarT sqrDistance) const
47 {
48 return sqrDistance;
49 }
50
51 template <class DistScalarT, class DiffScalarT>
52 DistScalarT
53 IncrementalBoxSqrDistance(DistScalarT boxSqrDist,
54 DiffScalarT boxDiff,
55 DiffScalarT cutDiff) const
56 {
57 return boxSqrDist + (DistScalarT)cutDiff - (DistScalarT)boxDiff;
58 }
59
60 template <class PointAT, class PointBT>
61 typename DistanceType<typename ScalarTypeDeferer<PointAT>::ScalarType,
63 BoxSqrDistance(const PointAT& a, const PointBT& min, const PointBT& max) const
64 {
66 typename ScalarTypeDeferer<PointBT>::ScalarType>::Type sqrDist =
67 0,
68 t;
69 for (unsigned int i = 0; i < m_dim; ++i)
70 {
71 if (a[i] < min[i])
72 {
73 t = min[i] - a[i];
74 sqrDist += t;
75 }
76 else if (a[i] > max[i])
77 {
78 t = a[i] - max[i];
79 sqrDist += t;
80 }
81 }
82 return sqrDist;
83 }
84 };
85}; // namespace GfxTL
86
87#endif
static ScalarT Abs(ScalarT s)
Definition MathHelper.h:15
Definition AABox.h:10
MatrixXX< C, R, T > min(const MatrixXX< C, R, T > &a, const MatrixXX< C, R, T > &b)
Definition MatrixXX.h:616
MatrixXX< C, R, T > max(const MatrixXX< C, R, T > &a, const MatrixXX< C, R, T > &b)
Definition MatrixXX.h:630
ScalarTypeConversion< ScalarAT, ScalarBT >::DifferenceType Type
Definition L1Norm.h:15
DistScalarT IncrementalBoxSqrDistance(DistScalarT boxSqrDist, DiffScalarT boxDiff, DiffScalarT cutDiff) const
Definition L1Norm.h:53
DistanceType< typenameScalarTypeDeferer< PointAT >::ScalarType, typenameScalarTypeDeferer< PointBT >::ScalarType >::Type Distance(const PointAT &p, const PointBT &v) const
Definition L1Norm.h:21
ScalarT RootOfDistance(ScalarT sqrDistance) const
Definition L1Norm.h:46
DistanceType< typenameScalarTypeDeferer< PointAT >::ScalarType, typenameScalarTypeDeferer< PointBT >::ScalarType >::Type SqrDistance(const PointAT &p, const PointBT &v) const
Definition L1Norm.h:39
DistanceType< typenameScalarTypeDeferer< PointAT >::ScalarType, typenameScalarTypeDeferer< PointBT >::ScalarType >::Type BoxSqrDistance(const PointAT &a, const PointBT &min, const PointBT &max) const
Definition L1Norm.h:63
PointT::value_type ScalarType