/usr/include/tf2_eigen/tf2_eigen.h is in libtf2-eigen-dev 0.5.12-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | /*
* Copyright (c) Koji Terada
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/** \author Koji Terada */
#ifndef TF2_EIGEN_H
#define TF2_EIGEN_H
#include <tf2/convert.h>
#include <Eigen/Geometry>
#include <geometry_msgs/PointStamped.h>
#include <geometry_msgs/PoseStamped.h>
namespace tf2
{
Eigen::Affine3d transformToEigen(const geometry_msgs::TransformStamped& t) {
return Eigen::Affine3d(Eigen::Translation3d(t.transform.translation.x, t.transform.translation.y, t.transform.translation.z)
* Eigen::Quaterniond(t.transform.rotation.w,
t.transform.rotation.x, t.transform.rotation.y, t.transform.rotation.z));
}
// this method needs to be implemented by client library developers
template <>
void doTransform(const tf2::Stamped<Eigen::Vector3d>& t_in,
tf2::Stamped<Eigen::Vector3d>& t_out,
const geometry_msgs::TransformStamped& transform) {
t_out = tf2::Stamped<Eigen::Vector3d>(transformToEigen(transform) * t_in,
transform.header.stamp,
transform.header.frame_id);
}
//convert to vector message
geometry_msgs::PointStamped toMsg(const tf2::Stamped<Eigen::Vector3d>& in)
{
geometry_msgs::PointStamped msg;
msg.header.stamp = in.stamp_;
msg.header.frame_id = in.frame_id_;
msg.point.x = in.x();
msg.point.y = in.y();
msg.point.z = in.z();
return msg;
}
void fromMsg(const geometry_msgs::PointStamped& msg, tf2::Stamped<Eigen::Vector3d>& out) {
out.stamp_ = msg.header.stamp;
out.frame_id_ = msg.header.frame_id;
out.x() = msg.point.x;
out.y() = msg.point.y;
out.z() = msg.point.z;
}
// this method needs to be implemented by client library developers
template <>
void doTransform(const tf2::Stamped<Eigen::Affine3d>& t_in,
tf2::Stamped<Eigen::Affine3d>& t_out,
const geometry_msgs::TransformStamped& transform) {
t_out = tf2::Stamped<Eigen::Affine3d>(transformToEigen(transform) * t_in, transform.header.stamp, transform.header.frame_id);
}
//convert to pose message
geometry_msgs::PoseStamped toMsg(const tf2::Stamped<Eigen::Affine3d>& in)
{
geometry_msgs::PoseStamped msg;
msg.header.stamp = in.stamp_;
msg.header.frame_id = in.frame_id_;
msg.pose.position.x = in.translation().x();
msg.pose.position.y = in.translation().y();
msg.pose.position.z = in.translation().z();
msg.pose.orientation.x = Eigen::Quaterniond(in.rotation()).x();
msg.pose.orientation.y = Eigen::Quaterniond(in.rotation()).y();
msg.pose.orientation.z = Eigen::Quaterniond(in.rotation()).z();
msg.pose.orientation.w = Eigen::Quaterniond(in.rotation()).w();
return msg;
}
void fromMsg(const geometry_msgs::PoseStamped& msg, tf2::Stamped<Eigen::Affine3d>& out)
{
out.stamp_ = msg.header.stamp;
out.frame_id_ = msg.header.frame_id;
out.setData(Eigen::Affine3d(Eigen::Translation3d(msg.pose.position.x, msg.pose.position.y, msg.pose.position.z)
* Eigen::Quaterniond(msg.pose.orientation.w,
msg.pose.orientation.x, msg.pose.orientation.y, msg.pose.orientation.z)));
}
} // namespace
#endif // TF2_EIGEN_H
|