pinocchio  3.7.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
 
Loading...
Searching...
No Matches
symmetric3.hpp
1//
2// Copyright (c) 2022 INRIA
3//
4
5#ifndef __pinocchio_python_spatial_symmetric3_hpp__
6#define __pinocchio_python_spatial_symmetric3_hpp__
7
8#include <eigenpy/exception.hpp>
9#include <eigenpy/memory.hpp>
10#include <eigenpy/eigen-to-python.hpp>
11#include <boost/python/tuple.hpp>
12
13#include "pinocchio/spatial/symmetric3.hpp"
14
15#include "pinocchio/bindings/python/utils/cast.hpp"
16#include "pinocchio/bindings/python/utils/copyable.hpp"
17#include "pinocchio/bindings/python/utils/printable.hpp"
18
19namespace pinocchio
20{
21 namespace python
22 {
23 namespace bp = boost::python;
24
25 template<typename Symmetric3>
26 struct Symmetric3PythonVisitor
27 : public boost::python::def_visitor<Symmetric3PythonVisitor<Symmetric3>>
28 {
29 enum
30 {
31 Options = Symmetric3::Options
32 };
33 typedef typename Symmetric3::Scalar Scalar;
34 typedef typename Symmetric3::Vector3 Vector3;
35 typedef typename Symmetric3::Vector6 Vector6;
36 typedef typename Symmetric3::Matrix3 Matrix3;
37 typedef typename Symmetric3::Matrix2 Matrix2;
38 typedef typename Symmetric3::Matrix32 Matrix32;
39
40 typedef Eigen::Matrix<Scalar, 3, 1, Options> Vector3Like;
41 typedef Eigen::Matrix<Scalar, 3, 3, Options> Matrix3Like;
42 typedef typename Symmetric3::SkewSquare SkewSquare;
43 typedef typename Symmetric3::AlphaSkewSquare AlphaSkewSquare;
44
45 public:
46 template<class PyClass>
47 void visit(PyClass & cl) const
48 {
49 static const Scalar dummy_precision = Eigen::NumTraits<Scalar>::dummy_precision();
50 PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH
51 PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_SELF_ASSIGN_OVERLOADED
52 cl.def(bp::init<>((bp::arg("self")), "Default constructor."))
53 .def(bp::init<const Matrix3 &>(
54 (bp::arg("self"), bp::arg("I")), "Initialize from symmetrical matrix I of size 3x3."))
55 .def(bp::init<const Vector6 &>(
56 (bp::arg("self"), bp::arg("I")), "Initialize from vector I of size 6."))
57 .def(bp::init<
58 const Scalar &, const Scalar &, const Scalar &, const Scalar &, const Scalar &,
59 const Scalar &>(
60 (bp::arg("self"), bp::arg("a0"), bp::arg("a1"), bp::arg("a2"), bp::arg("a3"),
61 bp::arg("a4"), bp::arg("a5")),
62 "Initialize from 6 scalar values."))
63 .def(
64 bp::init<const Symmetric3 &>((bp::arg("self"), bp::arg("other")), "Copy constructor."))
65 .def("Zero", &Symmetric3::Zero, "Returns a zero 3x3 matrix.")
66 .staticmethod("Zero")
67 .def(
68 "setZero", &Symmetric3::setZero, bp::arg("self"),
69 "Set all the components of *this to zero.")
70 .def("Random", &Symmetric3::Random, "Returns a random symmetric 3x3 matrix.")
71 .staticmethod("Random")
72 .def(
73 "setRandom", &Symmetric3::setRandom, bp::arg("self"),
74 "Set all the components of *this randomly.")
75 .def("Identity", &Symmetric3::Identity, "Returns identity matrix.")
76 .staticmethod("Identity")
77 .def(
78 "setIdentity", &Symmetric3::setIdentity, bp::arg("self"),
79 "Set the components of *this to identity.")
80#ifndef PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS
81 .def(bp::self == bp::self)
82 .def(bp::self != bp::self)
83#endif
84#ifndef PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS
85 .def(
86 "isApprox", &Symmetric3::isApprox,
87 (bp::arg("self"), bp::arg("other"), bp::arg("prec") = dummy_precision),
88 "Returns true if *this is approximately equal to other, within the precision given "
89 "by prec.")
90 .def(
91 "isZero", &Symmetric3::isZero, (bp::arg("self"), bp::arg("prec") = dummy_precision),
92 "Returns true if *this is approximately equal to the zero matrix, within the "
93 "precision given by prec.")
94#endif
95 .def(
96 "setDiagonal", &Symmetric3::template setDiagonal<Vector3Like>, bp::args("self", "diag"),
97 "Set the diagonal elements of 3x3 matrix.")
98 .def(
99 "inverse", &Symmetric3::template inverse<Matrix3Like>, bp::args("self", "res"),
100 "Invert the symmetrical 3x3 matrix.")
101 .def("fill", &Symmetric3::fill, bp::args("self", "value"))
102 .def(bp::self - bp::other<SkewSquare>())
103 .def(bp::self -= bp::other<SkewSquare>())
104 .def(bp::self - bp::other<AlphaSkewSquare>())
105 .def(bp::self -= bp::other<AlphaSkewSquare>())
106 .add_property(
107 "data", &Symmetric3PythonVisitor::getData, &Symmetric3PythonVisitor::setData,
108 "6D vector containing the data of the symmetric 3x3 matrix.")
109 .def(
110 "matrix", &Symmetric3::matrix, bp::arg("self"),
111 "Returns a matrix representation of the data.")
112 .def("vtiv", &Symmetric3::vtiv, bp::args("self", "v"))
113 .def(
114 "vxs", &Symmetric3::template vxs<Vector3>, bp::args("v", "S3"),
115 "Performs the operation \f$ M = [v]_{\times} S_{3} \f$., Apply the cross product of "
116 "v on each column of S and return result matrix M.")
117 .staticmethod("vxs")
118 .def(
119 "svx", &Symmetric3::template vxs<Vector3>, bp::args("v", "S3"),
120 "Performs the operation \f$ M = S_{3} [v]_{\times} \f$.")
121 .staticmethod("svx")
122 .def(
123 "rhsMult", &Symmetric3::template rhsMult<Vector3, Vector3>,
124 bp::args("SE3", "vin", "vout"))
125 .staticmethod("rhsMult")
126
127 .def(bp::self + bp::self)
128 .def(bp::self += bp::self)
129 .def(bp::self - bp::self)
130 .def(bp::self -= bp::self)
131 .def(bp::self *= bp::other<Scalar>())
132 .def(bp::self * bp::other<Vector3Like>())
133 .def(bp::self - bp::other<Matrix3Like>())
134 .def(bp::self + bp::other<Matrix3Like>())
135
136 .def(
137 "decomposeltI", &Symmetric3::decomposeltI, bp::arg("self"),
138 "Computes L for a symmetric matrix S.")
139 .def(
140 "rotate", &Symmetric3::template rotate<Matrix3>, bp::args("self", "R"),
141 "Computes R*S*R'")
142
143#ifndef PINOCCHIO_PYTHON_NO_SERIALIZATION
144 .def_pickle(Pickle())
145#endif
146 ;
147 PINOCCHIO_COMPILER_DIAGNOSTIC_POP
148 }
149
150 static Vector6 getData(const Symmetric3 & self)
151 {
152 return self.data();
153 }
154 static void setData(Symmetric3 & self, Vector6 data)
155 {
156 self.data() = data;
157 }
158
159 static void expose()
160 {
161 bp::class_<Symmetric3>(
162 "Symmetric3",
163 "This class represents symmetric 3x3 matrices.\n\n"
164 "Supported operations ...",
165 bp::no_init)
166 .def(Symmetric3PythonVisitor<Symmetric3>())
167 .def(CastVisitor<Symmetric3>())
168 .def(ExposeConstructorByCastVisitor<Symmetric3, ::pinocchio::Symmetric3>())
169 .def(CopyableVisitor<Symmetric3>())
170 .def(PrintableVisitor<Symmetric3>());
171 }
172
173 private:
174 struct Pickle : bp::pickle_suite
175 {
176 static boost::python::tuple getinitargs(const Symmetric3 & I)
177 {
178 return bp::make_tuple(I);
179 }
180 };
181
182 }; // struct Symmetric3PythonVisitor
183
184 } // namespace python
185} // namespace pinocchio
186
187#endif // __pinocchio_python_spatial_symmetric3_hpp__
Matrix32 decomposeltI() const
Computes L for a symmetric matrix A.
Main pinocchio namespace.
Definition treeview.dox:11