MaxNorm.h
Go to the documentation of this file.
1 #ifndef GfxTL__MAXNORM_HEADER__
2 #define GfxTL__MAXNORM_HEADER__
3 #include <GfxTL/MathHelper.h>
6 
7 namespace GfxTL
8 {
9  template< class VectorKernelT >
10  struct MaxNorm
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 di, max = Math< DistType >::Abs(p[0] - v[0]);
34  for (size_t i = 1; i < m_dim; ++i)
35  {
36  di = Math< DistType >::Abs(p[i] - v[i]);
37  if (di > max)
38  {
39  max = di;
40  }
41  }
42  return max;
43  }
44 
45  template< class PointAT, class PointBT >
46  typename DistanceType
47  <
50  >::Type
51  SqrDistance(const PointAT& p, const PointBT& v) const
52  {
53  typedef typename DistanceType
54  <
57  >::Type DistType;
58  DistType di, max = Math< DistType >::Abs(p[0] - v[0]);
59  for (size_t i = 1; i < m_dim; ++i)
60  {
61  di = Math< DistType >::Abs(p[i] - v[i]);
62  if (di > max)
63  {
64  max = di;
65  }
66  }
67  return max;
68  }
69 
70  template< class ScalarT >
71  ScalarT RootOfDistance(ScalarT sqrDistance) const
72  {
73  return sqrDistance;
74  }
75 
76  template< class DistScalarT, class DiffScalarT >
77  DistScalarT IncrementalBoxSqrDistance(DistScalarT boxDist, DiffScalarT boxDiff,
78  DiffScalarT cutDiff) const
79  {
80  return std::max(boxDist, (DistScalarT)Math< DiffScalarT >::Abs(cutDiff));
81  }
82 
83  template< class PointAT, class PointBT >
84  typename DistanceType
85  <
88  >::Type
89  BoxSqrDistance(const PointAT& a, const PointBT& min,
90  const PointBT& max) const
91  {
92  typename DistanceType
93  <
96  >::Type sqrDist = 0, t;
97  for (unsigned int i = 0; i < m_dim; ++i)
98  {
99  if (a[i] < min[i])
100  {
101  t = min[i] - a[i];
102  if (t > sqrDist)
103  {
104  sqrDist = t;
105  }
106  }
107  else if (a[i] > max[i])
108  {
109  t = a[i] - max[i];
110  if (t > sqrDist)
111  {
112  sqrDist = t;
113  }
114  }
115  }
116  return sqrDist;
117  }
118  };
119 };
120 
121 #endif
GfxTL::MaxNorm::Distance
DistanceType< typename ScalarTypeDeferer< PointAT >::ScalarType, typename ScalarTypeDeferer< PointBT >::ScalarType >::Type Distance(const PointAT &p, const PointBT &v) const
Definition: MaxNorm.h:26
GfxTL::max
MatrixXX< C, R, T > max(const MatrixXX< C, R, T > &a, const MatrixXX< C, R, T > &b)
Definition: MatrixXX.h:581
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
ScalarTypeConversion.h
GfxTL::MaxNorm::IncrementalBoxSqrDistance
DistScalarT IncrementalBoxSqrDistance(DistScalarT boxDist, DiffScalarT boxDiff, DiffScalarT cutDiff) const
Definition: MaxNorm.h:77
armarx::ctrlutil::a
double a(double t, double a0, double j)
Definition: CtrlUtil.h:45
GfxTL::MaxNorm::RootOfDistance
ScalarT RootOfDistance(ScalarT sqrDistance) const
Definition: MaxNorm.h:71
GfxTL::MaxNorm::BoxSqrDistance
DistanceType< typename ScalarTypeDeferer< PointAT >::ScalarType, typename ScalarTypeDeferer< PointBT >::ScalarType >::Type BoxSqrDistance(const PointAT &a, const PointBT &min, const PointBT &max) const
Definition: MaxNorm.h:89
max
T max(T t1, T t2)
Definition: gdiam.h:48
armarx::aron::similarity::FloatSimilarity::Type
Type
The Type enum.
Definition: FloatSimilarity.h:8
GfxTL::Math
Definition: MathHelper.h:11
GfxTL::MaxNorm::SqrDistance
DistanceType< typename ScalarTypeDeferer< PointAT >::ScalarType, typename ScalarTypeDeferer< PointBT >::ScalarType >::Type SqrDistance(const PointAT &p, const PointBT &v) const
Definition: MaxNorm.h:51
GfxTL
Definition: AABox.h:8
GfxTL::MaxNorm::DistanceType::Type
ScalarTypeConversion< ScalarAT, ScalarBT >::DifferenceType Type
Definition: MaxNorm.h:17
GfxTL::ScalarTypeConversion
Definition: ScalarTypeConversion.h:7
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
GfxTL::MaxNorm
Definition: MaxNorm.h:10
GfxTL::MaxNorm::DistanceType
Definition: MaxNorm.h:14
MathHelper.h
ScalarTypeDeferer.h