Loading...
Searching...
No Matches
linear-cone.hpp
Go to the documentation of this file.
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
12
13namespace multicontact_api {
14namespace python {
15
16namespace bp = boost::python;
17
18template <typename LC>
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 void visit(PyClass &cl) const {
31 cl.def(bp::init<>("Default constructor."))
32 .def(bp::init<MatrixDx>((bp::arg("rays"), "Init from a set of rays.")))
33 .def(bp::init<Index>(bp::args("size"), "Init with a given size."))
34 .def(bp::init<LC>(bp::args("other"), "Copy constructor."))
35
36 .add_property("size", &LC::size, "Returns the size of the set of rays.")
37 .add_static_property("dim", &dim, "Dimension of the linear cone.")
38
39 .add_property("rays", &getRays, &setRays,
40 "Matrix of rays of the linear cone.")
41 .def("__str__", &toString)
42 .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 .def("stack", &LC::template stack<MatrixDx>, bp::args("rays"),
48 "Stack new rays to the set of rays.")
49 .def("stack", &LC::template stack<Scalar, LC::Options>,
50 bp::args("cone"), "Stack the rays of one to the set of rays.")
51
52 .def(bp::self == bp::self)
53 .def(bp::self != bp::self);
54 }
55
56 static PyClass &expose(const std::string &class_name, std::string doc = "") {
57 if (doc.empty()) {
58 doc = "Linear Cone of dimension " + LC::dim;
59 doc += " defined by its rays.";
60 }
61
62 static PyClass cl_ = PyClass(class_name.c_str(), doc.c_str(), bp::no_init);
64
65 // Expose related matrix types
66 ENABLE_SPECIFIC_MATRIX_TYPE(MatrixDx);
67 ENABLE_SPECIFIC_MATRIX_TYPE(VectorD);
68
69 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
85template <typename ForceCone>
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 void visit(_PyClass &cl) const {
97 cl.def(bp::init<>("Default constructor."))
98 .def(bp::init<Matrix3x>(
99 (bp::arg("rays"), "Init from a matrix of rays.")))
100 .def(bp::init<Index>(bp::args("size"), "Init with a given size."))
101 .def(bp::init<ForceCone>(bp::args("other"), "Copy constructor."))
102
103 .def("SE3ActOn", &ForceCone::SE3ActOn, bp::args("M"),
104 "Returns the action of SE3 on *this, i.e. a WrenchCone.")
105 .def("toWrenchCone", &toWrenchCone, "Returns *this as a WrenchCone.")
106
107 .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 .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 .staticmethod("RegularCone");
122 }
123
124 static void expose(const std::string &class_name) {
125 std::string doc = "Force Cone of dimension 3";
126 doc += " defined by its rays.";
127
129
130 bp::class_<ForceCone, bp::bases<typename ForceCone::Base> >(
131 class_name.c_str(), doc.c_str(), bp::no_init)
133 }
134
135 static WrenchCone toWrenchCone(const ForceCone &self) {
136 return (WrenchCone)(self);
137 }
138};
139
140template <typename WrenchCone>
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 void visit(_PyClass &cl) const {
149 cl.def(bp::init<>("Default constructor."))
150 .def(bp::init<Matrix6x>(
151 (bp::arg("rays"), "Init from a matrix of rays.")))
152 .def(bp::init<Index>(bp::args("size"), "Init with a given size."))
153 .def(bp::init<WrenchCone>(bp::args("other"), "Copy constructor."))
154
155 .def("SE3ActOn", &WrenchCone::SE3ActOn, bp::args("M"),
156 "Returns the action of SE3 on *this, i.e. a WrenchCone.")
157 .def("linear", &getLinear, "Returns the linear block of *this.")
158 .def("angular", &getAngular, "Returns the angular block of *this.");
159 }
160
161 static void expose(const std::string &class_name) {
162 std::string doc = "Linear Wrench Cone";
163
165
166 bp::class_<WrenchCone, bp::bases<typename WrenchCone::Base> >(
167 class_name.c_str(), doc.c_str(), bp::no_init)
169 }
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__
Definition ellipsoid.hpp:12
static void expose(const std::string &class_name)
Definition linear-cone.hpp:124
ForceCone::VectorD VectorD
Definition linear-cone.hpp:90
ForceCone::Vector3 Vector3
Definition linear-cone.hpp:89
ForceCone::Scalar Scalar
Definition linear-cone.hpp:88
ForceCone::WrenchCone WrenchCone
Definition linear-cone.hpp:93
ForceCone::Index Index
Definition linear-cone.hpp:92
static WrenchCone toWrenchCone(const ForceCone &self)
Definition linear-cone.hpp:135
void visit(_PyClass &cl) const
Definition linear-cone.hpp:96
ForceCone::Matrix3x Matrix3x
Definition linear-cone.hpp:91
Definition linear-cone.hpp:20
static int dim()
Definition linear-cone.hpp:82
static std::string toString(const LC &c)
Definition linear-cone.hpp:73
static void setRays(LC &self, const MatrixDx &rays)
Definition linear-cone.hpp:80
bp::class_< LC > PyClass
Definition linear-cone.hpp:21
LC::Scalar Scalar
Definition linear-cone.hpp:26
static MatrixDx getRays(const LC &self)
Definition linear-cone.hpp:79
LC::Index Index
Definition linear-cone.hpp:27
LC::VectorD VectorD
Definition linear-cone.hpp:25
static PyClass & expose(const std::string &class_name, std::string doc="")
Definition linear-cone.hpp:56
LC Type
Definition linear-cone.hpp:22
LC::MatrixDx MatrixDx
Definition linear-cone.hpp:24
void visit(PyClass &cl) const
Definition linear-cone.hpp:30
WrenchCone::Index Index
Definition linear-cone.hpp:145
WrenchCone::Matrix6x Matrix6x
Definition linear-cone.hpp:144
WrenchCone::Matrix3x Matrix3x
Definition linear-cone.hpp:143
void visit(_PyClass &cl) const
Definition linear-cone.hpp:148
static Matrix3x getAngular(const WrenchCone &self)
Definition linear-cone.hpp:173
static void expose(const std::string &class_name)
Definition linear-cone.hpp:161
static Matrix3x getLinear(const WrenchCone &self)
Definition linear-cone.hpp:172