Robotics Library  0.7.0
TypeTraits.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2009, Markus Rickert
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 // POSSIBILITY OF SUCH DAMAGE.
25 //
26 
27 #ifndef RL_MATH_TYPETRAITS_H
28 #define RL_MATH_TYPETRAITS_H
29 
30 #define EIGEN_MATRIXBASE_PLUGIN <rl/math/MatrixBaseAddons.h>
31 #define EIGEN_QUATERNIONBASE_PLUGIN <rl/math/QuaternionBaseAddons.h>
32 #define EIGEN_TRANSFORM_PLUGIN <rl/math/TransformAddons.h>
33 
34 #include <limits>
35 #include <Eigen/Core>
36 
37 namespace rl
38 {
39  namespace math
40  {
41  template<typename T>
42  class TypeTraits
43  {
44  public:
45  static T Constant(const ::std::size_t& i, const T& value)
46  {
47  return value;
48  }
49 
50  static T Zero(const ::std::size_t& i)
51  {
52  return 0;
53  }
54 
55  static T abs(const T& t)
56  {
57  return ::std::abs(t);
58  }
59 
60  static bool equal(const T& lhs, const T& rhs, const T& epsilon = ::Eigen::NumTraits<T>::dummy_precision())
61  {
62  return ::std::abs(lhs - rhs) < epsilon;
63  }
64 
65  static T max_element(const T& t)
66  {
67  return t;
68  }
69 
70  static T min_element(const T& t)
71  {
72  return t;
73  }
74 
75  static ::std::size_t size(const T& t)
76  {
77  return 1;
78  }
79 
80  protected:
81 
82  private:
83 
84  };
85 
86  template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
87  class TypeTraits< ::Eigen::Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols>>
88  {
89  public:
90  static ::Eigen::Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> Constant(const ::std::size_t& i, const Scalar& value)
91  {
92  return ::Eigen::Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols>::Constant(i, value);
93  }
94 
95  static ::Eigen::Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> Zero(const ::std::size_t& i)
96  {
97  return ::Eigen::Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols>::Zero(i);
98  }
99 
100  static ::Eigen::Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> abs(const ::Eigen::Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols>& t)
101  {
102  return t.abs();
103  }
104 
105  static bool equal(const ::Eigen::Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols>& lhs, const ::Eigen::Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols>& rhs, const Scalar& epsilon = ::Eigen::NumTraits<Scalar>::dummy_precision())
106  {
107  return lhs.isApprox(rhs, epsilon);
108  }
109 
110  static Scalar max_element(const ::Eigen::Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols>& t)
111  {
112  return t.maxCoeff();
113  }
114 
115  static Scalar min_element(const ::Eigen::Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols>& t)
116  {
117  return t.minCoeff();
118  }
119 
120  static ::std::size_t size(const ::Eigen::Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols>& t)
121  {
122  return t.size();
123  }
124 
125  protected:
126 
127  private:
128 
129  };
130 
131  template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
132  class TypeTraits< ::Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>>
133  {
134  public:
135  static ::Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> Constant(const ::std::size_t& i, const Scalar& value)
136  {
137  return ::Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>::Constant(i, value);
138  }
139 
140  static ::Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> Zero(const ::std::size_t& i)
141  {
142  return ::Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>::Zero(i);
143  }
144 
145  static ::Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> abs(const ::Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>& t)
146  {
147  return t.cwiseAbs();
148  }
149 
150  static bool equal(const ::Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>& lhs, const ::Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>& rhs, const Scalar& epsilon = ::Eigen::NumTraits<Scalar>::dummy_precision())
151  {
152  return lhs.isApprox(rhs, epsilon);
153  }
154 
155  static Scalar max_element(const ::Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>& t)
156  {
157  return t.maxCoeff();
158  }
159 
160  static Scalar min_element(const ::Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>& t)
161  {
162  return t.minCoeff();
163  }
164 
165  static ::std::size_t size(const ::Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>& t)
166  {
167  return t.size();
168  }
169 
170  protected:
171 
172  private:
173 
174  };
175  }
176 }
177 
178 #endif // RL_MATH_TYPETRAITS_H
rl::math::Matrix
::Eigen::Matrix< Real, ::Eigen::Dynamic, ::Eigen::Dynamic > Matrix
Definition: Matrix.h:42
rl::math::TypeTraits< ::Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols > >::max_element
static Scalar max_element(const ::Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols > &t)
Definition: TypeTraits.h:155
rl::math::TypeTraits::max_element
static T max_element(const T &t)
Definition: TypeTraits.h:65
rl::math::TypeTraits::size
::std::size_t size(const T &t)
Definition: TypeTraits.h:75
rl::math::TypeTraits< ::Eigen::Array< Scalar, Rows, Cols, Options, MaxRows, MaxCols > >::max_element
static Scalar max_element(const ::Eigen::Array< Scalar, Rows, Cols, Options, MaxRows, MaxCols > &t)
Definition: TypeTraits.h:110
rl::math::TypeTraits::min_element
static T min_element(const T &t)
Definition: TypeTraits.h:70
rl::math::TypeTraits::Zero
static T Zero(const ::std::size_t &i)
Definition: TypeTraits.h:50
rl::math::TypeTraits::Constant
static T Constant(const ::std::size_t &i, const T &value)
Definition: TypeTraits.h:45
rl::math::TypeTraits< ::Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols > >::Zero
static ::Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols > Zero(const ::std::size_t &i)
Definition: TypeTraits.h:140
rl::math::TypeTraits< ::Eigen::Array< Scalar, Rows, Cols, Options, MaxRows, MaxCols > >::abs
static ::Eigen::Array< Scalar, Rows, Cols, Options, MaxRows, MaxCols > abs(const ::Eigen::Array< Scalar, Rows, Cols, Options, MaxRows, MaxCols > &t)
Definition: TypeTraits.h:100
rl::math::TypeTraits< ::Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols > >::size
::std::size_t size(const ::Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols > &t)
Definition: TypeTraits.h:165
rl::math::TypeTraits::equal
static bool equal(const T &lhs, const T &rhs, const T &epsilon=::Eigen::NumTraits< T >::dummy_precision())
Definition: TypeTraits.h:60
rl::math::TypeTraits::abs
static T abs(const T &t)
Definition: TypeTraits.h:55
rl::math::TypeTraits< ::Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols > >::Constant
static ::Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols > Constant(const ::std::size_t &i, const Scalar &value)
Definition: TypeTraits.h:135
rl::math::TypeTraits< ::Eigen::Array< Scalar, Rows, Cols, Options, MaxRows, MaxCols > >::min_element
static Scalar min_element(const ::Eigen::Array< Scalar, Rows, Cols, Options, MaxRows, MaxCols > &t)
Definition: TypeTraits.h:115
rl::math::TypeTraits< ::Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols > >::min_element
static Scalar min_element(const ::Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols > &t)
Definition: TypeTraits.h:160
rl::math::TypeTraits< ::Eigen::Array< Scalar, Rows, Cols, Options, MaxRows, MaxCols > >::size
::std::size_t size(const ::Eigen::Array< Scalar, Rows, Cols, Options, MaxRows, MaxCols > &t)
Definition: TypeTraits.h:120
rl::math::TypeTraits< ::Eigen::Array< Scalar, Rows, Cols, Options, MaxRows, MaxCols > >::equal
static bool equal(const ::Eigen::Array< Scalar, Rows, Cols, Options, MaxRows, MaxCols > &lhs, const ::Eigen::Array< Scalar, Rows, Cols, Options, MaxRows, MaxCols > &rhs, const Scalar &epsilon=::Eigen::NumTraits< Scalar >::dummy_precision())
Definition: TypeTraits.h:105
rl::math::TypeTraits< ::Eigen::Array< Scalar, Rows, Cols, Options, MaxRows, MaxCols > >::Constant
static ::Eigen::Array< Scalar, Rows, Cols, Options, MaxRows, MaxCols > Constant(const ::std::size_t &i, const Scalar &value)
Definition: TypeTraits.h:90
rl::math::TypeTraits
Definition: TypeTraits.h:43
rl::math::TypeTraits< ::Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols > >::equal
static bool equal(const ::Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols > &lhs, const ::Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols > &rhs, const Scalar &epsilon=::Eigen::NumTraits< Scalar >::dummy_precision())
Definition: TypeTraits.h:150
rl::math::TypeTraits< ::Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols > >::abs
static ::Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols > abs(const ::Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols > &t)
Definition: TypeTraits.h:145
rl::math::TypeTraits< ::Eigen::Array< Scalar, Rows, Cols, Options, MaxRows, MaxCols > >::Zero
static ::Eigen::Array< Scalar, Rows, Cols, Options, MaxRows, MaxCols > Zero(const ::std::size_t &i)
Definition: TypeTraits.h:95
rl
Robotics Library.
Definition: AnalogInput.cpp:30