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 : 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 di, max = Math<DistType>::Abs(p[0] - v[0]);
27  for (size_t i = 1; i < m_dim; ++i)
28  {
29  di = Math<DistType>::Abs(p[i] - v[i]);
30  if (di > max)
31  {
32  max = di;
33  }
34  }
35  return max;
36  }
37 
38  template <class PointAT, class PointBT>
39  typename DistanceType<typename ScalarTypeDeferer<PointAT>::ScalarType,
41  SqrDistance(const PointAT& p, const PointBT& v) const
42  {
45  DistType;
46  DistType di, max = Math<DistType>::Abs(p[0] - v[0]);
47  for (size_t i = 1; i < m_dim; ++i)
48  {
49  di = Math<DistType>::Abs(p[i] - v[i]);
50  if (di > max)
51  {
52  max = di;
53  }
54  }
55  return max;
56  }
57 
58  template <class ScalarT>
59  ScalarT
60  RootOfDistance(ScalarT sqrDistance) const
61  {
62  return sqrDistance;
63  }
64 
65  template <class DistScalarT, class DiffScalarT>
66  DistScalarT
67  IncrementalBoxSqrDistance(DistScalarT boxDist,
68  DiffScalarT boxDiff,
69  DiffScalarT cutDiff) const
70  {
71  return std::max(boxDist, (DistScalarT)Math<DiffScalarT>::Abs(cutDiff));
72  }
73 
74  template <class PointAT, class PointBT>
75  typename DistanceType<typename ScalarTypeDeferer<PointAT>::ScalarType,
77  BoxSqrDistance(const PointAT& a, const PointBT& min, const PointBT& max) const
78  {
81  0,
82  t;
83  for (unsigned int i = 0; i < m_dim; ++i)
84  {
85  if (a[i] < min[i])
86  {
87  t = min[i] - a[i];
88  if (t > sqrDist)
89  {
90  sqrDist = t;
91  }
92  }
93  else if (a[i] > max[i])
94  {
95  t = a[i] - max[i];
96  if (t > sqrDist)
97  {
98  sqrDist = t;
99  }
100  }
101  }
102  return sqrDist;
103  }
104  };
105 }; // namespace GfxTL
106 
107 #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:21
GfxTL::MaxNorm::SqrDistance
DistanceType< typename ScalarTypeDeferer< PointAT >::ScalarType, typename ScalarTypeDeferer< PointBT >::ScalarType >::Type SqrDistance(const PointAT &p, const PointBT &v) const
Definition: MaxNorm.h:41
GfxTL::max
MatrixXX< C, R, T > max(const MatrixXX< C, R, T > &a, const MatrixXX< C, R, T > &b)
Definition: MatrixXX.h:630
GfxTL::ScalarTypeDeferer::ScalarType
PointT::value_type ScalarType
Definition: ScalarTypeDeferer.h:15
GfxTL::Math::Abs
static ScalarT Abs(ScalarT s)
Definition: MathHelper.h:15
ScalarTypeConversion.h
GfxTL::MaxNorm::DistanceType::Type
ScalarTypeConversion< ScalarAT, ScalarBT >::DifferenceType Type
Definition: MaxNorm.h:15
GfxTL::MaxNorm::IncrementalBoxSqrDistance
DistScalarT IncrementalBoxSqrDistance(DistScalarT boxDist, DiffScalarT boxDiff, DiffScalarT cutDiff) const
Definition: MaxNorm.h:67
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:60
max
T max(T t1, T t2)
Definition: gdiam.h:51
armarx::aron::similarity::FloatSimilarity::Type
Type
The Type enum.
Definition: FloatSimilarity.h:10
GfxTL::Math
Definition: MathHelper.h:11
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::MaxNorm
Definition: MaxNorm.h:10
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:77
GfxTL::MaxNorm::DistanceType
Definition: MaxNorm.h:13
MathHelper.h
ScalarTypeDeferer.h