supereight
math_util.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2016-2019 Emanuele Vespa
3  * SPDX-FileCopyrightText: 2021 Smart Robotics Lab, Imperial College London, Technical University of Munich
4  * SPDX-FileCopyrightText: 2021 Nils Funk
5  * SPDX-FileCopyrightText: 2021 Sotiris Papatheodorou
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #ifndef SE_MATH_UTIL_HPP
10 #define SE_MATH_UTIL_HPP
11 
12 
13 
14 #include <Eigen/Dense>
15 #include <vector>
16 
17 
18 
19 namespace se {
20 namespace math {
21 
22 
23 
24 template<typename T>
25 constexpr bool is_power_of_two(T);
26 
27 template<>
28 constexpr bool is_power_of_two<unsigned>(const unsigned x);
29 
30 constexpr int log2_const(int n);
31 
32 static inline unsigned power_two_up(const float x);
33 
34 template<typename T>
35 static inline T fracf(const T& v);
36 
37 template<typename T>
38 static inline T floorf(const T& v);
39 
40 template<typename T>
41 static inline T fabs(const T& v);
42 
43 template<typename Scalar>
44 static constexpr inline Scalar sq(Scalar a);
45 
46 template<typename Scalar>
47 static constexpr inline Scalar cu(Scalar a);
48 
49 template<typename Scalar>
50 static inline bool in(const Scalar v, const Scalar a, const Scalar b);
51 
52 static inline Eigen::Vector3f to_translation(const Eigen::Matrix4f& T);
53 
54 static inline Eigen::Matrix3f to_rotation(const Eigen::Matrix4f& T);
55 
56 static inline Eigen::Matrix4f to_transformation(const Eigen::Vector3f& t);
57 
58 static inline Eigen::Matrix4f to_transformation(const Eigen::Matrix3f& R);
59 
60 static inline Eigen::Matrix4f to_transformation(const Eigen::Matrix3f& R, const Eigen::Vector3f& t);
61 
62 static inline Eigen::Vector3f to_inverse_translation(const Eigen::Matrix4f& T);
63 
64 static inline Eigen::Matrix3f to_inverse_rotation(const Eigen::Matrix4f& T);
65 
66 static inline Eigen::Matrix4f to_inverse_transformation(const Eigen::Matrix4f& T);
67 
68 template<typename T>
69 static inline typename std::enable_if<std::is_arithmetic<T>::value, T>::type
70 clamp(const T& f, const T& a, const T& b);
71 
72 static inline void clamp(Eigen::Ref<Eigen::VectorXf> res,
73  const Eigen::Ref<const Eigen::VectorXf> a,
74  const Eigen::Ref<Eigen::VectorXf> b);
75 
76 template<typename R, typename A, typename B>
77 static inline void
78 clamp(Eigen::MatrixBase<R>& res, const Eigen::MatrixBase<A>& a, const Eigen::MatrixBase<B>& b);
79 
83 static Eigen::Vector3f
84 plane_normal(const Eigen::Vector3f& p1, const Eigen::Vector3f& p2, const Eigen::Vector3f& p3);
85 
97 template<typename T>
98 static T median(std::vector<T>& data);
99 
114 template<typename T>
115 static T almost_median(std::vector<T>& data);
116 
121 template<typename T>
122 static T median(const std::vector<T>& data);
123 
143 static Eigen::Matrix3f hat(const Eigen::Vector3f& omega);
144 
145 static Eigen::Matrix3f exp_and_theta(const Eigen::Vector3f& omega, float& theta);
146 
160 static Eigen::Matrix4f exp(const Eigen::Matrix<float, 6, 1>& a);
161 
162 
163 
164 } // namespace math
165 } // namespace se
166 
167 
168 
169 #include "impl/math_util_impl.hpp"
170 
171 
172 
173 #endif // SE_MATH_UTIL_HPP
static constexpr Scalar sq(Scalar a)
static Eigen::Matrix3f to_inverse_rotation(const Eigen::Matrix4f &T)
static Eigen::Matrix3f to_rotation(const Eigen::Matrix4f &T)
static Eigen::Vector3f plane_normal(const Eigen::Vector3f &p1, const Eigen::Vector3f &p2, const Eigen::Vector3f &p3)
Compute the normal vector of a plane defined by 3 points.
static std::enable_if< std::is_arithmetic< T >::value, T >::type clamp(const T &f, const T &a, const T &b)
static Eigen::Matrix3f exp_and_theta(const Eigen::Vector3f &omega, float &theta)
static Eigen::Matrix4f exp(const Eigen::Matrix< float, 6, 1 > &a)
Group exponential.
static Eigen::Matrix3f hat(const Eigen::Vector3f &omega)
hat-operator
static T almost_median(std::vector< T > &data)
Compute the median of the data in the vector.
static T median(std::vector< T > &data)
Compute the median of the data in the vector.
static Eigen::Vector3f to_translation(const Eigen::Matrix4f &T)
static T fracf(const T &v)
static T fabs(const T &v)
static unsigned power_two_up(const float x)
static bool in(const Scalar v, const Scalar a, const Scalar b)
static Eigen::Vector3f to_inverse_translation(const Eigen::Matrix4f &T)
static Eigen::Matrix4f to_transformation(const Eigen::Vector3f &t)
static Eigen::Matrix4f to_inverse_transformation(const Eigen::Matrix4f &T)
Helper wrapper to allocate and de-allocate octants in the octree.
Definition: colour_utils.hpp:17
constexpr bool is_power_of_two< unsigned >(const unsigned x)
static constexpr Scalar cu(Scalar a)
constexpr int log2_const(int n)
static T floorf(const T &v)
constexpr bool is_power_of_two(T)