cpp2pybind11.cpp
Go to the documentation of this file.
2 
3 // This lines forces clang-format to keep the include split here
4 #include <pybind11/pybind11.h>
5 
6 #include <boost/python.hpp>
7 
8 #define SCALAR double
9 #define OPTIONS 0
10 #define JOINT_MODEL_COLLECTION ::pinocchio::JointCollectionDefaultTpl
12 
14 {
16  std::cout << "make_model: " << reinterpret_cast<intptr_t>(model) << std::endl;
17  return model;
18 }
19 
21 {
22  return m;
23 }
25 {
26  return &m;
27 }
28 
30 {
31  return a * b;
32 }
33 
34 template<typename T>
35 intptr_t get_ptr(T & m)
36 {
37  std::cout << &m << '\n' << m << std::endl;
38  return reinterpret_cast<intptr_t>(&m);
39 }
40 
41 void test1(int i)
42 {
43  std::cout << "no conversion: " << ' ' << i << std::endl;
44 }
46 {
47  std::cout << "testModel1: " << &model << std::endl;
48  model.name = "testModel1: I modified the model name";
49 }
51 {
52  std::cout << "testModel2: " << &model << ' ' << i << std::endl;
53  model.name = "testModel2: I modified the model name";
54  return reinterpret_cast<intptr_t>(&model);
55 }
56 intptr_t testModel3(pinocchio::Model const & model, int i)
57 {
58  std::cout << "testModel3: " << &model << ' ' << i << std::endl;
59  return reinterpret_cast<intptr_t>(&model);
60 }
61 
62 void testModel_manual(pybind11::object model)
63 {
64  testModel1(pinocchio::python::from<pinocchio::Model &>(model));
65 }
66 
68 
69 PYBIND11_MODULE(cpp2pybind11, m)
70 {
71  using namespace pybind11::literals; // For _a
72 
73  pybind11::module::import("pinocchio");
74  m.def("testModel_manual", testModel_manual);
75 
76  m.def("test1", make_pybind11_function(&test1));
77 
78  m.def("make_model", make_pybind11_function(&make_model));
79  m.def(
80  "return_same_model_broken", make_pybind11_function(&return_same_model_copy),
81  pybind11::return_value_policy::reference);
82  m.def(
83  "return_same_model", make_pybind11_function(&return_same_model_nocopy),
84  pybind11::return_value_policy::reference);
85 
86  m.def("get_ptr", make_pybind11_function(&get_ptr<pinocchio::Model>));
87  m.def("get_se3_ptr", make_pybind11_function(&get_ptr<pinocchio::SE3>));
88 
89  m.def("multiply_se3_1", make_pybind11_function(&multiply_se3), "a"_a, "b"_a);
90  m.def(
91  "multiply_se3", make_pybind11_function(&multiply_se3), "a"_a,
93  m.def("testModel1", make_pybind11_function(&testModel1));
94  m.def("testModel2", make_pybind11_function(&testModel2));
95  m.def("testModel3", make_pybind11_function(&testModel3));
96 
97  pybind11::module no_wrapper = m.def_submodule("no_wrapper");
98  no_wrapper.def(
99  "multiply_se3", &multiply_se3, "a"_a, "b"_a
100  // does not work = pinocchio::SE3::Identity()
101  );
102  no_wrapper.def("testModel1", &testModel1);
103  no_wrapper.def("testModel2", &testModel2);
104  no_wrapper.def("testModel3", &testModel3);
105 }
simulation-contact-dynamics.T
int T
Definition: simulation-contact-dynamics.py:94
pinocchio::python::make_pybind11_function
internal::function_wrapper< R(*)(Args...)> make_pybind11_function(R(*func)(Args...))
Creates a function wrapper.
Definition: pybind11.hpp:185
test-cpp2pybind11.m
m
Definition: test-cpp2pybind11.py:22
PYBIND11_MODULE
PYBIND11_MODULE(cpp2pybind11, m)
Definition: cpp2pybind11.cpp:69
pinocchio::SE3Tpl< context::Scalar, context::Options >
inverse-kinematics.i
int i
Definition: inverse-kinematics.py:20
testModel1
void testModel1(pinocchio::Model &model)
Definition: cpp2pybind11.cpp:45
testModel2
intptr_t testModel2(pinocchio::Model &model, int i)
Definition: cpp2pybind11.cpp:50
return_same_model_copy
pinocchio::Model & return_same_model_copy(pinocchio::Model &m)
Definition: cpp2pybind11.cpp:20
b
Vec3f b
anymal-simulation.model
model
Definition: anymal-simulation.py:12
pinocchio::python::default_arg
py::object default_arg(T t)
Definition: pybind11.hpp:193
testModel3
intptr_t testModel3(pinocchio::Model const &model, int i)
Definition: cpp2pybind11.cpp:56
pybind11-all.hpp
a
Vec3f a
multiply_se3
pinocchio::SE3 multiply_se3(pinocchio::SE3 const &a, pinocchio::SE3 const &b)
Definition: cpp2pybind11.cpp:29
return_same_model_nocopy
pinocchio::Model * return_same_model_nocopy(pinocchio::Model &m)
Definition: cpp2pybind11.cpp:24
make_model
pinocchio::Model * make_model()
Definition: cpp2pybind11.cpp:13
pinocchio::SE3Tpl< context::Scalar, context::Options >::Identity
static SE3Tpl Identity()
Definition: spatial/se3-tpl.hpp:136
test1
void test1(int i)
Definition: cpp2pybind11.cpp:41
get_ptr
intptr_t get_ptr(T &m)
Definition: cpp2pybind11.cpp:35
pybind11.hpp
pinocchio::ModelTpl
Definition: context/generic.hpp:20
testModel_manual
void testModel_manual(pybind11::object model)
Definition: cpp2pybind11.cpp:62
pinocchio::Model
ModelTpl< context::Scalar, context::Options > Model
Definition: multibody/fwd.hpp:33


pinocchio
Author(s):
autogenerated on Sat Jun 22 2024 02:41:46