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 
7 namespace GfxTL
8 {
9  template< class VectorKernelT >
10  struct L1Norm
11  : public VectorKernelT
12  {
13  template< class ScalarAT, class ScalarBT >
14  struct DistanceType
15  {
16  typedef typename ScalarTypeConversion< ScalarAT,
17  ScalarBT >::DifferenceType Type;
18  };
19 
20  template< class PointAT, class PointBT >
21  typename DistanceType
22  <
25  >::Type
26  Distance(const PointAT& p, const PointBT& v) const
27  {
28  typedef typename DistanceType
29  <
32  >::Type DistType;
33  DistType d = p[0] - v[0], di;
34  d = Math< DistType >::Abs(d);
35  for (unsigned int i = 1; i < m_dim; ++i)
36  {
37  di = p[i] - v[i];
38  d += Math< DistType >::Abs(di);
39  }
40  return d;
41  }
42 
43  template< class PointAT, class PointBT >
44  typename DistanceType
45  <
48  >::Type
49  SqrDistance(const PointAT& p, const PointBT& v) const
50  {
51  return Distance(p, v);
52  }
53 
54  template< class ScalarT >
55  ScalarT RootOfDistance(ScalarT sqrDistance) const
56  {
57  return sqrDistance;
58  }
59 
60  template< class DistScalarT, class DiffScalarT >
61  DistScalarT IncrementalBoxSqrDistance(DistScalarT boxSqrDist, DiffScalarT boxDiff,
62  DiffScalarT cutDiff) const
63  {
64  return boxSqrDist + (DistScalarT)cutDiff
65  - (DistScalarT)boxDiff;
66  }
67 
68  template< class PointAT, class PointBT >
69  typename DistanceType
70  <
73  >::Type
74  BoxSqrDistance(const PointAT& a, const PointBT& min,
75  const PointBT& max) const
76  {
77  typename DistanceType
78  <
81  >::Type sqrDist = 0, t;
82  for (unsigned int i = 0; i < m_dim; ++i)
83  {
84  if (a[i] < min[i])
85  {
86  t = min[i] - a[i];
87  sqrDist += t;
88  }
89  else if (a[i] > max[i])
90  {
91  t = a[i] - max[i];
92  sqrDist += t;
93  }
94  }
95  return sqrDist;
96  }
97  };
98 };
99 
100 #endif
GfxTL::L1Norm::DistanceType
Definition: L1Norm.h:14
GfxTL::max
MatrixXX< C, R, T > max(const MatrixXX< C, R, T > &a, const MatrixXX< C, R, T > &b)
Definition: MatrixXX.h:581
GfxTL::L1Norm::SqrDistance
DistanceType< typename ScalarTypeDeferer< PointAT >::ScalarType, typename ScalarTypeDeferer< PointBT >::ScalarType >::Type SqrDistance(const PointAT &p, const PointBT &v) const
Definition: L1Norm.h:49
GfxTL::ScalarTypeDeferer::ScalarType
PointT::value_type ScalarType
Definition: ScalarTypeDeferer.h:14
GfxTL::min
MatrixXX< C, R, T > min(const MatrixXX< C, R, T > &a, const MatrixXX< C, R, T > &b)
Definition: MatrixXX.h:568
GfxTL::Math::Abs
static ScalarT Abs(ScalarT s)
Definition: MathHelper.h:14
GfxTL::L1Norm::IncrementalBoxSqrDistance
DistScalarT IncrementalBoxSqrDistance(DistScalarT boxSqrDist, DiffScalarT boxDiff, DiffScalarT cutDiff) const
Definition: L1Norm.h:61
ScalarTypeConversion.h
GfxTL::L1Norm::Distance
DistanceType< typename ScalarTypeDeferer< PointAT >::ScalarType, typename ScalarTypeDeferer< PointBT >::ScalarType >::Type Distance(const PointAT &p, const PointBT &v) const
Definition: L1Norm.h:26
armarx::ctrlutil::a
double a(double t, double a0, double j)
Definition: CtrlUtil.h:45
GfxTL::L1Norm
Definition: L1Norm.h:10
armarx::aron::similarity::FloatSimilarity::Type
Type
The Type enum.
Definition: FloatSimilarity.h:8
GfxTL
Definition: AABox.h:8
GfxTL::ScalarTypeConversion
Definition: ScalarTypeConversion.h:7
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
GfxTL::L1Norm::RootOfDistance
ScalarT RootOfDistance(ScalarT sqrDistance) const
Definition: L1Norm.h:55
MathHelper.h
GfxTL::L1Norm::BoxSqrDistance
DistanceType< typename ScalarTypeDeferer< PointAT >::ScalarType, typename ScalarTypeDeferer< PointBT >::ScalarType >::Type BoxSqrDistance(const PointAT &a, const PointBT &min, const PointBT &max) const
Definition: L1Norm.h:74
ScalarTypeDeferer.h
GfxTL::L1Norm::DistanceType::Type
ScalarTypeConversion< ScalarAT, ScalarBT >::DifferenceType Type
Definition: L1Norm.h:17