Verified Commit 7681006c authored by Justin Carpentier's avatar Justin Carpentier
Browse files

python: expose pool

parent bcb68671
......@@ -64,6 +64,12 @@ IF(NOT BUILD_WITH_HPP_FCL_PYTHON_BINDINGS)
)
ENDIF(NOT BUILD_WITH_HPP_FCL_PYTHON_BINDINGS)
IF(NOT BUILD_WITH_OPENMP_SUPPORT)
LIST(FILTER ${PROJECT_NAME}_PYTHON_HEADERS EXCLUDE REGEX "^multibody/pool")
LIST(FILTER ${PROJECT_NAME}_PYTHON_SOURCES EXCLUDE REGEX "^multibody/pool")
ENDIF(NOT BUILD_WITH_OPENMP_SUPPORT)
LIST(APPEND HEADERS ${${PROJECT_NAME}_PYTHON_HEADERS})
# Headers of the Python bindings
......@@ -71,6 +77,7 @@ MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/bindings/python"
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/bindings/python/spatial")
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/bindings/python/multibody")
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/bindings/python/multibody/joint")
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/bindings/python/multibody/pool")
IF(BUILD_WITH_HPP_FCL_PYTHON_BINDINGS)
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/bindings/python/multibody/fcl")
ENDIF(BUILD_WITH_HPP_FCL_PYTHON_BINDINGS)
......@@ -96,6 +103,11 @@ IF(BUILD_PYTHON_INTERFACE)
SET(PKG_CONFIG_PYWRAP_REQUIRES "eigenpy >= 2.6.2")
ADD_LIBRARY(${PYWRAP} SHARED ${${PYWRAP}_SOURCES} ${${PYWRAP}_HEADERS})
IF(BUILD_WITH_OPENMP_SUPPORT)
TARGET_COMPILE_DEFINITIONS(${PYWRAP} PRIVATE -DPINOCCHIO_PYTHON_INTERFACE_WITH_OPENMP)
TARGET_INCLUDE_DIRECTORIES(${PYWRAP} SYSTEM PRIVATE ${OpenMP_INCLUDE_DIR})
#TARGET_LINK_LIBRARIES(${PYWRAP} PRIVATE -Wl,-undefined,dynamic_lookup,${OpenMP_LIBRARIES})
ENDIF(BUILD_WITH_OPENMP_SUPPORT)
ADD_DEPENDENCIES(python ${PYWRAP})
SET_TARGET_PROPERTIES(${PYWRAP} PROPERTIES PREFIX "") # Remove lib prefix for the target
......
//
// Copyright (c) 2015-2020 CNRS INRIA
// Copyright (c) 2015-2021 CNRS INRIA
// Copyright (c) 2015 Wandercraft, 86 rue de Paris 91400 Orsay, France.
//
......@@ -43,6 +43,9 @@ namespace pinocchio
#ifdef PINOCCHIO_WITH_HPP_FCL_PYTHON_BINDINGS
void exposeFCL();
#endif // PINOCCHIO_WITH_HPP_FCL_PYTHON_BINDINGS
#ifdef PINOCCHIO_PYTHON_INTERFACE_WITH_OPENMP
void exposePool();
#endif
} // namespace python
} // namespace pinocchio
......
......@@ -96,6 +96,10 @@ BOOST_PYTHON_MODULE(pinocchio_pywrap)
exposeFCL();
#endif // PINOCCHIO_WITH_HPP_FCL_PYTHON_BINDINGS
#ifdef PINOCCHIO_PYTHON_INTERFACE_WITH_OPENMP
exposePool();
#endif
exposeVersion();
exposeDependencies();
exposeConversions();
......
//
// Copyright (c) 2021 INRIA
//
#include "pinocchio/bindings/python/fwd.hpp"
#include "pinocchio/bindings/python/multibody/pool/model.hpp"
#include "pinocchio/bindings/python/multibody/pool/geometry.hpp"
namespace pinocchio
{
namespace python
{
void exposePool()
{
ModelPoolPythonVisitor<ModelPool>::expose();
GeometryPoolPythonVisitor<GeometryPool>::expose();
}
} // namespace python
} // namespace pinocchio
//
// Copyright (c) 2021 INRIA
//
#ifndef __pinocchio_python_multibody_pool_geometry_hpp__
#define __pinocchio_python_multibody_pool_geometry_hpp__
#include <eigenpy/eigen-to-python.hpp>
#include "pinocchio/multibody/pool/geometry.hpp"
#include <boost/python/overloads.hpp>
#include <eigenpy/memory.hpp>
#include <eigenpy/exception.hpp>
#include "pinocchio/algorithm/check.hpp"
#include "pinocchio/bindings/python/utils/copyable.hpp"
#include "pinocchio/bindings/python/utils/std-vector.hpp"
EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(pinocchio::GeometryPool)
namespace pinocchio
{
namespace python
{
namespace bp = boost::python;
template<typename GeometryPool>
struct GeometryPoolPythonVisitor
: public bp::def_visitor< GeometryPoolPythonVisitor<GeometryPool> >
{
typedef typename GeometryPool::Base Base;
typedef typename GeometryPool::Model Model;
typedef typename GeometryPool::GeometryModel GeometryModel;
typedef typename GeometryPool::GeometryData GeometryData;
typedef typename GeometryPool::GeometryDataVector GeometryDataVector;
/* --- Exposing C++ API to python through the handler ----------------- */
template<class PyClass>
void visit(PyClass& cl) const
{
cl
.def(bp::init<Model,GeometryModel,bp::optional<int> >(bp::args("self","model","geometry_model","size"),
"Default constructor."))
.def(bp::init<GeometryPool>(bp::args("self","other"),
"Copy constructor."))
.def("geometry_model",(GeometryModel & (GeometryPool::*)())&GeometryPool::geometry_model,
bp::arg("self"),"Geometry model contained in the pool.",
bp::return_internal_reference<>())
.def("geometry_data",(GeometryData & (GeometryPool::*)(const size_t))&GeometryPool::geometry_data,
bp::args("self","index"),"Return a specific geometry_data data.",
bp::return_internal_reference<>())
.def("geometry_datas",(GeometryDataVector & (GeometryPool::*)())&GeometryPool::geometry_datas,
bp::arg("self"),"Returns the geometry data vector.",
bp::return_internal_reference<>())
.def("update",(void (GeometryPool::*)(const GeometryModel &))&GeometryPool::update,
bp::args("self","geometry_model"),
"Update the geometry model, meaning that all the datas will be refreshed accordingly.")
.def("update",(void (GeometryPool::*)(const GeometryData &))&GeometryPool::update,
bp::args("self","data"),"Update all the geometry datas with the input geometry data value.")
;
}
static void expose()
{
bp::class_<GeometryPool,bp::bases<Base> >("GeometryPool",
"Pool containing a model + a geometry_model and several datas for parallel computations",
bp::no_init)
.def(GeometryPoolPythonVisitor())
.def(CopyableVisitor<GeometryPool>())
;
StdVectorPythonVisitor<GeometryData,typename GeometryDataVector::allocator_type>::expose("StdVec_GeometryData");
}
};
}
}
#endif // ifnded __pinocchio_python_multibody_pool_geometry_hpp__
//
// Copyright (c) 2021 INRIA
//
#ifndef __pinocchio_python_multibody_pool_model_hpp__
#define __pinocchio_python_multibody_pool_model_hpp__
#include <eigenpy/eigen-to-python.hpp>
#include "pinocchio/multibody/pool/model.hpp"
#include <boost/python/overloads.hpp>
#include <eigenpy/memory.hpp>
#include <eigenpy/exception.hpp>
#include "pinocchio/algorithm/check.hpp"
#include "pinocchio/bindings/python/utils/copyable.hpp"
#include "pinocchio/bindings/python/utils/std-vector.hpp"
EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(pinocchio::ModelPool)
namespace pinocchio
{
namespace python
{
namespace bp = boost::python;
template<typename ModelPool>
struct ModelPoolPythonVisitor
: public bp::def_visitor< ModelPoolPythonVisitor<ModelPool> >
{
typedef typename ModelPool::Model Model;
typedef typename ModelPool::Data Data;
typedef typename ModelPool::DataVector DataVector;
/* --- Exposing C++ API to python through the handler ----------------- */
template<class PyClass>
void visit(PyClass& cl) const
{
cl
.def(bp::init<Model,bp::optional<int> >(bp::args("self","model","size"),
"Default constructor."))
.def(bp::init<ModelPool>(bp::args("self","other"),
"Copy constructor."))
.def("model",(Model & (ModelPool::*)())&ModelPool::model,
bp::arg("self"),"Model contained in the pool.",
bp::return_internal_reference<>())
.def("data",(Data & (ModelPool::*)(const size_t))&ModelPool::data,
bp::args("self","index"),"Return a specific data.",
bp::return_internal_reference<>())
.def("datas",(DataVector & (ModelPool::*)())&ModelPool::datas,
bp::arg("self"),"Returns the data vectors.",
bp::return_internal_reference<>())
.def("size",&ModelPool::size,bp::arg("self"),
"Returns the size of the pool.")
.def("resize",&ModelPool::resize,bp::args("self","new_size"),
"Resize the pool.")
.def("update",(void (ModelPool::*)(const Model &))&ModelPool::update,
bp::args("self","model"),
"Update the model, meaning that all the datas will be refreshed accordingly.")
.def("update",(void (ModelPool::*)(const Data &))&ModelPool::update,
bp::args("self","data"),"Update all the datas with the input data value.")
;
}
static void expose()
{
bp::class_<ModelPool>("ModelPool",
"Pool containing a model and several datas for parallel computations",
bp::no_init)
.def(ModelPoolPythonVisitor())
.def(CopyableVisitor<ModelPool>())
;
StdVectorPythonVisitor<Data,typename DataVector::allocator_type>::expose("StdVec_Data");
}
};
}
}
#endif // ifnded __pinocchio_python_multibody_pool_model_hpp__
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