eigen_kdl.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2009, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include <eigen_conversions/eigen_kdl.h>
00031 
00032 namespace tf {
00033 
00034 void quaternionKDLToEigen(const KDL::Rotation &k, Eigen::Quaterniond &e)
00035 {
00036   // // is it faster to do this?
00037   k.GetQuaternion(e.x(), e.y(), e.z(), e.w());
00038   
00039   // or this?
00040   //double x, y, z, w;
00041   //k.GetQuaternion(x, y, z, w);
00042   //e = Eigen::Quaterniond(w, x, y, z);
00043 }
00044 
00045 void quaternionEigenToKDL(const Eigen::Quaterniond &e, KDL::Rotation &k)
00046 {
00047   k = KDL::Rotation::Quaternion(e.x(), e.y(), e.z(), e.w());  
00048 }
00049 
00050 namespace {
00051   template<typename T>
00052   void transformKDLToEigenImpl(const KDL::Frame &k, T &e)
00053   {
00054     // translation
00055     for (unsigned int i = 0; i < 3; ++i)
00056       e(i, 3) = k.p[i];
00057 
00058     // rotation matrix
00059     for (unsigned int i = 0; i < 9; ++i)
00060       e(i/3, i%3) = k.M.data[i];
00061 
00062     // "identity" row
00063     e(3,0) = 0.0;
00064     e(3,1) = 0.0;
00065     e(3,2) = 0.0;
00066     e(3,3) = 1.0;
00067   }
00068 
00069   template<typename T>
00070   void transformEigenToKDLImpl(const T &e, KDL::Frame &k)
00071   {
00072     for (unsigned int i = 0; i < 3; ++i)
00073       k.p[i] = e(i, 3);
00074     for (unsigned int i = 0; i < 9; ++i)
00075       k.M.data[i] = e(i/3, i%3);
00076   }
00077 
00078 }
00079 
00080 void transformKDLToEigen(const KDL::Frame &k, Eigen::Affine3d &e)
00081 {
00082   transformKDLToEigenImpl(k, e);
00083 }
00084 
00085 void transformKDLToEigen(const KDL::Frame &k, Eigen::Isometry3d &e)
00086 {
00087   transformKDLToEigenImpl(k, e);
00088 }
00089 
00090 void transformEigenToKDL(const Eigen::Affine3d &e, KDL::Frame &k)
00091 {
00092   transformEigenToKDLImpl(e, k);
00093 }
00094 
00095 void transformEigenToKDL(const Eigen::Isometry3d &e, KDL::Frame &k)
00096 {
00097   transformEigenToKDLImpl(e, k);
00098 }
00099 
00100 void twistEigenToKDL(const Eigen::Matrix<double, 6, 1> &e, KDL::Twist &k)
00101 {
00102   for(int i = 0; i < 6; ++i)
00103     k[i] = e[i];
00104 }
00105 
00106 void twistKDLToEigen(const KDL::Twist &k, Eigen::Matrix<double, 6, 1> &e)
00107 {
00108   for(int i = 0; i < 6; ++i)
00109     e[i] = k[i];
00110 }
00111 
00112 void vectorEigenToKDL(const Eigen::Matrix<double, 3, 1> &e, KDL::Vector &k)
00113 {
00114   for(int i = 0; i < 3; ++i)
00115     k[i] = e[i];
00116 }
00117 void vectorKDLToEigen(const KDL::Vector &k, Eigen::Matrix<double, 3, 1> &e)
00118 {
00119   for(int i = 0; i < 3; ++i)
00120     e[i] = k[i];
00121 }
00122 
00123 void wrenchKDLToEigen(const KDL::Wrench &k, Eigen::Matrix<double, 6, 1> &e)
00124 {
00125   for(int i = 0; i < 6; ++i)
00126     e[i] = k[i];
00127 }
00128 
00129 void wrenchEigenToKDL(const Eigen::Matrix<double, 6, 1> &e, KDL::Wrench &k)
00130 {
00131   for(int i = 0; i < 6; ++i)
00132     k[i] = e[i];
00133 }
00134 
00135 
00136 } // namespace


eigen_conversions
Author(s): Stuart Glaser, Adam Leeper
autogenerated on Mon Jul 9 2018 02:37:25