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 : public VectorKernelT
11  {
12  template <class ScalarAT, class ScalarBT>
13  struct DistanceType
14  {
16  };
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;
27  d = Math<DistType>::Abs(d);
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  {
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
GfxTL::L1Norm::DistanceType
Definition: L1Norm.h:13
GfxTL::max
MatrixXX< C, R, T > max(const MatrixXX< C, R, T > &a, const MatrixXX< C, R, T > &b)
Definition: MatrixXX.h:630
GfxTL::L1Norm::Distance
DistanceType< typename ScalarTypeDeferer< PointAT >::ScalarType, typename ScalarTypeDeferer< PointBT >::ScalarType >::Type Distance(const PointAT &p, const PointBT &v) const
Definition: L1Norm.h:21
GfxTL::ScalarTypeDeferer::ScalarType
PointT::value_type ScalarType
Definition: ScalarTypeDeferer.h:15
GfxTL::L1Norm::SqrDistance
DistanceType< typename ScalarTypeDeferer< PointAT >::ScalarType, typename ScalarTypeDeferer< PointBT >::ScalarType >::Type SqrDistance(const PointAT &p, const PointBT &v) const
Definition: L1Norm.h:39
GfxTL::Math::Abs
static ScalarT Abs(ScalarT s)
Definition: MathHelper.h:15
GfxTL::L1Norm::IncrementalBoxSqrDistance
DistScalarT IncrementalBoxSqrDistance(DistScalarT boxSqrDist, DiffScalarT boxDiff, DiffScalarT cutDiff) const
Definition: L1Norm.h:53
ScalarTypeConversion.h
armarx::ctrlutil::a
double a(double t, double a0, double j)
Definition: CtrlUtil.h:45
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:63
GfxTL::L1Norm::DistanceType::Type
ScalarTypeConversion< ScalarAT, ScalarBT >::DifferenceType Type
Definition: L1Norm.h:15
GfxTL::L1Norm
Definition: L1Norm.h:10
armarx::aron::similarity::FloatSimilarity::Type
Type
The Type enum.
Definition: FloatSimilarity.h:10
GfxTL::min
MatrixXX< C, R, T > min(const MatrixXX< C, R, T > &a, const MatrixXX< C, R, T > &b)
Definition: MatrixXX.h:616
GfxTL
Definition: AABox.h:9
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:46
MathHelper.h
ScalarTypeDeferer.h