traits.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /** \file itasc/kdl/utilities/traits.h
  2. * \ingroup itasc
  3. */
  4. #ifndef KDLPV_TRAITS_H
  5. #define KDLPV_TRAITS_H
  6. #include "utility.h"
  7. // forwards declarations :
  8. namespace KDL {
  9. class Frame;
  10. class Rotation;
  11. class Vector;
  12. class Twist;
  13. class Wrench;
  14. class FrameVel;
  15. class RotationVel;
  16. class VectorVel;
  17. class TwistVel;
  18. }
  19. /**
  20. * @brief Traits are traits classes to determine the type of a derivative of another type.
  21. *
  22. * For geometric objects the "geometric" derivative is chosen. For example the derivative of a Rotation
  23. * matrix is NOT a 3x3 matrix containing the derivative of the elements of a rotation matrix. The derivative
  24. * of the rotation matrix is a Vector corresponding the rotational velocity. Mostly used in template classes
  25. * and routines to derive a correct type when needed.
  26. *
  27. * You can see this as a compile-time lookuptable to find the type of the derivative.
  28. *
  29. * Example
  30. * \verbatim
  31. Rotation R;
  32. Traits<Rotation> dR;
  33. \endverbatim
  34. */
  35. template <typename T>
  36. struct Traits {
  37. typedef T valueType;
  38. typedef T derivType;
  39. };
  40. template <>
  41. struct Traits<KDL::Frame> {
  42. typedef KDL::Frame valueType;
  43. typedef KDL::Twist derivType;
  44. };
  45. template <>
  46. struct Traits<KDL::Twist> {
  47. typedef KDL::Twist valueType;
  48. typedef KDL::Twist derivType;
  49. };
  50. template <>
  51. struct Traits<KDL::Wrench> {
  52. typedef KDL::Wrench valueType;
  53. typedef KDL::Wrench derivType;
  54. };
  55. template <>
  56. struct Traits<KDL::Rotation> {
  57. typedef KDL::Rotation valueType;
  58. typedef KDL::Vector derivType;
  59. };
  60. template <>
  61. struct Traits<KDL::Vector> {
  62. typedef KDL::Vector valueType;
  63. typedef KDL::Vector derivType;
  64. };
  65. template <>
  66. struct Traits<double> {
  67. typedef double valueType;
  68. typedef double derivType;
  69. };
  70. template <>
  71. struct Traits<float> {
  72. typedef float valueType;
  73. typedef float derivType;
  74. };
  75. template <>
  76. struct Traits<KDL::FrameVel> {
  77. typedef KDL::Frame valueType;
  78. typedef KDL::TwistVel derivType;
  79. };
  80. template <>
  81. struct Traits<KDL::TwistVel> {
  82. typedef KDL::Twist valueType;
  83. typedef KDL::TwistVel derivType;
  84. };
  85. template <>
  86. struct Traits<KDL::RotationVel> {
  87. typedef KDL::Rotation valueType;
  88. typedef KDL::VectorVel derivType;
  89. };
  90. template <>
  91. struct Traits<KDL::VectorVel> {
  92. typedef KDL::Vector valueType;
  93. typedef KDL::VectorVel derivType;
  94. };
  95. #endif