Directory: | ./ |
---|---|
File: | include/multicontact-api/bindings/python/geometry/linear-cone.hpp |
Date: | 2025-03-10 16:17:01 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 59 | 70 | 84.3% |
Branches: | 76 | 164 | 46.3% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | // Copyright (c) 2015-2018, CNRS | ||
2 | // Authors: Justin Carpentier <jcarpent@laas.fr> | ||
3 | |||
4 | #ifndef __multicontact_api_python_geometry_linear_cone_hpp__ | ||
5 | #define __multicontact_api_python_geometry_linear_cone_hpp__ | ||
6 | |||
7 | #include <eigenpy/eigenpy.hpp> | ||
8 | #include <pinocchio/fwd.hpp> | ||
9 | |||
10 | #include "multicontact-api/bindings/python/serialization/archive.hpp" | ||
11 | #include "multicontact-api/geometry/linear-cone.hpp" | ||
12 | |||
13 | namespace multicontact_api { | ||
14 | namespace python { | ||
15 | |||
16 | namespace bp = boost::python; | ||
17 | |||
18 | template <typename LC> | ||
19 | struct LCPythonVisitor | ||
20 | : public boost::python::def_visitor<LCPythonVisitor<LC> > { | ||
21 | typedef bp::class_<LC> PyClass; | ||
22 | typedef LC Type; | ||
23 | |||
24 | typedef typename LC::MatrixDx MatrixDx; | ||
25 | typedef typename LC::VectorD VectorD; | ||
26 | typedef typename LC::Scalar Scalar; | ||
27 | typedef typename LC::Index Index; | ||
28 | |||
29 | template <class PyClass> | ||
30 | 12 | void visit(PyClass &cl) const { | |
31 |
1/2✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
12 | cl.def(bp::init<>("Default constructor.")) |
32 |
4/8✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 6 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
|
24 | .def(bp::init<MatrixDx>((bp::arg("rays"), "Init from a set of rays."))) |
33 |
3/6✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 6 times.
✗ Branch 8 not taken.
|
24 | .def(bp::init<Index>(bp::args("size"), "Init with a given size.")) |
34 |
3/6✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 6 times.
✗ Branch 8 not taken.
|
24 | .def(bp::init<LC>(bp::args("other"), "Copy constructor.")) |
35 | |||
36 | 24 | .add_property("size", &LC::size, "Returns the size of the set of rays.") | |
37 |
2/4✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
|
12 | .add_static_property("dim", &dim, "Dimension of the linear cone.") |
38 | |||
39 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
12 | .add_property("rays", &getRays, &setRays, |
40 | "Matrix of rays of the linear cone.") | ||
41 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
12 | .def("__str__", &toString) |
42 |
2/4✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
|
24 | .def("isApprox", |
43 | (bool(LC::*)(const LC &, const Scalar &) const) & LC::isApprox, | ||
44 | bp::args("other", "prec"), | ||
45 | "Returns true if *this is approximately equal to other, within " | ||
46 | "the precision determined by prec.") | ||
47 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
24 | .def("stack", &LC::template stack<MatrixDx>, bp::args("rays"), |
48 | "Stack new rays to the set of rays.") | ||
49 |
2/4✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
|
24 | .def("stack", &LC::template stack<Scalar, LC::Options>, |
50 | bp::args("cone"), "Stack the rays of one to the set of rays.") | ||
51 | |||
52 |
2/4✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
|
12 | .def(bp::self == bp::self) |
53 |
1/2✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
12 | .def(bp::self != bp::self); |
54 | 12 | } | |
55 | |||
56 | 12 | static PyClass &expose(const std::string &class_name, std::string doc = "") { | |
57 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
12 | if (doc.empty()) { |
58 | 12 | doc = "Linear Cone of dimension " + LC::dim; | |
59 | 12 | doc += " defined by its rays."; | |
60 | } | ||
61 | |||
62 |
3/8✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
|
12 | static PyClass cl_ = PyClass(class_name.c_str(), doc.c_str(), bp::no_init); |
63 |
2/4✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
|
12 | cl_.def(LCPythonVisitor<LC>()).def(SerializableVisitor<LC>()); |
64 | |||
65 | // Expose related matrix types | ||
66 | 12 | ENABLE_SPECIFIC_MATRIX_TYPE(MatrixDx); | |
67 | 12 | ENABLE_SPECIFIC_MATRIX_TYPE(VectorD); | |
68 | |||
69 | 12 | return cl_; | |
70 | } | ||
71 | |||
72 | protected: | ||
73 | ✗ | static std::string toString(const LC &c) { | |
74 | ✗ | std::ostringstream s; | |
75 | ✗ | s << c; | |
76 | ✗ | return s.str(); | |
77 | } | ||
78 | |||
79 | ✗ | static MatrixDx getRays(const LC &self) { return self.rays(); } | |
80 | ✗ | static void setRays(LC &self, const MatrixDx &rays) { self.rays() = rays; } | |
81 | |||
82 | ✗ | static int dim() { return LC::dim; } | |
83 | }; | ||
84 | |||
85 | template <typename ForceCone> | ||
86 | struct ForceConePythonVisitor | ||
87 | : public boost::python::def_visitor<ForceConePythonVisitor<ForceCone> > { | ||
88 | typedef typename ForceCone::Scalar Scalar; | ||
89 | typedef typename ForceCone::Vector3 Vector3; | ||
90 | typedef typename ForceCone::VectorD VectorD; | ||
91 | typedef typename ForceCone::Matrix3x Matrix3x; | ||
92 | typedef typename ForceCone::Index Index; | ||
93 | typedef typename ForceCone::WrenchCone WrenchCone; | ||
94 | |||
95 | template <class _PyClass> | ||
96 | 3 | void visit(_PyClass &cl) const { | |
97 |
1/2✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | cl.def(bp::init<>("Default constructor.")) |
98 |
3/6✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
|
3 | .def(bp::init<Matrix3x>( |
99 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
6 | (bp::arg("rays"), "Init from a matrix of rays."))) |
100 |
3/6✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
|
6 | .def(bp::init<Index>(bp::args("size"), "Init with a given size.")) |
101 |
3/6✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
|
6 | .def(bp::init<ForceCone>(bp::args("other"), "Copy constructor.")) |
102 | |||
103 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
6 | .def("SE3ActOn", &ForceCone::SE3ActOn, bp::args("M"), |
104 | "Returns the action of SE3 on *this, i.e. a WrenchCone.") | ||
105 |
2/4✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
3 | .def("toWrenchCone", &toWrenchCone, "Returns *this as a WrenchCone.") |
106 | |||
107 |
2/4✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
6 | .def("RegularCone", |
108 | (ForceCone(*)(const Scalar, const VectorD &, | ||
109 | const int))&ForceCone::RegularCone, | ||
110 | bp::args("mu", "direction", "num rays"), | ||
111 | "Generates a regular linear cone from a given number of rays, a " | ||
112 | "main direction and a friction " | ||
113 | "coefficient.") | ||
114 |
2/4✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
6 | .def("RegularCone", |
115 | (ForceCone(*)(const Scalar, const VectorD &, const int, | ||
116 | const Scalar))&ForceCone::RegularCone, | ||
117 | bp::args("mu", "direction", "num rays", "angle offset"), | ||
118 | "Generates a regular linear cone from a given number of rays, a " | ||
119 | "main direction and a friction " | ||
120 | "coefficient, with an offset on the orientation.") | ||
121 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | .staticmethod("RegularCone"); |
122 | 3 | } | |
123 | |||
124 | 3 | static void expose(const std::string &class_name) { | |
125 |
1/2✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | std::string doc = "Force Cone of dimension 3"; |
126 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | doc += " defined by its rays."; |
127 | |||
128 |
3/6✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 3 times.
✗ Branch 10 not taken.
|
3 | LCPythonVisitor<typename ForceCone::Base>::expose("LinearCone3"); |
129 | |||
130 |
1/2✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
|
3 | bp::class_<ForceCone, bp::bases<typename ForceCone::Base> >( |
131 | class_name.c_str(), doc.c_str(), bp::no_init) | ||
132 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | .def(ForceConePythonVisitor<ForceCone>()); |
133 | 3 | } | |
134 | |||
135 | ✗ | static WrenchCone toWrenchCone(const ForceCone &self) { | |
136 | ✗ | return (WrenchCone)(self); | |
137 | } | ||
138 | }; | ||
139 | |||
140 | template <typename WrenchCone> | ||
141 | struct WrenchConePythonVisitor | ||
142 | : public boost::python::def_visitor<WrenchConePythonVisitor<WrenchCone> > { | ||
143 | typedef typename WrenchCone::Matrix3x Matrix3x; | ||
144 | typedef typename WrenchCone::Matrix6x Matrix6x; | ||
145 | typedef typename WrenchCone::Index Index; | ||
146 | |||
147 | template <class _PyClass> | ||
148 | 3 | void visit(_PyClass &cl) const { | |
149 |
1/2✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | cl.def(bp::init<>("Default constructor.")) |
150 |
3/6✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
|
3 | .def(bp::init<Matrix6x>( |
151 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
6 | (bp::arg("rays"), "Init from a matrix of rays."))) |
152 |
3/6✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
|
6 | .def(bp::init<Index>(bp::args("size"), "Init with a given size.")) |
153 |
3/6✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
|
6 | .def(bp::init<WrenchCone>(bp::args("other"), "Copy constructor.")) |
154 | |||
155 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
6 | .def("SE3ActOn", &WrenchCone::SE3ActOn, bp::args("M"), |
156 | "Returns the action of SE3 on *this, i.e. a WrenchCone.") | ||
157 |
2/4✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
3 | .def("linear", &getLinear, "Returns the linear block of *this.") |
158 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | .def("angular", &getAngular, "Returns the angular block of *this."); |
159 | 3 | } | |
160 | |||
161 | 3 | static void expose(const std::string &class_name) { | |
162 |
1/2✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | std::string doc = "Linear Wrench Cone"; |
163 | |||
164 |
3/6✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 3 times.
✗ Branch 10 not taken.
|
3 | LCPythonVisitor<typename WrenchCone::Base>::expose("LinearCone6"); |
165 | |||
166 |
1/2✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
|
3 | bp::class_<WrenchCone, bp::bases<typename WrenchCone::Base> >( |
167 | class_name.c_str(), doc.c_str(), bp::no_init) | ||
168 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | .def(WrenchConePythonVisitor<WrenchCone>()); |
169 | 3 | } | |
170 | |||
171 | protected: | ||
172 | ✗ | static Matrix3x getLinear(const WrenchCone &self) { return self.linear(); } | |
173 | ✗ | static Matrix3x getAngular(const WrenchCone &self) { return self.angular(); } | |
174 | }; | ||
175 | |||
176 | } // namespace python | ||
177 | } // namespace multicontact_api | ||
178 | |||
179 | #endif // ifnef __multicontact_api_python_geometry_linear_cone_hpp__ | ||
180 |