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 
13 namespace multicontact_api {
14 namespace python {
15 
16 namespace bp = boost::python;
17 
18 template <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 
85 template <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;
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 &, const int)) &
109  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)) &
117  ForceCone::RegularCone,
118  bp::args("mu", "direction", "num rays", "angle offset"),
119  "Generates a regular linear cone from a given number of rays, a "
120  "main direction and a friction "
121  "coefficient, with an offset on the orientation.")
122  .staticmethod("RegularCone");
123  }
124 
125  static void expose(const std::string &class_name) {
126  std::string doc = "Force Cone of dimension 3";
127  doc += " defined by its rays.";
128 
130 
131  bp::class_<ForceCone, bp::bases<typename ForceCone::Base> >(
132  class_name.c_str(), doc.c_str(), bp::no_init)
134  }
135 
136  static WrenchCone toWrenchCone(const ForceCone &self) {
137  return (WrenchCone)(self);
138  }
139 };
140 
141 template <typename WrenchCone>
143  : public boost::python::def_visitor<WrenchConePythonVisitor<WrenchCone> > {
144  typedef typename WrenchCone::Matrix3x Matrix3x;
145  typedef typename WrenchCone::Matrix6x Matrix6x;
146  typedef typename WrenchCone::Index Index;
147 
148  template <class _PyClass>
149  void visit(_PyClass &cl) const {
150  cl.def(bp::init<>("Default constructor."))
151  .def(bp::init<Matrix6x>(
152  (bp::arg("rays"), "Init from a matrix of rays.")))
153  .def(bp::init<Index>(bp::args("size"), "Init with a given size."))
154  .def(bp::init<WrenchCone>(bp::args("other"), "Copy constructor."))
155 
156  .def("SE3ActOn", &WrenchCone::SE3ActOn, bp::args("M"),
157  "Returns the action of SE3 on *this, i.e. a WrenchCone.")
158  .def("linear", &getLinear, "Returns the linear block of *this.")
159  .def("angular", &getAngular, "Returns the angular block of *this.");
160  }
161 
162  static void expose(const std::string &class_name) {
163  std::string doc = "Linear Wrench Cone";
164 
166 
167  bp::class_<WrenchCone, bp::bases<typename WrenchCone::Base> >(
168  class_name.c_str(), doc.c_str(), bp::no_init)
170  }
171 
172  protected:
173  static Matrix3x getLinear(const WrenchCone &self) { return self.linear(); }
174  static Matrix3x getAngular(const WrenchCone &self) { return self.angular(); }
175 };
176 
177 } // namespace python
178 } // namespace multicontact_api
179 
180 #endif // ifnef __multicontact_api_python_geometry_linear_cone_hpp__
static MatrixDx getRays(const LC &self)
Definition: linear-cone.hpp:79
static WrenchCone toWrenchCone(const ForceCone &self)
Definition: linear-cone.hpp:136
ForceCone::VectorD VectorD
Definition: linear-cone.hpp:90
static int dim()
Definition: linear-cone.hpp:82
LC::MatrixDx MatrixDx
Definition: linear-cone.hpp:24
void visit(_PyClass &cl) const
Definition: linear-cone.hpp:149
static Matrix3x getAngular(const WrenchCone &self)
Definition: linear-cone.hpp:174
WrenchCone::Matrix3x Matrix3x
Definition: linear-cone.hpp:144
static void expose(const std::string &class_name)
Definition: linear-cone.hpp:125
ForceCone::Matrix3x Matrix3x
Definition: linear-cone.hpp:91
ForceCone::Vector3 Vector3
Definition: linear-cone.hpp:89
static PyClass & expose(const std::string &class_name, std::string doc="")
Definition: linear-cone.hpp:56
WrenchCone::Index Index
Definition: linear-cone.hpp:146
ForceConeTpl< double > ForceCone
Definition: fwd.hpp:22
WrenchConeTpl< double > WrenchCone
Definition: fwd.hpp:25
WrenchCone::Matrix6x Matrix6x
Definition: linear-cone.hpp:145
Definition: ellipsoid.hpp:12
static Matrix3x getLinear(const WrenchCone &self)
Definition: linear-cone.hpp:173
LC::Index Index
Definition: linear-cone.hpp:27
void visit(PyClass &cl) const
Definition: linear-cone.hpp:30
static std::string toString(const LC &c)
Definition: linear-cone.hpp:73
LC Type
Definition: linear-cone.hpp:22
ForceCone::Scalar Scalar
Definition: linear-cone.hpp:88
LC::Scalar Scalar
Definition: linear-cone.hpp:26
static void setRays(LC &self, const MatrixDx &rays)
Definition: linear-cone.hpp:80
LC::VectorD VectorD
Definition: linear-cone.hpp:25
ForceCone::WrenchCone WrenchCone
Definition: linear-cone.hpp:93
bp::class_< LC > PyClass
Definition: linear-cone.hpp:21
Definition: linear-cone.hpp:19
ForceCone::Index Index
Definition: linear-cone.hpp:92
static void expose(const std::string &class_name)
Definition: linear-cone.hpp:162
void visit(_PyClass &cl) const
Definition: linear-cone.hpp:96