Choreonoid  1.8
EigenUtil.h
Go to the documentation of this file.
1 
5 #ifndef CNOID_UTIL_EIGEN_UTIL_H
6 #define CNOID_UTIL_EIGEN_UTIL_H
7 
8 #include "EigenTypes.h"
9 #include "MathUtil.h"
10 #include <memory>
11 #include "exportdecl.h"
12 
13 namespace cnoid {
14 
15 inline Vector3 degree(const Vector3& v){ return Vector3(degree(v.x()), degree(v.y()), degree(v.z())); }
16 inline Vector3 radian(const Vector3& v){ return Vector3(radian(v.x()), radian(v.y()), radian(v.z())); }
17 
18 CNOID_EXPORT Vector3 rpyFromRot(const Matrix3& R);
19 CNOID_EXPORT Vector3 rpyFromRot(const Matrix3& R, const Vector3& prevRPY);
20 
21 CNOID_EXPORT Matrix3 rotFromRpy(double r, double p, double y);
22 
23 inline Matrix3 rotFromRpy(const Vector3& rpy) {
24  return rotFromRpy(rpy[0], rpy[1], rpy[2]);
25 }
26 
27 CNOID_EXPORT Vector3 omegaFromRot(const Matrix3& R);
28 
29 inline Matrix3 hat(const Vector3& x) {
30  Matrix3 M;
31  M << 0.0, -x(2), x(1),
32  x(2), 0.0, -x(0),
33  -x(1), x(0), 0.0;
34  return M;
35 }
36 
37 CNOID_EXPORT std::string str(const Vector3& v);
38 CNOID_EXPORT std::string str(const Vector3f& v);
39 CNOID_EXPORT std::string str(const Vector2& v);
40 CNOID_EXPORT std::string str(const AngleAxis& a);
41 CNOID_EXPORT bool toVector3(const std::string& s, Vector3& out_v);
42 CNOID_EXPORT bool toVector3(const std::string& s, Vector3f& out_v);
43 CNOID_EXPORT bool toVector6(const std::string& s, Vector6& out_v);
44 
45 CNOID_EXPORT void normalizeRotation(Matrix3& R);
46 CNOID_EXPORT void normalizeRotation(Affine3& T);
47 CNOID_EXPORT void normalizeRotation(Isometry3& T);
48 
50 {
51  Isometry3 M;
52  auto S = A.linear();
53  auto R = M.linear();
54  R.col(2) = S.col(2).normalized(); // Z
55  R.col(1) = R.col(2).cross(S.col(0).normalized()).normalized(); // Y
56  R.col(0) = R.col(1).cross(R.col(2)); // X
57  M.translation() = A.translation();
58  return M;
59 }
60 
61 template<class T, typename... Args>
62 std::shared_ptr<T> make_shared_aligned(Args&&... args)
63 {
64  return std::allocate_shared<T>(Eigen::aligned_allocator<T>(), std::forward<Args>(args)...);
65 }
66 
67 }
68 
69 #endif
cnoid::Vector2
Eigen::Vector2d Vector2
Definition: EigenTypes.h:55
cnoid::Vector3
Eigen::Vector3d Vector3
Definition: EigenTypes.h:57
cnoid::str
std::string str(const Vector3 &v)
Definition: EigenUtil.cpp:206
cnoid::Isometry3
Eigen::Isometry3d Isometry3
Definition: EigenTypes.h:73
cnoid::omegaFromRot
Vector3 omegaFromRot(const Matrix3 &R)
Definition: EigenUtil.cpp:179
cnoid::Matrix3
Eigen::Matrix3d Matrix3
Definition: EigenTypes.h:56
cnoid::AngleAxis
Eigen::AngleAxisd AngleAxis
Definition: EigenTypes.h:64
cnoid::normalizeRotation
void normalizeRotation(Matrix3 &R)
Definition: EigenUtil.cpp:270
cnoid::radian
Vector3 radian(const Vector3 &v)
Definition: EigenUtil.h:16
cnoid::toVector6
bool toVector6(const std::string &s, Vector6 &out_v)
Definition: EigenUtil.cpp:264
cnoid::hat
Matrix3 hat(const Vector3 &x)
Definition: EigenUtil.h:29
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::rpyFromRot
Vector3 rpyFromRot(const Matrix3 &R)
Definition: EigenUtil.cpp:34
cnoid::rotFromRpy
Matrix3 rotFromRpy(double r, double p, double y)
Definition: EigenUtil.cpp:16
cnoid::make_shared_aligned
std::shared_ptr< T > make_shared_aligned(Args &&... args)
Definition: EigenUtil.h:62
MathUtil.h
cnoid::Vector6
Eigen::Matrix< double, 6, 1 > Vector6
Definition: EigenTypes.h:61
EigenTypes.h
cnoid::degree
Vector3 degree(const Vector3 &v)
Definition: EigenUtil.h:15
cnoid::Affine3
Eigen::Affine3d Affine3
Definition: EigenTypes.h:62
cnoid::toVector3
bool toVector3(const std::string &s, Vector3 &out_v)
Definition: EigenUtil.cpp:252
cnoid::convertToIsometryWithOrthonormalization
Isometry3 convertToIsometryWithOrthonormalization(const Affine3 &A)
Definition: EigenUtil.h:49