pinocchio  3.7.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
 
Loading...
Searching...
No Matches
model.hpp
1//
2// Copyright (c) 2021-2022 INRIA
3//
4
5#ifndef __pinocchio_python_multibody_pool_model_hpp__
6#define __pinocchio_python_multibody_pool_model_hpp__
7
8#include <eigenpy/eigen-to-python.hpp>
9
10#include "pinocchio/multibody/pool/model.hpp"
11
12#include <boost/python/overloads.hpp>
13#include <eigenpy/memory.hpp>
14#include <eigenpy/exception.hpp>
15
16#include "pinocchio/algorithm/check.hpp"
17#include "pinocchio/bindings/python/utils/copyable.hpp"
18#include "pinocchio/bindings/python/utils/std-vector.hpp"
19
20#if EIGENPY_VERSION_AT_MOST(2, 8, 1)
21EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(pinocchio::ModelPool)
22#endif
23
24namespace pinocchio
25{
26 namespace python
27 {
28 namespace bp = boost::python;
29
30 template<typename ModelPool>
31 struct ModelPoolPythonVisitor : public bp::def_visitor<ModelPoolPythonVisitor<ModelPool>>
32 {
33
34 typedef typename ModelPool::Model Model;
35 typedef typename ModelPool::Data Data;
36 typedef typename ModelPool::ModelVector ModelVector;
37 typedef typename ModelPool::DataVector DataVector;
38
39 /* --- Exposing C++ API to python through the handler ----------------- */
40 template<class PyClass>
41 void visit(PyClass & cl) const
42 {
43 cl.def(bp::init<const Model &, bp::optional<size_t>>(
44 bp::args("self", "model", "size"), "Default constructor."))
45 .def(bp::init<const ModelPool &>(bp::args("self", "other"), "Copy constructor."))
46
47 .def(
48 "getModel", (Model & (ModelPool::*)(const size_t)) & ModelPool::getModel,
49 bp::args("self", "index"), "Return a specific model.",
50 bp::return_internal_reference<>())
51 .def(
52 "getModels", (ModelVector & (ModelPool::*)()) & ModelPool::getModels, bp::arg("self"),
53 "Returns the model vectors.", bp::return_internal_reference<>())
54
55 .def(
56 "getData", (Data & (ModelPool::*)(const size_t)) & ModelPool::getData,
57 bp::args("self", "index"), "Return a specific data.", bp::return_internal_reference<>())
58 .def(
59 "getDatas", (DataVector & (ModelPool::*)()) & ModelPool::getDatas, bp::arg("self"),
60 "Returns the data vectors.", bp::return_internal_reference<>())
61
62 .def("size", &ModelPool::size, bp::arg("self"), "Returns the size of the pool.")
63 .def("resize", &ModelPool::resize, bp::args("self", "new_size"), "Resize the pool.")
64
65 .def(
66 "update", (void(ModelPool::*)(const Data &)) & ModelPool::update,
67 bp::args("self", "data"), "Update all the datas with the input data value.");
68 }
69
70 static void expose()
71 {
72
73 bp::class_<ModelPool>(
74 "ModelPool", "Pool containing a model and several datas for parallel computations",
75 bp::no_init)
76 .def(ModelPoolPythonVisitor())
77 .def(CopyableVisitor<ModelPool>());
78
79 StdVectorPythonVisitor<ModelVector>::expose("StdVec_Model");
80 StdVectorPythonVisitor<DataVector>::expose("StdVec_Data");
81 }
82 };
83 } // namespace python
84} // namespace pinocchio
85
86#endif // ifnded __pinocchio_python_multibody_pool_model_hpp__
Main pinocchio namespace.
Definition treeview.dox:11