Toggle main menu visibility
Loading...
Searching...
No Matches
second-order-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_second_order_cone_hpp__
5
#define __multicontact_api_python_geometry_second_order_cone_hpp__
6
7
#include <eigenpy/eigenpy.hpp>
8
9
#include "
multicontact-api/bindings/python/serialization/archive.hpp
"
10
#include "
multicontact-api/geometry/second-order-cone.hpp
"
11
12
namespace
multicontact_api
{
13
namespace
python
{
14
15
namespace
bp = boost::python;
16
17
template
<
typename
SOC>
18
struct
SOCPythonVisitor
19
:
public
boost::python::def_visitor<SOCPythonVisitor<SOC> > {
20
typedef
typename
SOC::MatrixD
MatrixD
;
21
typedef
typename
SOC::VectorD
VectorD
;
22
typedef
typename
SOC::Scalar
Scalar
;
23
24
template
<
class
PyClass>
25
void
visit
(PyClass &cl)
const
{
26
cl.def(bp::init<>(
"Default constructor."
))
27
.def(bp::init<MatrixD, VectorD>((bp::arg(
"Q"
), bp::arg(
"direction"
))))
28
.def(
"__str__"
, &
toString
)
29
.def(
"lhsValue"
, &SOC::lhsValue, bp::arg(
"vector"
),
30
"Returns the lhs value of the conic inequality."
)
31
.def(
"rhsValue"
, &SOC::rhsValue, bp::arg(
"vector"
),
32
"Returns the rhs value of the conic inequality."
)
33
.def(
"check"
, (
bool
(SOC::*)(
const
VectorD
&)
const
) & SOC::check,
34
bp::arg(
"vector"
),
35
"Checks if the vector given in argument belongs to the conic "
36
"constraint."
)
37
.def(
"check"
,
38
(
bool
(SOC::*)(
const
VectorD
&,
const
Scalar
)
const
) & SOC::check,
39
bp::args(
"vector"
,
"factor"
),
40
"Checks if the vector given in argument belongs to the conic "
41
"constraint with a given reduction factor."
)
42
.add_property(
"direction"
, &
get_direction
, &SOC::setDirection,
43
"Accessor to the direction property."
)
44
.add_property(
"Q"
, &
get_Q
, &SOC::setQ,
"Accessor to the Q property."
)
45
.def(
"isApprox"
,
46
(
bool
(SOC::*)(
const
SOC &,
const
Scalar
&)
const
) & SOC::isApprox,
47
bp::args(
"other"
,
"prec"
),
48
"Returns true if *this is approximately equal to other, within "
49
"the precision determined by prec."
)
50
.def(bp::self == bp::self)
51
.def(bp::self != bp::self)
52
53
.def(
"RegularCone"
, &SOC::RegularCone, bp::args(
"mu"
,
"direction"
),
54
"Creates a regular cone from a given friction coefficient and a "
55
"direction."
)
56
.staticmethod(
"RegularCone"
);
57
}
58
59
static
void
expose
(
const
std::string &class_name) {
60
std::string doc =
"SOC of dimension "
+ SOC::dim;
61
doc +=
" defined by its direction and its quadratic norm."
;
62
bp::class_<SOC>(class_name.c_str(), doc.c_str(), bp::no_init)
63
.def(
SOCPythonVisitor<SOC>
())
64
.def(
SerializableVisitor<SOC>
());
65
66
// Expose related matrix types
67
ENABLE_SPECIFIC_MATRIX_TYPE(
MatrixD
);
68
ENABLE_SPECIFIC_MATRIX_TYPE(
VectorD
);
69
}
70
71
protected
:
72
static
std::string
toString
(
const
SOC &c) {
73
std::ostringstream s;
74
s << c;
75
return
s.str();
76
}
77
78
static
VectorD
get_direction
(
const
SOC &c) {
return
c.direction(); }
79
static
MatrixD
get_Q
(
const
SOC &c) {
return
c.Q(); }
80
};
81
82
}
// namespace python
83
}
// namespace multicontact_api
84
85
#endif
// ifnef __multicontact_api_python_geometry_second_order_cone_hpp__
archive.hpp
second-order-cone.hpp
multicontact_api::python
Definition
ellipsoid.hpp:13
multicontact_api
Definition
ellipsoid.hpp:12
multicontact_api::python::SOCPythonVisitor
Definition
second-order-cone.hpp:19
multicontact_api::python::SOCPythonVisitor::get_direction
static VectorD get_direction(const SOC &c)
Definition
second-order-cone.hpp:78
multicontact_api::python::SOCPythonVisitor::VectorD
SOC::VectorD VectorD
Definition
second-order-cone.hpp:21
multicontact_api::python::SOCPythonVisitor::get_Q
static MatrixD get_Q(const SOC &c)
Definition
second-order-cone.hpp:79
multicontact_api::python::SOCPythonVisitor::toString
static std::string toString(const SOC &c)
Definition
second-order-cone.hpp:72
multicontact_api::python::SOCPythonVisitor::Scalar
SOC::Scalar Scalar
Definition
second-order-cone.hpp:22
multicontact_api::python::SOCPythonVisitor::MatrixD
SOC::MatrixD MatrixD
Definition
second-order-cone.hpp:20
multicontact_api::python::SOCPythonVisitor::expose
static void expose(const std::string &class_name)
Definition
second-order-cone.hpp:59
multicontact_api::python::SOCPythonVisitor::visit
void visit(PyClass &cl) const
Definition
second-order-cone.hpp:25
multicontact_api::python::SerializableVisitor
Definition
archive.hpp:37
include
multicontact-api
bindings
python
geometry
second-order-cone.hpp
Generated by
1.17.0