29 #ifndef TF2_EIGEN__TF2_EIGEN_H_
30 #define TF2_EIGEN__TF2_EIGEN_H_
34 #include <Eigen/Geometry>
35 #include <geometry_msgs/msg/point_stamped.hpp>
36 #include <geometry_msgs/msg/pose_stamped.hpp>
37 #include <geometry_msgs/msg/quaternion_stamped.hpp>
38 #include <geometry_msgs/msg/twist.hpp>
39 #include <geometry_msgs/msg/point.hpp>
40 #include <geometry_msgs/msg/quaternion.hpp>
54 return Eigen::Isometry3d(
55 Eigen::Translation3d(t.translation.x, t.translation.y, t.translation.z) *
56 Eigen::Quaterniond(t.rotation.w, t.rotation.x, t.rotation.y, t.rotation.z));
76 geometry_msgs::msg::TransformStamped t;
77 t.transform.translation.x = T.translation().x();
78 t.transform.translation.y = T.translation().y();
79 t.transform.translation.z = T.translation().z();
81 Eigen::Quaterniond q(T.linear());
82 t.transform.rotation.x = q.x();
83 t.transform.rotation.y = q.y();
84 t.transform.rotation.z = q.z();
85 t.transform.rotation.w = q.w();
97 geometry_msgs::msg::TransformStamped t;
98 t.transform.translation.x = T.translation().x();
99 t.transform.translation.y = T.translation().y();
100 t.transform.translation.z = T.translation().z();
102 Eigen::Quaterniond q(T.rotation());
103 t.transform.rotation.x = q.x();
104 t.transform.rotation.y = q.y();
105 t.transform.rotation.z = q.z();
106 t.transform.rotation.w = q.w();
123 const Eigen::Vector3d & t_in,
124 Eigen::Vector3d & t_out,
125 const geometry_msgs::msg::TransformStamped & transform)
136 geometry_msgs::msg::Point
toMsg(
const Eigen::Vector3d & in)
138 geometry_msgs::msg::Point msg;
151 void fromMsg(
const geometry_msgs::msg::Point & msg, Eigen::Vector3d & out)
164 geometry_msgs::msg::Vector3 &
toMsg(
const Eigen::Vector3d & in, geometry_msgs::msg::Vector3 & out)
178 void fromMsg(
const geometry_msgs::msg::Vector3 & msg, Eigen::Vector3d & out)
196 const geometry_msgs::msg::TransformStamped & transform)
201 transform.header.frame_id);
212 geometry_msgs::msg::PointStamped msg;
215 msg.point =
toMsg(
static_cast<const Eigen::Vector3d &
>(in));
229 fromMsg(msg.point,
static_cast<Eigen::Vector3d &
>(out));
244 const Eigen::Affine3d & t_in,
245 Eigen::Affine3d & t_out,
246 const geometry_msgs::msg::TransformStamped & transform)
254 const Eigen::Isometry3d & t_in,
255 Eigen::Isometry3d & t_out,
256 const geometry_msgs::msg::TransformStamped & transform)
267 geometry_msgs::msg::Quaternion
toMsg(
const Eigen::Quaterniond & in)
269 geometry_msgs::msg::Quaternion msg;
283 void fromMsg(
const geometry_msgs::msg::Quaternion & msg, Eigen::Quaterniond & out)
285 out = Eigen::Quaterniond(msg.w, msg.x, msg.y, msg.z);
300 const Eigen::Quaterniond & t_in,
301 Eigen::Quaterniond & t_out,
302 const geometry_msgs::msg::TransformStamped & transform)
304 Eigen::Quaterniond t;
305 fromMsg(transform.transform.rotation, t);
317 geometry_msgs::msg::QuaternionStamped msg;
320 msg.quaternion =
toMsg(
static_cast<const Eigen::Quaterniond &
>(in));
334 fromMsg(msg.quaternion,
static_cast<Eigen::Quaterniond &
>(out));
348 const geometry_msgs::msg::TransformStamped & transform)
350 t_out.
frame_id_ = transform.header.frame_id;
353 static_cast<const Eigen::Quaterniond &
>(t_in),
354 static_cast<Eigen::Quaterniond &
>(t_out), transform);
363 geometry_msgs::msg::Pose
toMsg(
const Eigen::Affine3d & in)
365 geometry_msgs::msg::Pose msg;
366 msg.position.x = in.translation().x();
367 msg.position.y = in.translation().y();
368 msg.position.z = in.translation().z();
369 Eigen::Quaterniond q(in.linear());
370 msg.orientation.x = q.x();
371 msg.orientation.y = q.y();
372 msg.orientation.z = q.z();
373 msg.orientation.w = q.w();
383 geometry_msgs::msg::Pose
toMsg(
const Eigen::Isometry3d & in)
385 geometry_msgs::msg::Pose msg;
386 msg.position.x = in.translation().x();
387 msg.position.y = in.translation().y();
388 msg.position.z = in.translation().z();
389 Eigen::Quaterniond q(in.linear());
390 msg.orientation.x = q.x();
391 msg.orientation.y = q.y();
392 msg.orientation.z = q.z();
393 msg.orientation.w = q.w();
405 geometry_msgs::msg::Vector3
toMsg2(
const Eigen::Vector3d & in)
407 geometry_msgs::msg::Vector3 msg;
420 void fromMsg(
const geometry_msgs::msg::Pose & msg, Eigen::Affine3d & out)
422 out = Eigen::Affine3d(
423 Eigen::Translation3d(msg.position.x, msg.position.y, msg.position.z) *
437 void fromMsg(
const geometry_msgs::msg::Pose & msg, Eigen::Isometry3d & out)
439 out = Eigen::Isometry3d(
440 Eigen::Translation3d(msg.position.x, msg.position.y, msg.position.z) *
454 geometry_msgs::msg::Twist
toMsg(
const Eigen::Matrix<double, 6, 1> & in)
456 geometry_msgs::msg::Twist msg;
457 msg.linear.x = in[0];
458 msg.linear.y = in[1];
459 msg.linear.z = in[2];
460 msg.angular.x = in[3];
461 msg.angular.y = in[4];
462 msg.angular.z = in[5];
472 void fromMsg(
const geometry_msgs::msg::Twist & msg, Eigen::Matrix<double, 6, 1> & out)
474 out[0] = msg.linear.x;
475 out[1] = msg.linear.y;
476 out[2] = msg.linear.z;
477 out[3] = msg.angular.x;
478 out[4] = msg.angular.y;
479 out[5] = msg.angular.z;
496 const geometry_msgs::msg::TransformStamped & transform)
500 transform.header.stamp), transform.header.frame_id);
517 const geometry_msgs::msg::TransformStamped & transform)
521 transform.header.stamp), transform.header.frame_id);
532 geometry_msgs::msg::PoseStamped msg;
535 msg.pose =
toMsg(
static_cast<const Eigen::Affine3d &
>(in));
542 geometry_msgs::msg::PoseStamped msg;
545 msg.pose =
toMsg(
static_cast<const Eigen::Isometry3d &
>(in));
559 fromMsg(msg.pose,
static_cast<Eigen::Affine3d &
>(out));
567 fromMsg(msg.pose,
static_cast<Eigen::Isometry3d &
>(out));
584 geometry_msgs::msg::Pose
toMsg(
const Eigen::Affine3d & in)
590 geometry_msgs::msg::Pose
toMsg(
const Eigen::Isometry3d & in)
596 void fromMsg(
const geometry_msgs::msg::Point & msg, Eigen::Vector3d & out)
602 geometry_msgs::msg::Point
toMsg(
const Eigen::Vector3d & in)
608 void fromMsg(
const geometry_msgs::msg::Pose & msg, Eigen::Affine3d & out)
614 void fromMsg(
const geometry_msgs::msg::Pose & msg, Eigen::Isometry3d & out)
620 geometry_msgs::msg::Quaternion
toMsg(
const Eigen::Quaterniond & in)
626 geometry_msgs::msg::Twist
toMsg(
const Eigen::Matrix<double, 6, 1> & in)
632 void fromMsg(
const geometry_msgs::msg::Twist & msg, Eigen::Matrix<double, 6, 1> & out)
639 #endif // TF2_EIGEN__TF2_EIGEN_H_