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


eigenpy
Author(s): Justin Carpentier, Nicolas Mansard
autogenerated on Sat Nov 2 2024 02:14:45