Skip to content

Commit 5ad5a04

Browse files
authored
Merge pull request #26 from jcarpent/devel
Add {from,to}EulerAngles convertor
2 parents f17ed9b + f0aa437 commit 5ad5a04

File tree

5 files changed

+110
-3
lines changed

5 files changed

+110
-3
lines changed

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2015-2017 LAAS-CNRS
2+
# Copyright (c) 2015-2018 LAAS-CNRS
33
#
44
# This file is part of eigenpy.
55
# eigenpy is free software: you can redistribute it and/or
@@ -94,6 +94,7 @@ SET(HEADERS
9494
fwd.hpp
9595
map.hpp
9696
geometry.hpp
97+
geometry-conversion.hpp
9798
memory.hpp
9899
registration.hpp
99100
angle-axis.hpp
@@ -126,12 +127,14 @@ SET(${PROJECT_NAME}_SOLVERS_SOURCES
126127
src/solvers/preconditioners.cpp
127128
src/solvers/solvers.cpp
128129
)
130+
129131
SET(${PROJECT_NAME}_SOURCES
130132
${${PROJECT_NAME}_SOLVERS_SOURCES}
131133
src/exception.cpp
132134
src/eigenpy.cpp
133135
src/angle-axis.cpp
134136
src/quaternion.cpp
137+
src/geometry-conversion.cpp
135138
)
136139

137140
ADD_LIBRARY(${PROJECT_NAME} SHARED ${${PROJECT_NAME}_SOURCES} ${${PROJECT_NAME}_HEADERS})

python/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright (c) 2017, Justin Carpentier, CNRS
2+
// Copyright (c) 2017-2018, Justin Carpentier, CNRS
33
//
44
// This file is part of eigenpy
55
// eigenpy is free software: you can redistribute it
@@ -30,6 +30,7 @@ BOOST_PYTHON_MODULE(eigenpy)
3030
enableEigenPy();
3131
exposeAngleAxis();
3232
exposeQuaternion();
33+
exposeGeometryConversion();
3334

3435
{
3536
boost::python::scope solvers = boost::python::class_<SolversScope>("solvers");

src/geometry-conversion.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
#include "eigenpy/memory.hpp"
18+
#include "eigenpy/geometry.hpp"
19+
#include "eigenpy/geometry-conversion.hpp"
20+
21+
namespace eigenpy
22+
{
23+
void exposeGeometryConversion()
24+
{
25+
EulerAnglesConvertor<double>::expose();
26+
}
27+
} // namespace eigenpy

src/geometry-conversion.hpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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__

src/geometry.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014, Nicolas Mansard, LAAS-CNRS
2+
* Copyright 2014-2018, Nicolas Mansard, Justin Carpentier, LAAS-CNRS
33
*
44
* This file is part of eigenpy.
55
* eigenpy is free software: you can redistribute it and/or
@@ -23,6 +23,8 @@ namespace eigenpy
2323
void exposeQuaternion();
2424
void exposeAngleAxis();
2525

26+
void exposeGeometryConversion();
27+
2628
} // namespace eigenpy
2729

2830
#endif // define __eigenpy_geometry_hpp__

0 commit comments

Comments
 (0)