geometry.cpp
Go to the documentation of this file.
1 
4 /*****************************************************************************
5 ** Includes
6 *****************************************************************************/
7 
8 #include <Eigen/Geometry>
9 #include "../../include/sophus_ros_conversions/eigen.hpp"
10 #include "../../include/sophus_ros_conversions/geometry.hpp"
11 
12 /*****************************************************************************
13 ** Namespaces
14 *****************************************************************************/
15 
16 namespace sophus_ros_conversions {
17 
18 /*****************************************************************************
19 ** Implementation
20 *****************************************************************************/
21 
22 void poseMsgToSophus(const geometry_msgs::Pose &pose, Sophus::SE3f &se3)
23 {
24  Eigen::Quaternion<Sophus::SE3f::Scalar> orientation;
25  Sophus::SE3f::Point translation;
26  pointMsgToEigen(pose.position, translation);
27  quaternionMsgToEigen(pose.orientation, orientation);
28  se3 = Sophus::SE3f(orientation, translation); // TODO faster way to set this than reconstructing
29 }
30 
31 geometry_msgs::Pose sophusToPoseMsg(const Sophus::SE3f& s) {
32  geometry_msgs::Pose pose;
33  Eigen::Vector3f translation = s.translation();
34  pose.position = eigenToPointMsg(translation);
35  Eigen::Quaternionf quaternion = s.unit_quaternion();
36  pose.orientation = eigenToQuaternionMsg(quaternion);
37  return pose;
38 }
39 
40 // Sophus uses SE3f::Point as the translation type in the constructors of SE3f types.
41 void vector3MsgToSophus(const geometry_msgs::Vector3 &v, Sophus::SE3f::Point &translation)
42 {
43  translation << v.x, v.y, v.z;
44 }
45 
46 
47 void transformMsgToSophus(const geometry_msgs::Transform &transform, Sophus::SE3f &se3)
48 {
49  Sophus::SE3f::Point translation;
50  Eigen::Quaternion<Sophus::SE3f::Scalar> orientation;
51  vector3MsgToSophus(transform.translation, translation);
52  quaternionMsgToEigen(transform.rotation, orientation);
53  se3 = Sophus::SE3f(orientation, translation); // TODO faster way to set this than reconstructing
54 }
55 
56 Sophus::SE3f transformMsgToSophus(const geometry_msgs::Transform &transform)
57 {
58  Sophus::SE3f T;
59  transformMsgToSophus(transform, T);
60  return T;
61 }
62 
63 geometry_msgs::Transform sophusToTransformMsg(const Sophus::SE3f& se3) {
64  geometry_msgs::Transform msg;
65  msg.translation.x = se3.translation().x();
66  msg.translation.y = se3.translation().y();
67  msg.translation.z = se3.translation().z();
68  msg.rotation.x = se3.unit_quaternion().x();
69  msg.rotation.y = se3.unit_quaternion().y();
70  msg.rotation.z = se3.unit_quaternion().z();
71  msg.rotation.w = se3.unit_quaternion().w();
72  return msg;
73 }
74 
75 /*****************************************************************************
76  ** Trailers
77  *****************************************************************************/
78 
79 } // namespace sophus_ros_conversions
geometry_msgs::Transform sophusToTransformMsg(const Sophus::SE3f &se3)
Definition: geometry.cpp:63
geometry_msgs::Point eigenToPointMsg(Eigen::Vector3f &e)
Definition: eigen.cpp:41
void transformMsgToSophus(const geometry_msgs::Transform &transform, Sophus::SE3f &se3)
Definition: geometry.cpp:47
geometry_msgs::Quaternion eigenToQuaternionMsg(Eigen::Quaternionf &e)
Definition: eigen.cpp:49
void quaternionMsgToEigen(const geometry_msgs::Quaternion &m, Eigen::Quaternionf &e)
Definition: eigen.cpp:27
geometry_msgs::Pose sophusToPoseMsg(const Sophus::SE3f &s)
Definition: geometry.cpp:31
void pointMsgToEigen(const geometry_msgs::Point &m, Eigen::Vector3f &e)
Definition: eigen.cpp:20
void poseMsgToSophus(const geometry_msgs::Pose &p, Sophus::SE3f &s)
Definition: geometry.cpp:22
void vector3MsgToSophus(const geometry_msgs::Vector3 &v, Sophus::SE3f::Point &translation)
Definition: geometry.cpp:41


sophus_ros_conversions
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 15:07:04