|
| 1 | +/* |
| 2 | + * Copyright 2018, Justin Carpentier, LAAS-CNRS |
| 3 | + * |
| 4 | + * This file is part of eigenpy. |
| 5 | + * eigenpy is free software: you can redistribute it and/or |
| 6 | + * modify it under the terms of the GNU Lesser General Public License |
| 7 | + * as published by the Free Software Foundation, either version 3 of |
| 8 | + * the License, or (at your option) any later version. |
| 9 | + * eigenpy is distributed in the hope that it will be |
| 10 | + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty |
| 11 | + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU Lesser General Public License for more details. You should |
| 13 | + * have received a copy of the GNU Lesser General Public License along |
| 14 | + * with eigenpy. If not, see <http://www.gnu.org/licenses/>. |
| 15 | + */ |
| 16 | + |
| 17 | +#ifndef __eigenpy_geometry_conversion_hpp__ |
| 18 | +#define __eigenpy_geometry_conversion_hpp__ |
| 19 | + |
| 20 | +#include <Eigen/Core> |
| 21 | +#include <Eigen/Geometry> |
| 22 | +#include <boost/python.hpp> |
| 23 | + |
| 24 | +namespace eigenpy |
| 25 | +{ |
| 26 | + |
| 27 | + namespace bp = boost::python; |
| 28 | + |
| 29 | + template<typename Scalar,int Options=0> |
| 30 | + struct EulerAnglesConvertor |
| 31 | + { |
| 32 | + |
| 33 | + typedef typename Eigen::Matrix<Scalar,3,1,Options> Vector3; |
| 34 | + typedef typename Eigen::Matrix<Scalar,3,3,Options> Matrix3; |
| 35 | + typedef typename Vector3::Index Index; |
| 36 | + |
| 37 | + typedef typename Eigen::AngleAxis<Scalar> AngleAxis; |
| 38 | + |
| 39 | + static void expose() |
| 40 | + { |
| 41 | + bp::def("toEulerAngles",&EulerAnglesConvertor::toEulerAngles, |
| 42 | + bp::args("mat (dim 3x3)","a0","a1","a2"), |
| 43 | + "It returns the Euler-angles of the rotation matrix mat using the convention defined by the triplet (a0,a1,a2)."); |
| 44 | + |
| 45 | + bp::def("fromEulerAngles",&EulerAnglesConvertor::fromEulerAngles, |
| 46 | + bp::args("ea (vector of Euler angles)","a0","a1","a2"), |
| 47 | + "It returns the rotation matrix associated to the Euler angles using the convention defined by the triplet (a0,a1,a2)."); |
| 48 | + } |
| 49 | + |
| 50 | + static Vector3 toEulerAngles(const Matrix3 & mat, |
| 51 | + Index a0, |
| 52 | + Index a1, |
| 53 | + Index a2) |
| 54 | + { |
| 55 | + return mat.eulerAngles(a0,a1,a2); |
| 56 | + } |
| 57 | + |
| 58 | + static Matrix3 fromEulerAngles(const Vector3 & ea, |
| 59 | + Index a0, |
| 60 | + Index a1, |
| 61 | + Index a2) |
| 62 | + { |
| 63 | + Matrix3 mat; |
| 64 | + mat = AngleAxis(ea[0], Vector3::Unit(a0)) |
| 65 | + * AngleAxis(ea[1], Vector3::Unit(a1)) |
| 66 | + * AngleAxis(ea[2], Vector3::Unit(a2)); |
| 67 | + return mat; |
| 68 | + } |
| 69 | + }; |
| 70 | + |
| 71 | + |
| 72 | +} // namespace eigenpy |
| 73 | + |
| 74 | +#endif // define __eigenpy_geometry_conversion_hpp__ |
0 commit comments