VectorKernel.h
Go to the documentation of this file.
1 #ifndef GfxTL__VECTORKERNEL_HEADER__
2 #define GfxTL__VECTORKERNEL_HEADER__
3 
6 #include <GfxTL/VectorXD.h>
7 #include <GfxTL/NullClass.h>
8 
9 namespace GfxTL
10 {
12  {
13  public:
14  void Dimension(unsigned int dim)
15  {
16  m_dim = dim;
17  }
18 
19  const unsigned int Dimension() const
20  {
21  return m_dim;
22  }
23 
24  protected:
25  unsigned int m_dim;
26  };
27 
28  template< unsigned int DimT >
30  {
31  public:
32  const unsigned int Dimension() const
33  {
34  return m_dim;
35  }
36 
37  protected:
38  enum { m_dim = DimT };
39  };
40 
41  template< class DimensionStrategyT, class BaseT = NullClass >
42  struct VectorKernel
43  : public BaseT
44  , public DimensionStrategyT
45  {
46  typedef DimensionStrategyT DimensionStrategyType;
47 
48  template< class PointAT, class PointBT >
49  void AssignVector(const PointAT& a, const PointBT* b) const
50  {
51  for (unsigned int i = 0; i < DimensionStrategyT::m_dim; ++i)
52  {
53  (*b)[i] = a[i];
54  }
55  }
56 
57  template< class PointAT, class PointBT, class PointDT >
58  void Add(const PointAT& a, const PointBT& b, PointDT* d) const
59  {
60  for (unsigned int i = 0; i < DimensionStrategyT::m_dim; ++i)
61  {
62  (*d)[i] = a[i] + b[i];
63  }
64  }
65 
66  template< class PointAT, class PointBT, class PointDT >
67  void Sub(const PointAT& a, const PointBT& b, PointDT* d) const
68  {
69  for (unsigned int i = 0; i < DimensionStrategyT::m_dim; ++i)
70  {
71  (*d)[i] = a[i] - b[i];
72  }
73  }
74 
75  template< class PointAT, class PointBT >
76  typename ScalarTypeConversion
77  <
78  typename ScalarTypeConversion
79  <
82  >::MultiplicationType,
83  typename ScalarTypeConversion
84  <
87  >::MultiplicationType
88  >::AdditionType Dot(const PointAT& a, const PointBT& b) const
89  {
90  typename ScalarTypeConversion
91  <
92  typename ScalarTypeConversion
93  <
96  >::MultiplicationType,
97  typename ScalarTypeConversion
98  <
101  >::MultiplicationType
102  >::AdditionType d = a[0] * b[0];
103  for (unsigned int i = 1; i < DimensionStrategyT::m_dim; ++i)
104  {
105  d += a[i] * b[i];
106  }
107  return d;
108  }
109 
110  template< class PointAT, class PointBT >
111  void Mul(typename ScalarTypeDeferer< PointAT >::ScalarType s, const PointAT& a,
112  PointBT* b) const
113  {
114  for (unsigned int i = 0; i < DimensionStrategyT::m_dim; ++i)
115  {
116  (*b)[i] = s * a[i];
117  }
118  }
119  };
120 
121  template< class BaseT = NullClass >
122  struct DynVectorKernel
123  : public VectorKernel< DynamicDimensionVectorKernelStrategy, BaseT >
124  {};
125 
126  template< unsigned int DimT >
128  {
129  template< class BaseT = NullClass >
131  : public VectorKernel< FixedDimensionVectorKernelStrategy< DimT >, BaseT >
132  {};
133  };
134 };
135 
136 #endif
GfxTL::VectorKernel::Add
void Add(const PointAT &a, const PointBT &b, PointDT *d) const
Definition: VectorKernel.h:58
GfxTL::VectorKernelD
Definition: VectorKernel.h:127
GfxTL::DynamicDimensionVectorKernelStrategy::Dimension
void Dimension(unsigned int dim)
Definition: VectorKernel.h:14
GfxTL::DynamicDimensionVectorKernelStrategy
Definition: VectorKernel.h:11
GfxTL::VectorKernel::Dot
ScalarTypeConversion< typename ScalarTypeConversion< typename ScalarTypeDeferer< PointAT >::ScalarType, typename ScalarTypeDeferer< PointBT >::ScalarType >::MultiplicationType, typename ScalarTypeConversion< typename ScalarTypeDeferer< PointAT >::ScalarType, typename ScalarTypeDeferer< PointBT >::ScalarType >::MultiplicationType >::AdditionType Dot(const PointAT &a, const PointBT &b) const
Definition: VectorKernel.h:88
GfxTL::ScalarTypeDeferer::ScalarType
PointT::value_type ScalarType
Definition: ScalarTypeDeferer.h:14
GfxTL::VectorKernelD::VectorKernelType
Definition: VectorKernel.h:130
GfxTL::FixedDimensionVectorKernelStrategy::Dimension
const unsigned int Dimension() const
Definition: VectorKernel.h:32
ScalarTypeConversion.h
VectorXD.h
GfxTL::DynamicDimensionVectorKernelStrategy::m_dim
unsigned int m_dim
Definition: VectorKernel.h:25
armarx::ctrlutil::a
double a(double t, double a0, double j)
Definition: CtrlUtil.h:45
GfxTL::VectorKernel::Sub
void Sub(const PointAT &a, const PointBT &b, PointDT *d) const
Definition: VectorKernel.h:67
GfxTL::VectorKernel::DimensionStrategyType
DimensionStrategyT DimensionStrategyType
Definition: VectorKernel.h:46
GfxTL::DynamicDimensionVectorKernelStrategy::Dimension
const unsigned int Dimension() const
Definition: VectorKernel.h:19
GfxTL
Definition: AABox.h:8
GfxTL::ScalarTypeConversion
Definition: ScalarTypeConversion.h:7
NullClass.h
GfxTL::VectorKernel::AssignVector
void AssignVector(const PointAT &a, const PointBT *b) const
Definition: VectorKernel.h:49
GfxTL::VectorKernel
Definition: VectorKernel.h:42
GfxTL::VectorKernel::Mul
void Mul(typename ScalarTypeDeferer< PointAT >::ScalarType s, const PointAT &a, PointBT *b) const
Definition: VectorKernel.h:111
GfxTL::FixedDimensionVectorKernelStrategy::m_dim
@ m_dim
Definition: VectorKernel.h:38
ScalarTypeDeferer.h
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
GfxTL::FixedDimensionVectorKernelStrategy
Definition: VectorKernel.h:29