transform.cpp
Go to the documentation of this file.
00001 #include "transform_graph/transform.h"
00002 
00003 #include "Eigen/Dense"
00004 
00005 #include "eigen_conversions/eigen_msg.h"
00006 #include "geometry_msgs/Pose.h"
00007 #include "geometry_msgs/Transform.h"
00008 #include "tf/transform_datatypes.h"
00009 #include "tf_conversions/tf_eigen.h"
00010 
00011 #include "transform_graph/orientation.h"
00012 #include "transform_graph/position.h"
00013 
00014 using std::string;
00015 
00016 namespace transform_graph {
00017 Transform::Transform() : transform_(Eigen::Affine3d::Identity()) {}
00018 
00019 Transform::Transform(const transform_graph::Position& position,
00020                      const transform_graph::Orientation& orientation)
00021     : transform_(Eigen::Affine3d::Identity()) {
00022   transform_.translate(position.vector());
00023   transform_.rotate(orientation.matrix());
00024 }
00025 
00026 Transform::Transform(const tf::Transform& st)
00027     : transform_(Eigen::Affine3d::Identity()) {
00028   transform_graph::Position position(st.getOrigin());
00029   transform_graph::Orientation orientation(st.getRotation());
00030   transform_.translate(position.vector());
00031   transform_.rotate(orientation.matrix());
00032 }
00033 
00034 Transform::Transform(const geometry_msgs::Pose& p)
00035     : transform_(Eigen::Affine3d::Identity()) {
00036   tf::poseMsgToEigen(p, transform_);
00037 }
00038 
00039 Transform::Transform(const geometry_msgs::Transform& p)
00040     : transform_(Eigen::Affine3d::Identity()) {
00041   tf::transformMsgToEigen(p, transform_);
00042 }
00043 
00044 Transform::Transform(const Eigen::Affine3d& a) : transform_(a) {}
00045 
00046 Transform::Transform(const Eigen::Matrix4d& m) : transform_(m) {}
00047 
00048 Transform Transform::Identity() {
00049   Transform transform;
00050   return transform;
00051 }
00052 
00053 transform_graph::Position Transform::position() const {
00054   transform_graph::Position position(transform_.translation());
00055   return position;
00056 }
00057 
00058 transform_graph::Orientation Transform::orientation() const {
00059   transform_graph::Orientation orientation(transform_.rotation());
00060   return orientation;
00061 }
00062 
00063 tf::Transform Transform::tf_transform() const {
00064   tf::Transform tft;
00065   tf::transformEigenToTF(transform_, tft);
00066   return tft;
00067 }
00068 
00069 geometry_msgs::Pose Transform::pose() const {
00070   geometry_msgs::Pose pose;
00071   tf::poseEigenToMsg(transform_, pose);
00072   return pose;
00073 }
00074 
00075 geometry_msgs::Transform Transform::transform() const {
00076   geometry_msgs::Transform transform;
00077   tf::transformEigenToMsg(transform_, transform);
00078   return transform;
00079 }
00080 
00081 Eigen::Matrix4d Transform::matrix() const { return transform_.matrix(); }
00082 
00083 Eigen::Affine3d Transform::affine() const { return transform_; }
00084 
00085 void Transform::ToPose(geometry_msgs::Pose* pose) const {
00086   pose->position.x = transform_.translation().x();
00087   pose->position.y = transform_.translation().y();
00088   pose->position.z = transform_.translation().z();
00089   Eigen::Quaterniond q(transform_.rotation());
00090   pose->orientation.w = q.w();
00091   pose->orientation.x = q.x();
00092   pose->orientation.y = q.y();
00093   pose->orientation.z = q.z();
00094 }
00095 
00096 Transform Transform::inverse() const {
00097   return Transform(transform_.inverse(Eigen::Affine).matrix());
00098 }
00099 }  // namespace transform_graph


transform_graph
Author(s):
autogenerated on Sat Jun 8 2019 19:23:43