Main MRPT website > C++ reference for MRPT 1.5.3
types.hpp
Go to the documentation of this file.
1 #ifndef SOPHUS_TYEPES_HPP
2 #define SOPHUS_TYEPES_HPP
3 
4 #include <Eigen/Geometry>
5 #include "common.hpp"
6 
7 namespace Sophus {
8 
9 template <class Scalar, int M, int Options = 0>
10 using Vector = Eigen::Matrix<Scalar, M, 1, Options>;
11 
12 template <class Scalar, int Options = 0>
16 
17 template <class Scalar, int Options = 0>
21 
22 template <class Scalar>
26 
27 template <class Scalar>
31 
32 template <class Scalar>
36 
37 template <class Scalar, int M, int N>
38 using Matrix = Eigen::Matrix<Scalar, M, N>;
39 
40 template <class Scalar>
44 
45 template <class Scalar>
49 
50 template <class Scalar>
54 
55 template <class Scalar>
59 
60 template <class Scalar>
64 
65 namespace details {
66 template <class Scalar>
67 class Metric {
68  public:
69  static Scalar impl(Scalar s0, Scalar s1) {
70  using std::abs;
71  return abs(s0 - s1);
72  }
73 };
74 
75 template <class Scalar, int M, int N>
76 class Metric<Matrix<Scalar, M, N>> {
77  public:
78  static Scalar impl(Matrix<Scalar, M, N> const& p0,
79  Matrix<Scalar, M, N> const& p1) {
80  return (p0 - p1).norm();
81  }
82 };
83 
84 template <typename Scalar>
85 class SetToZero {
86  public:
87  static void impl(Scalar& s) { s = Scalar(0); }
88 };
89 
90 template <typename Scalar, int M, int N>
91 class SetToZero<Matrix<Scalar, M, N>> {
92  public:
93  static void impl(Matrix<Scalar, M, N>& v) { v.setZero(); }
94 };
95 
96 template <typename Scalar>
97 class SquaredNorm {
98  public:
99  static Scalar impl(Scalar const& s) { return s * s; }
100 };
101 
102 template <typename Scalar, int N>
103 class SquaredNorm<Matrix<Scalar, N, 1>> {
104  public:
105  static Scalar impl(Matrix<Scalar, N, 1> const& s) { return s.squaredNorm(); }
106 };
107 
108 template <typename Scalar>
109 class Transpose {
110  public:
111  static Scalar impl(Scalar const& s) { return s; }
112 };
113 
114 template <typename Scalar, int M, int N>
115 class Transpose<Matrix<Scalar, M, N>> {
116  public:
118  return s.transpose();
119  }
120 };
121 } // namespace details
122 
123 // Returns Euclidiean metric between two points ``p0`` and ``p1``, with ``p``
124 // being a matrix or a scalar.
125 //
126 template <class T>
127 auto metric(T const& p0, T const& p1)
128  -> decltype(details::Metric<T>::impl(p0, p1)) {
129  return details::Metric<T>::impl(p0, p1);
130 }
131 
132 // Sets point ``p`` to zero, with ``p`` being a matrix or a scalar.
133 //
134 template <class T>
135 auto setToZero(T& p) -> decltype(details::SetToZero<T>::impl(p)) {
136  return details::SetToZero<T>::impl(p);
137 }
138 
139 // Returns the squared 2-norm of ``p``, with ``p`` being a vector or a scalar.
140 //
141 template <class T>
142 auto squaredNorm(T const& p) -> decltype(details::SquaredNorm<T>::impl(p)) {
144 }
145 
146 // Returns ``p.transpose()`` if ``p`` is a matrix, and simply ``p`` if m is a
147 // scalar.
148 //
149 template <typename T>
150 auto transpose(T const& p) -> decltype(details::Transpose<T>::impl(T())) {
151  return details::Transpose<T>::impl(p);
152 }
153 
154 // Planes in 3d are hyperplanes.
155 template <class T>
156 using Plane3 = Eigen::Hyperplane<T, 3>;
159 
160 // Lines in 2d are hyperplanes.
161 template <class T>
162 using Line2 = Eigen::Hyperplane<T, 2>;
165 
166 } // namespace Sophus
167 
168 #endif // SOPHUS_TYEPES_HPP
Vector3< float > Vector3f
Definition: types.hpp:19
Eigen::Hyperplane< T, 3 > Plane3
Definition: types.hpp:156
Matrix< Scalar, 4, 4 > Matrix4
Definition: types.hpp:51
Vector2< float > Vector2f
Definition: types.hpp:14
static Scalar impl(Matrix< Scalar, M, N > const &p0, Matrix< Scalar, M, N > const &p1)
Definition: types.hpp:78
auto setToZero(T &p) -> decltype(details::SetToZero< T >::impl(p))
Definition: types.hpp:135
static Scalar impl(Matrix< Scalar, N, 1 > const &s)
Definition: types.hpp:105
Eigen::Hyperplane< T, 2 > Line2
Definition: types.hpp:162
Matrix3< float > Matrix3f
Definition: types.hpp:47
Vector2< double > Vector2d
Definition: types.hpp:15
Vector7< double > Vector7d
Definition: types.hpp:35
Matrix< Scalar, 6, 6 > Matrix6
Definition: types.hpp:56
Vector3< double > Vector3d
Definition: types.hpp:20
Matrix4< float > Matrix4f
Definition: types.hpp:52
Vector7< float > Vector7f
Definition: types.hpp:34
Vector< Scalar, 6 > Vector6
Definition: types.hpp:28
Matrix2< double > Matrix2d
Definition: types.hpp:43
Matrix4< double > Matrix4d
Definition: types.hpp:53
static Scalar impl(Scalar const &s)
Definition: types.hpp:99
auto transpose(T const &p) -> decltype(details::Transpose< T >::impl(T()))
Definition: types.hpp:150
Vector< Scalar, 2, Options > Vector2
Definition: types.hpp:13
Vector6< float > Vector6f
Definition: types.hpp:29
Matrix6< float > Matrix6f
Definition: types.hpp:57
Vector4< float > Vector4f
Definition: types.hpp:24
static Matrix< Scalar, M, N > impl(Matrix< Scalar, M, N > const &s)
Definition: types.hpp:117
Line2< double > Line2d
Definition: types.hpp:163
Eigen::Matrix< Scalar, M, N > Matrix
Definition: types.hpp:38
Matrix< Scalar, 7, 7 > Matrix7
Definition: types.hpp:61
Matrix3< double > Matrix3d
Definition: types.hpp:48
Vector< Scalar, 3, Options > Vector3
Definition: types.hpp:18
Matrix2< float > Matrix2f
Definition: types.hpp:42
Matrix7< float > Matrix7f
Definition: types.hpp:62
static Scalar impl(Scalar s0, Scalar s1)
Definition: types.hpp:69
Matrix< Scalar, 2, 2 > Matrix2
Definition: types.hpp:41
Plane3< double > Plane3d
Definition: types.hpp:157
Eigen::Matrix< Scalar, M, 1, Options > Vector
Definition: types.hpp:10
Matrix< Scalar, 3, 3 > Matrix3
Definition: types.hpp:46
Matrix6< double > Matrix6d
Definition: types.hpp:58
Matrix7< double > Matrix7d
Definition: types.hpp:63
Plane3< float > Plane3f
Definition: types.hpp:158
static void impl(Matrix< Scalar, M, N > &v)
Definition: types.hpp:93
Vector6< double > Vector6d
Definition: types.hpp:30
Vector< Scalar, 7 > Vector7
Definition: types.hpp:33
Vector< Scalar, 4 > Vector4
Definition: types.hpp:23
Line2< float > Line2f
Definition: types.hpp:164
auto metric(T const &p0, T const &p1) -> decltype(details::Metric< T >::impl(p0, p1))
Definition: types.hpp:127
static void impl(Scalar &s)
Definition: types.hpp:87
auto squaredNorm(T const &p) -> decltype(details::SquaredNorm< T >::impl(p))
Definition: types.hpp:142
static Scalar impl(Scalar const &s)
Definition: types.hpp:111
Vector4< double > Vector4d
Definition: types.hpp:25



Page generated by Doxygen 1.8.13 for MRPT 1.5.3 at Sun Nov 26 00:44:48 UTC 2017