|
5 | 5 | #ifndef __eigenpy_angle_axis_hpp__ |
6 | 6 | #define __eigenpy_angle_axis_hpp__ |
7 | 7 |
|
8 | | -#include "eigenpy/eigenpy.hpp" |
9 | | - |
10 | 8 | #include <Eigen/Core> |
11 | 9 | #include <Eigen/Geometry> |
12 | 10 |
|
13 | | -namespace eigenpy |
14 | | -{ |
15 | | - |
16 | | - namespace bp = boost::python; |
17 | | - |
18 | | - template<typename AngleAxis> class AngleAxisVisitor; |
19 | | - |
20 | | - template<typename Scalar> |
21 | | - struct call< Eigen::AngleAxis<Scalar> > |
22 | | - { |
23 | | - typedef Eigen::AngleAxis<Scalar> AngleAxis; |
24 | | - |
25 | | - static inline void expose() |
26 | | - { |
27 | | - AngleAxisVisitor<AngleAxis>::expose(); |
28 | | - } |
29 | | - |
30 | | - static inline bool isApprox(const AngleAxis & self, const AngleAxis & other, |
31 | | - const Scalar & prec = Eigen::NumTraits<Scalar>::dummy_precision()) |
32 | | - { |
33 | | - return self.isApprox(other,prec); |
34 | | - } |
35 | | - }; |
36 | | - |
37 | | - template<typename AngleAxis> |
38 | | - class AngleAxisVisitor |
39 | | - : public bp::def_visitor< AngleAxisVisitor<AngleAxis> > |
40 | | - { |
41 | | - |
42 | | - typedef typename AngleAxis::Scalar Scalar; |
43 | | - typedef typename AngleAxis::Vector3 Vector3; |
44 | | - typedef typename AngleAxis::Matrix3 Matrix3; |
45 | | - |
46 | | - typedef typename Eigen::Quaternion<Scalar,0> Quaternion; |
47 | | - typedef Eigen::RotationBase<AngleAxis,3> RotationBase; |
48 | | - |
49 | | - BOOST_PYTHON_FUNCTION_OVERLOADS(isApproxAngleAxis_overload,call<AngleAxis>::isApprox,2,3) |
50 | | - |
51 | | - public: |
52 | | - |
53 | | - template<class PyClass> |
54 | | - void visit(PyClass& cl) const |
55 | | - { |
56 | | - cl |
57 | | - .def(bp::init<>(bp::arg("self"),"Default constructor")) |
58 | | - .def(bp::init<Scalar,Vector3> |
59 | | - ((bp::arg("self"),bp::arg("angle"),bp::arg("axis")), |
| 11 | +#include "eigenpy/eigenpy.hpp" |
| 12 | + |
| 13 | +namespace eigenpy { |
| 14 | + |
| 15 | +namespace bp = boost::python; |
| 16 | + |
| 17 | +template <typename AngleAxis> |
| 18 | +class AngleAxisVisitor; |
| 19 | + |
| 20 | +template <typename Scalar> |
| 21 | +struct call<Eigen::AngleAxis<Scalar> > { |
| 22 | + typedef Eigen::AngleAxis<Scalar> AngleAxis; |
| 23 | + |
| 24 | + static inline void expose() { AngleAxisVisitor<AngleAxis>::expose(); } |
| 25 | + |
| 26 | + static inline bool isApprox( |
| 27 | + const AngleAxis& self, const AngleAxis& other, |
| 28 | + const Scalar& prec = Eigen::NumTraits<Scalar>::dummy_precision()) { |
| 29 | + return self.isApprox(other, prec); |
| 30 | + } |
| 31 | +}; |
| 32 | + |
| 33 | +template <typename AngleAxis> |
| 34 | +class AngleAxisVisitor : public bp::def_visitor<AngleAxisVisitor<AngleAxis> > { |
| 35 | + typedef typename AngleAxis::Scalar Scalar; |
| 36 | + typedef typename AngleAxis::Vector3 Vector3; |
| 37 | + typedef typename AngleAxis::Matrix3 Matrix3; |
| 38 | + |
| 39 | + typedef typename Eigen::Quaternion<Scalar, 0> Quaternion; |
| 40 | + typedef Eigen::RotationBase<AngleAxis, 3> RotationBase; |
| 41 | + |
| 42 | + BOOST_PYTHON_FUNCTION_OVERLOADS(isApproxAngleAxis_overload, |
| 43 | + call<AngleAxis>::isApprox, 2, 3) |
| 44 | + |
| 45 | + public: |
| 46 | + template <class PyClass> |
| 47 | + void visit(PyClass& cl) const { |
| 48 | + cl.def(bp::init<>(bp::arg("self"), "Default constructor")) |
| 49 | + .def(bp::init<Scalar, Vector3>( |
| 50 | + (bp::arg("self"), bp::arg("angle"), bp::arg("axis")), |
60 | 51 | "Initialize from angle and axis.")) |
61 | | - .def(bp::init<Matrix3> |
62 | | - ((bp::arg("self"),bp::arg("R")), |
63 | | - "Initialize from a rotation matrix")) |
64 | | - .def(bp::init<Quaternion>((bp::arg("self"),bp::arg("quaternion")), |
65 | | - "Initialize from a quaternion.")) |
66 | | - .def(bp::init<AngleAxis>((bp::arg("self"),bp::arg("copy")), |
67 | | - "Copy constructor.")) |
68 | | - |
69 | | - /* --- Properties --- */ |
70 | | - .add_property("axis", |
71 | | - bp::make_function((Vector3 & (AngleAxis::*)())&AngleAxis::axis, |
72 | | - bp::return_internal_reference<>()), |
73 | | - &AngleAxisVisitor::setAxis,"The rotation axis.") |
74 | | - .add_property("angle", |
75 | | - (Scalar (AngleAxis::*)()const)&AngleAxis::angle, |
76 | | - &AngleAxisVisitor::setAngle,"The rotation angle.") |
77 | | - |
78 | | - /* --- Methods --- */ |
79 | | - .def("inverse",&AngleAxis::inverse, |
80 | | - bp::arg("self"), |
81 | | - "Return the inverse rotation.") |
82 | | - .def("fromRotationMatrix",&AngleAxis::template fromRotationMatrix<Matrix3>, |
83 | | - (bp::arg("self"),bp::arg("rotation matrix")), |
84 | | - "Sets *this from a 3x3 rotation matrix", |
85 | | - bp::return_self<>()) |
86 | | - .def("toRotationMatrix", |
87 | | - &AngleAxis::toRotationMatrix, |
88 | | -// bp::arg("self"), |
89 | | - "Constructs and returns an equivalent rotation matrix.") |
90 | | - .def("matrix",&AngleAxis::matrix, |
91 | | - bp::arg("self"), |
92 | | - "Returns an equivalent rotation matrix.") |
93 | | - |
94 | | - .def("isApprox", |
95 | | - &call<AngleAxis>::isApprox, |
96 | | - isApproxAngleAxis_overload(bp::args("self","other","prec"), |
97 | | - "Returns true if *this is approximately equal to other, within the precision determined by prec.")) |
98 | | - |
99 | | - /* --- Operators --- */ |
100 | | - .def(bp::self * bp::other<Vector3>()) |
101 | | - .def(bp::self * bp::other<Quaternion>()) |
102 | | - .def(bp::self * bp::self) |
103 | | - .def("__eq__",&AngleAxisVisitor::__eq__) |
104 | | - .def("__ne__",&AngleAxisVisitor::__ne__) |
105 | | - |
106 | | - .def("__str__",&print) |
107 | | - .def("__repr__",&print) |
108 | | - ; |
109 | | - } |
110 | | - |
111 | | - private: |
112 | | - |
113 | | - static void setAxis(AngleAxis & self, const Vector3 & axis) |
114 | | - { self.axis() = axis; } |
115 | | - |
116 | | - static void setAngle( AngleAxis & self, const Scalar & angle) |
117 | | - { self.angle() = angle; } |
118 | | - |
119 | | - static bool __eq__(const AngleAxis & u, const AngleAxis & v) |
120 | | - { return u.axis() == v.axis() && v.angle() == u.angle(); } |
121 | | - |
122 | | - static bool __ne__(const AngleAxis & u, const AngleAxis & v) |
123 | | - { return !__eq__(u,v); } |
124 | | - |
125 | | - static std::string print(const AngleAxis & self) |
126 | | - { |
127 | | - std::stringstream ss; |
128 | | - ss << "angle: " << self.angle() << std::endl; |
129 | | - ss << "axis: " << self.axis().transpose() << std::endl; |
130 | | - |
131 | | - return ss.str(); |
132 | | - } |
133 | | - |
134 | | - public: |
135 | | - |
136 | | - static void expose() |
137 | | - { |
138 | | - bp::class_<AngleAxis>("AngleAxis", |
139 | | - "AngleAxis representation of a rotation.\n\n", |
140 | | - bp::no_init) |
141 | | - .def(AngleAxisVisitor<AngleAxis>()); |
142 | | - |
143 | | - // Cast to Eigen::RotationBase |
144 | | - bp::implicitly_convertible<AngleAxis,RotationBase>(); |
145 | | - } |
146 | | - |
147 | | - }; |
148 | | - |
149 | | -} // namespace eigenpy |
150 | | - |
151 | | -#endif //ifndef __eigenpy_angle_axis_hpp__ |
| 52 | + .def(bp::init<Matrix3>((bp::arg("self"), bp::arg("R")), |
| 53 | + "Initialize from a rotation matrix")) |
| 54 | + .def(bp::init<Quaternion>((bp::arg("self"), bp::arg("quaternion")), |
| 55 | + "Initialize from a quaternion.")) |
| 56 | + .def(bp::init<AngleAxis>((bp::arg("self"), bp::arg("copy")), |
| 57 | + "Copy constructor.")) |
| 58 | + |
| 59 | + /* --- Properties --- */ |
| 60 | + .add_property( |
| 61 | + "axis", |
| 62 | + bp::make_function((Vector3 & (AngleAxis::*)()) & AngleAxis::axis, |
| 63 | + bp::return_internal_reference<>()), |
| 64 | + &AngleAxisVisitor::setAxis, "The rotation axis.") |
| 65 | + .add_property("angle", |
| 66 | + (Scalar(AngleAxis::*)() const) & AngleAxis::angle, |
| 67 | + &AngleAxisVisitor::setAngle, "The rotation angle.") |
| 68 | + |
| 69 | + /* --- Methods --- */ |
| 70 | + .def("inverse", &AngleAxis::inverse, bp::arg("self"), |
| 71 | + "Return the inverse rotation.") |
| 72 | + .def("fromRotationMatrix", |
| 73 | + &AngleAxis::template fromRotationMatrix<Matrix3>, |
| 74 | + (bp::arg("self"), bp::arg("rotation matrix")), |
| 75 | + "Sets *this from a 3x3 rotation matrix", bp::return_self<>()) |
| 76 | + .def("toRotationMatrix", &AngleAxis::toRotationMatrix, |
| 77 | + // bp::arg("self"), |
| 78 | + "Constructs and returns an equivalent rotation matrix.") |
| 79 | + .def("matrix", &AngleAxis::matrix, bp::arg("self"), |
| 80 | + "Returns an equivalent rotation matrix.") |
| 81 | + |
| 82 | + .def("isApprox", &call<AngleAxis>::isApprox, |
| 83 | + isApproxAngleAxis_overload( |
| 84 | + bp::args("self", "other", "prec"), |
| 85 | + "Returns true if *this is approximately equal to other, " |
| 86 | + "within the precision determined by prec.")) |
| 87 | + |
| 88 | + /* --- Operators --- */ |
| 89 | + .def(bp::self * bp::other<Vector3>()) |
| 90 | + .def(bp::self * bp::other<Quaternion>()) |
| 91 | + .def(bp::self * bp::self) |
| 92 | + .def("__eq__", &AngleAxisVisitor::__eq__) |
| 93 | + .def("__ne__", &AngleAxisVisitor::__ne__) |
| 94 | + |
| 95 | + .def("__str__", &print) |
| 96 | + .def("__repr__", &print); |
| 97 | + } |
| 98 | + |
| 99 | + private: |
| 100 | + static void setAxis(AngleAxis& self, const Vector3& axis) { |
| 101 | + self.axis() = axis; |
| 102 | + } |
| 103 | + |
| 104 | + static void setAngle(AngleAxis& self, const Scalar& angle) { |
| 105 | + self.angle() = angle; |
| 106 | + } |
| 107 | + |
| 108 | + static bool __eq__(const AngleAxis& u, const AngleAxis& v) { |
| 109 | + return u.axis() == v.axis() && v.angle() == u.angle(); |
| 110 | + } |
| 111 | + |
| 112 | + static bool __ne__(const AngleAxis& u, const AngleAxis& v) { |
| 113 | + return !__eq__(u, v); |
| 114 | + } |
| 115 | + |
| 116 | + static std::string print(const AngleAxis& self) { |
| 117 | + std::stringstream ss; |
| 118 | + ss << "angle: " << self.angle() << std::endl; |
| 119 | + ss << "axis: " << self.axis().transpose() << std::endl; |
| 120 | + |
| 121 | + return ss.str(); |
| 122 | + } |
| 123 | + |
| 124 | + public: |
| 125 | + static void expose() { |
| 126 | + bp::class_<AngleAxis>( |
| 127 | + "AngleAxis", "AngleAxis representation of a rotation.\n\n", bp::no_init) |
| 128 | + .def(AngleAxisVisitor<AngleAxis>()); |
| 129 | + |
| 130 | + // Cast to Eigen::RotationBase |
| 131 | + bp::implicitly_convertible<AngleAxis, RotationBase>(); |
| 132 | + } |
| 133 | +}; |
| 134 | + |
| 135 | +} // namespace eigenpy |
| 136 | + |
| 137 | +#endif // ifndef __eigenpy_angle_axis_hpp__ |
0 commit comments