Commit f506d5a2 authored by Rohan Budhiraja's avatar Rohan Budhiraja
Browse files

[jointdatavariants] create structure to expose jointdatas.

parent 3c8239b3
......@@ -16,8 +16,13 @@ namespace pinocchio
static void exposeVariants()
{
boost::mpl::for_each<JointModelVariant::types>(exposer());
bp::to_python_converter<pinocchio::JointModelVariant, jointModelVariantVisitor>();
boost::mpl::for_each<JointModelVariant::types>(model_exposer());
bp::to_python_converter<pinocchio::JointModelVariant,
JointVariantVisitor<pinocchio::JointModelVariant > >();
boost::mpl::for_each<JointDataVariant::types>(data_exposer());
bp::to_python_converter<pinocchio::JointDataVariant,
JointVariantVisitor<pinocchio::JointDataVariant > >();
}
void exposeJoints()
......
......@@ -17,8 +17,8 @@ namespace pinocchio
namespace bp = boost::python;
template<class JointModelDerived>
struct JointPythonVisitor
: public boost::python::def_visitor< JointPythonVisitor<JointModelDerived> >
struct JointModelDerivedPythonVisitor
: public boost::python::def_visitor< JointModelDerivedPythonVisitor<JointModelDerived> >
{
public:
......@@ -27,11 +27,11 @@ namespace pinocchio
{
cl
// All are add_properties cause ReadOnly
.add_property("id",&JointPythonVisitor::getId)
.add_property("idx_q",&JointPythonVisitor::getIdx_q)
.add_property("idx_v",&JointPythonVisitor::getIdx_v)
.add_property("nq",&JointPythonVisitor::getNq)
.add_property("nv",&JointPythonVisitor::getNv)
.add_property("id",&JointModelDerivedPythonVisitor::getId)
.add_property("idx_q",&JointModelDerivedPythonVisitor::getIdx_q)
.add_property("idx_v",&JointModelDerivedPythonVisitor::getIdx_v)
.add_property("nq",&JointModelDerivedPythonVisitor::getNq)
.add_property("nv",&JointModelDerivedPythonVisitor::getNv)
.def("setIndexes",&JointModelDerived::setIndexes)
.def("shortname",&JointModelDerived::shortname)
;
......@@ -44,6 +44,41 @@ namespace pinocchio
static int getNv(const JointModelDerived & self) {return self.nv();}
static void expose()
{
}
};
template<class JointDataDerived>
struct JointDataDerivedPythonVisitor
: public boost::python::def_visitor< JointDataDerivedPythonVisitor<JointDataDerived> >
{
public:
template<class PyClass>
void visit(PyClass& cl) const
{
cl
// All are add_properties cause ReadOnly
//.add_property("id",&JointDataDerivedPythonVisitor::getId)
//.add_property("idx_q",&JointDataDerivedPythonVisitor::getIdx_q)
//.add_property("idx_v",&JointDataDerivedPythonVisitor::getIdx_v)
//.add_property("nq",&JointDataDerivedPythonVisitor::getNq)
//.add_property("nv",&JointDataDerivedPythonVisitor::getNv)
//.def("setIndexes",&JointDataDerived::setIndexes)
.def("shortname",&JointDataDerived::shortname)
;
}
//static JointIndex getId( const JointDataDerived & self ) { return self.id(); }
//static int getIdx_q(const JointDataDerived & self) {return self.idx_q();}
//static int getIdx_v(const JointDataDerived & self) {return self.idx_v();}
//static int getNq(const JointDataDerived & self) {return self.nq();}
//static int getNv(const JointDataDerived & self) {return self.nv();}
static void expose()
{
......
//
// Copyright (c) 2019 CNRS
//
#ifndef __pinocchio_python_joints_datas_hpp__
#define __pinocchio_python_joints_datas_hpp__
#include <eigenpy/exception.hpp>
#include <eigenpy/eigenpy.hpp>
//#include "pinocchio/multibody/joint/joint-collection.hpp"
//#include "pinocchio/multibody/joint/joint-composite.hpp"
namespace pinocchio
{
namespace python
{
namespace bp = boost::python;
// generic expose_joint_data : do nothing special
template <class T>
inline bp::class_<T>& expose_joint_data(bp::class_<T>& cl)
{
return cl;
}
template<>
inline bp::class_<JointDataComposite>& expose_joint_data<JointDataComposite> (bp::class_<JointDataComposite> & cl)
{
return cl
.def(bp::init<const typename JointDataComposite::JointDataVector&, const int, const int>
(bp::args("Vector of joints", "nq", "nv"),
"Init JointDataComposite with a defined size"))
;
}
} // namespace python
} // namespace pinocchio
#endif // ifndef __pinocchio_python_joint_datas_hpp__
......@@ -9,6 +9,7 @@
#include <eigenpy/eigenpy.hpp>
#include "pinocchio/multibody/joint/joint-collection.hpp"
#include "pinocchio/bindings/python/multibody/joint/joints-models.hpp"
#include "pinocchio/bindings/python/multibody/joint/joints-datas.hpp"
#include "pinocchio/bindings/python/utils/printable.hpp"
namespace pinocchio
......@@ -17,11 +18,12 @@ namespace pinocchio
{
namespace bp = boost::python;
struct jointModelVariantVisitor : boost::static_visitor<PyObject *>
template<typename VariantType>
struct JointVariantVisitor : boost::static_visitor<PyObject *>
{
static result_type convert(JointModelVariant const & jv)
static result_type convert(VariantType const & jv)
{
return apply_visitor(jointModelVariantVisitor(), jv);
return apply_visitor(JointVariantVisitor<VariantType>(), jv);
}
template<typename T>
......@@ -31,7 +33,23 @@ namespace pinocchio
}
};
struct exposer
struct data_exposer
{
template<class T>
void operator()(T)
{
expose_joint_data<T>(
bp::class_<T>(T::classname().c_str(),
T::classname().c_str(),
bp::init<>())
.def(JointDataDerivedPythonVisitor<T>())
//.def(PrintableVisitor<T>())
);
bp::implicitly_convertible<T,pinocchio::JointDataVariant>();
}
};
struct model_exposer
{
template<class T>
void operator()(T)
......@@ -40,12 +58,13 @@ namespace pinocchio
bp::class_<T>(T::classname().c_str(),
T::classname().c_str(),
bp::init<>())
.def(JointPythonVisitor<T>())
.def(JointModelDerivedPythonVisitor<T>())
.def(PrintableVisitor<T>())
);
bp::implicitly_convertible<T,pinocchio::JointModelVariant>();
}
};
} // namespace python
} // namespace pinocchio
......
......@@ -124,6 +124,9 @@ struct CastType< NewScalar, JointModelTpl<Scalar,Options> > \
UTypeRef U() { return derived().U_accessor(); }
DTypeConstRef Dinv() const { return derived().Dinv_accessor(); }
UDTypeConstRef UDinv() const { return derived().UDinv_accessor(); }
std::string shortname() const { return derived().shortname(); }
static std::string classname() { return Derived::classname(); }
protected:
......
......@@ -73,6 +73,16 @@ namespace pinocchio
typedef container::aligned_vector<JointDataVariant> JointDataVector;
// JointDataComposite() {} // can become necessary if we want a vector of JointDataComposite ?
JointDataCompositeTpl()
: joints()
, iMlast(0), pjMi(0)
, S(0)
, M(),v(),c()
, U(0,0), Dinv(0,0), UDinv(0,0)
, StU(0,0)
{}
JointDataCompositeTpl(const JointDataVector & joint_data, const int /*nq*/, const int nv)
: joints(joint_data), iMlast(joint_data.size()), pjMi(joint_data.size())
......@@ -103,6 +113,9 @@ namespace pinocchio
D_t StU;
static std::string classname() { return std::string("JointDataComposite"); }
std::string shortname() const { return classname(); }
};
template<typename NewScalar, typename Scalar, int Options, template<typename S, int O> class JointCollectionTpl>
......
......@@ -202,6 +202,9 @@ namespace pinocchio
JointDataFreeFlyerTpl() : M(1), U(), Dinv(), UDinv(UD_t::Identity()) {}
static std::string classname() { return std::string("JointDataFreeFlyer"); }
std::string shortname() const { return classname(); }
}; // struct JointDataFreeFlyerTpl
JOINT_CAST_TYPE_SPECIALIZATION(JointModelFreeFlyerTpl);
......
......@@ -115,6 +115,9 @@ namespace pinocchio
D_t Dinv_accessor() const { return Dinv(); }
UD_t UDinv_accessor() const { return UDinv(); }
static std::string classname() { return "JointData"; }
std::string shortname() const { return ::pinocchio::shortname(*this); }
};
template<typename NewScalar, typename Scalar, int Options, template<typename S, int O> class JointCollectionTpl>
......
......@@ -433,6 +433,9 @@ namespace pinocchio
JointDataPlanarTpl () : M(1), U(), Dinv(), UDinv() {}
static std::string classname() { return std::string("JointDataPlanar"); }
std::string shortname() const { return classname(); }
}; // struct JointDataPlanarTpl
JOINT_CAST_TYPE_SPECIALIZATION(JointModelPlanarTpl);
......
......@@ -416,6 +416,9 @@ namespace pinocchio
, U(), Dinv(), UDinv()
{}
static std::string classname() { return std::string("JointDataPrismaticUnaligned"); }
std::string shortname() const { return classname(); }
}; // struct JointDataPrismaticUnalignedTpl
template<typename Scalar, int Options>
......
......@@ -485,6 +485,9 @@ namespace pinocchio
JointDataPrismaticTpl() {}
static std::string classname() { return std::string("JointDataPrismatic"); }
std::string shortname() const { return classname(); }
}; // struct JointDataPrismaticTpl
template<typename NewScalar, typename Scalar, int Options, int axis>
......
......@@ -437,6 +437,9 @@ namespace pinocchio
, U(), Dinv(), UDinv()
{}
static std::string classname() { return std::string("JointDataRevoluteUnaligned"); }
std::string shortname() const { return classname(); }
}; // struct JointDataRevoluteUnalignedTpl
JOINT_CAST_TYPE_SPECIALIZATION(JointModelRevoluteUnalignedTpl);
......
......@@ -73,6 +73,9 @@ namespace pinocchio
JointDataRevoluteUnboundedTpl() {}
static std::string classname() { return std::string("JointDataRevoluteUnbounded"); }
std::string shortname() const { return classname(); }
}; // struct JointDataRevoluteUnbounded
template<typename NewScalar, typename Scalar, int Options, int axis>
......
......@@ -563,6 +563,9 @@ namespace pinocchio
JointDataRevoluteTpl() {}
static std::string classname() { return std::string("JointDataRevolute"); }
std::string shortname() const { return classname(); }
}; // struct JointDataRevoluteTpl
template<typename NewScalar, typename Scalar, int Options, int axis>
......
......@@ -292,6 +292,9 @@ namespace pinocchio
D_t StU;
JointDataSphericalZYXTpl () : M(1), U(), Dinv(), UDinv() {}
static std::string classname() { return std::string("JointDataSphericalZYX"); }
std::string shortname() const { return classname(); }
}; // strcut JointDataSphericalZYXTpl
......
......@@ -388,6 +388,9 @@ namespace pinocchio
JointDataSphericalTpl () : M(1), U(), Dinv(), UDinv() {}
static std::string classname() { return std::string("JointDataSpherical"); }
std::string shortname() const { return classname(); }
}; // struct JointDataSphericalTpl
JOINT_CAST_TYPE_SPECIALIZATION(JointModelSphericalTpl);
......
......@@ -469,6 +469,8 @@ namespace pinocchio
JointDataTranslationTpl() {}
static std::string classname() { return std::string("JointDataTranslation"); }
std::string shortname() const { return classname(); }
}; // struct JointDataTranslationTpl
JOINT_CAST_TYPE_SPECIALIZATION(JointModelTranslationTpl);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment