Commit 94934094 authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

Merge branch 'devel' into 'devel'

Format

See merge request loco-3d/multicontact-api!10
parents b5289806 7ab19b5b
Pipeline #5638 passed with stage
in 11 minutes and 36 seconds
......@@ -16,6 +16,13 @@ SET(PROJECT_DESCRIPTION "Multi-contact locomotion for multi-body systems")
SET(PROJECT_URL "https://gepgitlab.laas.fr/${PROJECT_NAMESPACE}/${PROJECT_NAME}")
OPTION(BUILD_PYTHON_INTERFACE "Build the python binding" ON)
OPTION (INSTALL_PYTHON_INTERFACE_ONLY "Install *ONLY* the python binding" OFF)
IF(INSTALL_PYTHON_INTERFACE_ONLY)
SET(INSTALL_DOCUMENTATION OFF CACHE BOOL "documentation is not in python interface")
SET(INSTALL_GENERATED_HEADERS OFF CACHE BOOL "headers are not in python interface")
SET(INSTALL_PKG_CONFIG_FILE OFF CACHE BOOL ".pc is not in python interface")
ENDIF(INSTALL_PYTHON_INTERFACE_ONLY)
SET(DOXYGEN_USE_MATHJAX YES)
SET(CXX_DISABLE_WERROR True)
......@@ -40,7 +47,9 @@ ENDIF(BUILD_PYTHON_INTERFACE)
SEARCH_FOR_BOOST()
INCLUDE_DIRECTORIES(SYSTEM ${Boost_INCLUDE_DIRS})
ADD_SUBDIRECTORY(include/${CUSTOM_HEADER_DIR})
IF(NOT INSTALL_PYTHON_INTERFACE_ONLY)
ADD_SUBDIRECTORY(include/${CUSTOM_HEADER_DIR})
ENDIF(NOT INSTALL_PYTHON_INTERFACE_ONLY)
ADD_SUBDIRECTORY(bindings)
ADD_SUBDIRECTORY(unittest)
......
......@@ -4,13 +4,8 @@
#include "multicontact-api/bindings/python/geometry/ellipsoid.hpp"
#include "multicontact-api/bindings/python/geometry/expose-geometry.hpp"
namespace multicontact_api
{
namespace python
{
void exposeEllipsoid()
{
EllipsoidPythonVisitor<multicontact_api::geometry::Ellipsoid3d>::expose("Ellipsoid3d");
}
}
}
namespace multicontact_api {
namespace python {
void exposeEllipsoid() { EllipsoidPythonVisitor<multicontact_api::geometry::Ellipsoid3d>::expose("Ellipsoid3d"); }
} // namespace python
} // namespace multicontact_api
......@@ -4,14 +4,11 @@
#include "multicontact-api/bindings/python/geometry/linear-cone.hpp"
#include "multicontact-api/bindings/python/geometry/expose-geometry.hpp"
namespace multicontact_api
{
namespace python
{
void exposeLinearCone()
{
ForceConePythonVisitor<multicontact_api::geometry::ForceCone>::expose("ForceCone");
WrenchConePythonVisitor<multicontact_api::geometry::WrenchCone>::expose("WrenchCone");
}
}
namespace multicontact_api {
namespace python {
void exposeLinearCone() {
ForceConePythonVisitor<multicontact_api::geometry::ForceCone>::expose("ForceCone");
WrenchConePythonVisitor<multicontact_api::geometry::WrenchCone>::expose("WrenchCone");
}
} // namespace python
} // namespace multicontact_api
......@@ -4,14 +4,11 @@
#include "multicontact-api/bindings/python/geometry/second-order-cone.hpp"
#include "multicontact-api/bindings/python/geometry/expose-geometry.hpp"
namespace multicontact_api
{
namespace python
{
void exposeSecondOrderCone()
{
SOCPythonVisitor<multicontact_api::geometry::SOC6d>::expose("SOC6");
SOCPythonVisitor<multicontact_api::geometry::SOC3d>::expose("SOC3");
}
}
namespace multicontact_api {
namespace python {
void exposeSecondOrderCone() {
SOCPythonVisitor<multicontact_api::geometry::SOC6d>::expose("SOC6");
SOCPythonVisitor<multicontact_api::geometry::SOC3d>::expose("SOC3");
}
} // namespace python
} // namespace multicontact_api
......@@ -10,8 +10,7 @@
namespace bp = boost::python;
BOOST_PYTHON_MODULE(libmulticontact_api)
{
BOOST_PYTHON_MODULE(libmulticontact_api) {
eigenpy::enableEigenPy();
using namespace multicontact_api::python;
......
......@@ -4,13 +4,10 @@
#include "multicontact-api/bindings/python/scenario/expose-scenario.hpp"
#include "multicontact-api/bindings/python/scenario/contact-model-planar.hpp"
namespace multicontact_api
{
namespace python
{
void exposeContactModels()
{
ContactModelPlanarPythonVisitor<multicontact_api::scenario::ContactModelPlanar>::expose("ContactModelPlanar");
}
}
namespace multicontact_api {
namespace python {
void exposeContactModels() {
ContactModelPlanarPythonVisitor<multicontact_api::scenario::ContactModelPlanar>::expose("ContactModelPlanar");
}
} // namespace python
} // namespace multicontact_api
......@@ -4,13 +4,10 @@
#include "multicontact-api/bindings/python/scenario/expose-scenario.hpp"
#include "multicontact-api/bindings/python/scenario/contact-patch.hpp"
namespace multicontact_api
{
namespace python
{
void exposeContactPatch()
{
ContactPatchPythonVisitor<multicontact_api::scenario::ContactPatch>::expose("ContactPatch");
}
}
namespace multicontact_api {
namespace python {
void exposeContactPatch() {
ContactPatchPythonVisitor<multicontact_api::scenario::ContactPatch>::expose("ContactPatch");
}
} // namespace python
} // namespace multicontact_api
......@@ -5,14 +5,11 @@
#include "multicontact-api/bindings/python/scenario/contact-phase.hpp"
#include "multicontact-api/bindings/python/scenario/contact-phase-humanoid.hpp"
namespace multicontact_api
{
namespace python
{
void exposeContactPhase()
{
ContactPhasePythonVisitor<multicontact_api::scenario::ContactPhase4>::expose("ContactPhase4");
ContactPhaseHumanoidPythonVisitor<multicontact_api::scenario::ContactPhaseHumanoid>::expose("ContactPhaseHumanoid");
}
}
namespace multicontact_api {
namespace python {
void exposeContactPhase() {
ContactPhasePythonVisitor<multicontact_api::scenario::ContactPhase4>::expose("ContactPhase4");
ContactPhaseHumanoidPythonVisitor<multicontact_api::scenario::ContactPhaseHumanoid>::expose("ContactPhaseHumanoid");
}
} // namespace python
} // namespace multicontact_api
......@@ -6,15 +6,13 @@
#include "multicontact-api/bindings/python/scenario/contact-phase-humanoid.hpp"
#include "multicontact-api/bindings/python/scenario/ms-interval.hpp"
namespace multicontact_api
{
namespace python
{
void exposeContactSequence()
{
// ContactSequencePythonVisitor<multicontact_api::scenario::ContactSequence4>::expose("ContactSequence4");
ContactSequencePythonVisitor<multicontact_api::scenario::ContactSequenceHumanoid>::expose("ContactSequenceHumanoid");
MSIntervalPythonVisitor<multicontact_api::scenario::ContactSequenceHumanoid::MSIntervalData>::expose("MSIntervalData");
}
}
namespace multicontact_api {
namespace python {
void exposeContactSequence() {
// ContactSequencePythonVisitor<multicontact_api::scenario::ContactSequence4>::expose("ContactSequence4");
ContactSequencePythonVisitor<multicontact_api::scenario::ContactSequenceHumanoid>::expose("ContactSequenceHumanoid");
MSIntervalPythonVisitor<multicontact_api::scenario::ContactSequenceHumanoid::MSIntervalData>::expose(
"MSIntervalData");
}
} // namespace python
} // namespace multicontact_api
......@@ -7,39 +7,32 @@
#include <boost/python/enum.hpp>
namespace multicontact_api
{
namespace python
{
namespace bp = boost::python;
namespace multicontact_api {
namespace python {
namespace bp = boost::python;
using namespace multicontact_api::scenario;
using namespace multicontact_api::scenario;
void exposeEnumHumanoidPhaseType()
{
bp::enum_<HumanoidPhaseType>("HumanoidPhaseType")
.value("SINGLE_SUPPORT",SINGLE_SUPPORT)
.value("DOUBLE_SUPPORT",DOUBLE_SUPPORT)
.value("TRIPLE_SUPPORT",TRIPLE_SUPPORT)
.value("QUADRUPLE_SUPPORT",QUADRUPLE_SUPPORT)
.value("NO_SUPPORT",NO_SUPPORT)
.value("HUMANOID_PHASE_UNDEFINED",HUMANOID_PHASE_UNDEFINED)
;
}
void exposeEnumHumanoidPhaseType() {
bp::enum_<HumanoidPhaseType>("HumanoidPhaseType")
.value("SINGLE_SUPPORT", SINGLE_SUPPORT)
.value("DOUBLE_SUPPORT", DOUBLE_SUPPORT)
.value("TRIPLE_SUPPORT", TRIPLE_SUPPORT)
.value("QUADRUPLE_SUPPORT", QUADRUPLE_SUPPORT)
.value("NO_SUPPORT", NO_SUPPORT)
.value("HUMANOID_PHASE_UNDEFINED", HUMANOID_PHASE_UNDEFINED);
}
void exposeEnumConicType()
{
bp::enum_<ConicType>("ConicType")
.value("CONIC_SOWC",CONIC_SOWC)
.value("CONIC_DOUBLE_DESCRIPTION",CONIC_DOUBLE_DESCRIPTION)
.value("CONIC_UNDEFINED",CONIC_UNDEFINED)
;
}
void exposeEnumConicType() {
bp::enum_<ConicType>("ConicType")
.value("CONIC_SOWC", CONIC_SOWC)
.value("CONIC_DOUBLE_DESCRIPTION", CONIC_DOUBLE_DESCRIPTION)
.value("CONIC_UNDEFINED", CONIC_UNDEFINED);
}
void exposeScenarioEnums()
{
exposeEnumHumanoidPhaseType();
exposeEnumConicType();
}
}
void exposeScenarioEnums() {
exposeEnumHumanoidPhaseType();
exposeEnumConicType();
}
} // namespace python
} // namespace multicontact_api
......@@ -3,19 +3,16 @@
#include "multicontact-api/bindings/python/trajectories/cubic-hermite-spline.hpp"
namespace multicontact_api
{
namespace python
{
void exposeTrajectories()
{
using namespace trajectories;
typedef CubicHermiteSplineTpl<double,3> CubicHermiteSpline3;
typedef CubicHermiteSplineTpl<double,Eigen::Dynamic> CubicHermiteSpline;
namespace multicontact_api {
namespace python {
void exposeTrajectories() {
using namespace trajectories;
typedef CubicHermiteSplineTpl<double, 3> CubicHermiteSpline3;
typedef CubicHermiteSplineTpl<double, Eigen::Dynamic> CubicHermiteSpline;
CubicHermiteSplinePythonVisitor<CubicHermiteSpline3>::expose("CubicHermiteSpline3");
CubicHermiteSplinePythonVisitor<CubicHermiteSpline>::expose("CubicHermiteSpline");
exposeSplineAlgos();
}
}
CubicHermiteSplinePythonVisitor<CubicHermiteSpline3>::expose("CubicHermiteSpline3");
CubicHermiteSplinePythonVisitor<CubicHermiteSpline>::expose("CubicHermiteSpline");
exposeSplineAlgos();
}
} // namespace python
} // namespace multicontact_api
......@@ -9,33 +9,25 @@
#include <boost/python/to_python_indirect.hpp>
#include <typeinfo>
namespace multicontact_api
{
namespace python
{
namespace multicontact_api {
namespace python {
namespace bp = boost::python;
namespace bp = boost::python;
template<typename reference_wrapper_type>
struct reference_wrapper_converter
{
typedef reference_wrapper_type ref_type;
typedef typename reference_wrapper_type::type type;
template <typename reference_wrapper_type>
struct reference_wrapper_converter {
typedef reference_wrapper_type ref_type;
typedef typename reference_wrapper_type::type type;
static PyObject* convert(ref_type const& ref)
{
ref_type* const p = &const_cast<ref_type&>(ref);
if(p == 0)
return bp::detail::none();
return bp::detail::make_reference_holder::execute(&p->get());
}
static void expose()
{
bp::to_python_converter<ref_type,reference_wrapper_converter>();
}
};
static PyObject* convert(ref_type const& ref) {
ref_type* const p = &const_cast<ref_type&>(ref);
if (p == 0) return bp::detail::none();
return bp::detail::make_reference_holder::execute(&p->get());
}
}
#endif // ifndef __multicontact_api_python_container_reference_wrapper_hpp__
static void expose() { bp::to_python_converter<ref_type, reference_wrapper_converter>(); }
};
} // namespace python
} // namespace multicontact_api
#endif // ifndef __multicontact_api_python_container_reference_wrapper_hpp__
......@@ -8,28 +8,19 @@
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include <string>
namespace multicontact_api
{
namespace python
{
namespace multicontact_api {
namespace python {
namespace bp = boost::python;
template<typename Vector, bool NoProxy = false>
struct VectorPythonVisitor
: public bp::def_visitor< VectorPythonVisitor<Vector> >
{
static void expose(const std::string & class_name,
const std::string & doc = "")
{
bp::class_<Vector>(class_name.c_str(),doc.c_str())
.def(bp::vector_indexing_suite<Vector,NoProxy>())
;
}
};
namespace bp = boost::python;
template <typename Vector, bool NoProxy = false>
struct VectorPythonVisitor : public bp::def_visitor<VectorPythonVisitor<Vector> > {
static void expose(const std::string& class_name, const std::string& doc = "") {
bp::class_<Vector>(class_name.c_str(), doc.c_str()).def(bp::vector_indexing_suite<Vector, NoProxy>());
}
}
};
} // namespace python
} // namespace multicontact_api
#endif // ifndef __multcontact_api_python_container_visitor_hpp__
#endif // ifndef __multcontact_api_python_container_visitor_hpp__
......@@ -5,22 +5,22 @@
#define __multicontact_api_python_geometry_ellipsoid_hpp__
namespace multicontact_api {
namespace python {
namespace internal {
namespace python {
namespace internal {
template<typename T>
struct build_type_name
{
static const char* name();
static const char* shortname();
};
template <typename T>
struct build_type_name {
static const char* name();
static const char* shortname();
};
template<>
const char * build_type_name<double>::shortname() { return "d"; }
}
}
template <>
const char* build_type_name<double>::shortname() {
return "d";
}
#endif // ifndef __multicontact_api_python_geometry_ellipsoid_hpp__
} // namespace internal
} // namespace python
} // namespace multicontact_api
#endif // ifndef __multicontact_api_python_geometry_ellipsoid_hpp__
......@@ -9,56 +9,46 @@
#include "multicontact-api/geometry/ellipsoid.hpp"
namespace multicontact_api
{
namespace python
{
namespace bp = boost::python;
template<typename Ellipsoid>
struct EllipsoidPythonVisitor
: public boost::python::def_visitor< EllipsoidPythonVisitor<Ellipsoid> >
{
typedef typename Ellipsoid::Matrix Matrix;
typedef typename Ellipsoid::Vector Vector;
template<class PyClass>
void visit(PyClass& cl) const
{
cl
.def(bp::init<Matrix,Vector>
((bp::arg("A"),bp::arg("center"))))
.def("__str__",&toString)
.def("lhsValue",&Ellipsoid::lhsValue,bp::arg("point"),"Returns the value of norm(A*(x-c)).")
.add_property("center",&get_center,&set_center,"Accessor to the center property.")
.add_property("A",&get_A,&set_A,"Accessor to the A property.")
;
}
static void set_center(Ellipsoid & e, const Vector & center) { e.center() = center; }
static Vector get_center(const Ellipsoid & e) { return e.center(); }
static void set_A(Ellipsoid & e, const Matrix & A) { e.A() = A; }
static Matrix get_A(const Ellipsoid & e) { return e.A(); }
namespace multicontact_api {
namespace python {
namespace bp = boost::python;
template <typename Ellipsoid>
struct EllipsoidPythonVisitor : public boost::python::def_visitor<EllipsoidPythonVisitor<Ellipsoid> > {
typedef typename Ellipsoid::Matrix Matrix;
typedef typename Ellipsoid::Vector Vector;
template <class PyClass>
void visit(PyClass& cl) const {
cl.def(bp::init<Matrix, Vector>((bp::arg("A"), bp::arg("center"))))
.def("__str__", &toString)
.def("lhsValue", &Ellipsoid::lhsValue, bp::arg("point"), "Returns the value of norm(A*(x-c)).")
.add_property("center", &get_center, &set_center, "Accessor to the center property.")
.add_property("A", &get_A, &set_A, "Accessor to the A property.");
}
static void expose(const std::string & class_name)
{
std::string doc = "Ellipsoid of dimension " + Ellipsoid::dim;
doc += " defined by its matrix A and its center.";
bp::class_<Ellipsoid>(class_name.c_str(),
doc.c_str(),
bp::no_init)
.def(EllipsoidPythonVisitor<Ellipsoid>())
;
static void set_center(Ellipsoid& e, const Vector& center) { e.center() = center; }
static Vector get_center(const Ellipsoid& e) { return e.center(); }
}
static void set_A(Ellipsoid& e, const Matrix& A) { e.A() = A; }
static Matrix get_A(const Ellipsoid& e) { return e.A(); }
protected:
static std::string toString(const Ellipsoid & e) { std::ostringstream s; s << e; return s.str(); }
};
static void expose(const std::string& class_name) {
std::string doc = "Ellipsoid of dimension " + Ellipsoid::dim;
doc += " defined by its matrix A and its center.";
bp::class_<Ellipsoid>(class_name.c_str(), doc.c_str(), bp::no_init).def(EllipsoidPythonVisitor<Ellipsoid>());
}
protected:
static std::string toString(const Ellipsoid& e) {
std::ostringstream s;
s << e;
return s.str();
}
}
};
} // namespace python
} // namespace multicontact_api
#endif // ifnef __multicontact_api_python_geometry_ellipsoid_hpp__
#endif // ifnef __multicontact_api_python_geometry_ellipsoid_hpp__
......@@ -4,24 +4,20 @@
#ifndef __multicontact_api_python_expose_geometry_hpp__
#define __multicontact_api_python_expose_geometry_hpp__
namespace multicontact_api {
namespace python {
namespace multicontact_api
{
namespace python
{
void exposeEllipsoid();
void exposeLinearCone();
void exposeSecondOrderCone();
void exposeEllipsoid();
void exposeLinearCone();
void exposeSecondOrderCone();
inline void exposeGeometry()
{
exposeEllipsoid();
exposeLinearCone();
exposeSecondOrderCone();
}
}
inline void exposeGeometry() {
exposeEllipsoid();
exposeLinearCone();
exposeSecondOrderCone();
}
#endif // ifndef __multicontact_api_python_expose_geometry_hpp__
} // namespace python
} // namespace multicontact_api
#endif // ifndef __multicontact_api_python_expose_geometry_hpp__
......@@ -10,167 +10,150 @@
#include "multicontact-api/geometry/linear-cone.hpp"
#include "multicontact-api/bindings/python/serialization/archive.hpp"
namespace multicontact_api
{
namespace python
{
namespace bp = boost::python;
template<typename LC>
struct LCPythonVisitor
: public boost::python::def_visitor< LCPythonVisitor<LC> >
{
typedef bp::class_<LC> PyClass;
typedef LC Type;
typedef typename LC::MatrixDx MatrixDx;
typedef typename LC::VectorD VectorD;
typedef typename LC::Scalar Scalar;
typedef typename LC::Index Index;
template<class PyClass>
void visit(PyClass & cl) const
{
cl
.def(bp::init<>("Default constructor."))
.def(bp::init<MatrixDx>((bp::arg("rays"),"Init from a set of rays.")))
.def(bp::init<Index>(bp::args("size"),"Init with a given size."))
.def(bp::init<LC>(bp::args("other"),"Copy constructor."))
.add_property("size",&LC::size,"Returns the size of the set of rays.")
.add_static_property("dim",&dim,"Dimension of the linear cone.")
.add_property("rays",&getRays,&setRays,"Matrix of rays of the linear cone.")