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 
15  std::cout << "make_model: " << reinterpret_cast<intptr_t>(model) << std::endl;
16  return model;
17 }
18 
21 
23  return a * b;
24 }
25 
26 template <typename T>
27 intptr_t get_ptr(T& m) {
28  std::cout << &m << '\n' << m << std::endl;
29  return reinterpret_cast<intptr_t>(&m);
30 }
31 
32 void test1(int i) { std::cout << "no conversion: " << ' ' << i << std::endl; }
34  std::cout << "testModel1: " << &model << std::endl;
35  model.name = "testModel1: I modified the model name";
36 }
38  std::cout << "testModel2: " << &model << ' ' << i << std::endl;
39  model.name = "testModel2: I modified the model name";
40  return reinterpret_cast<intptr_t>(&model);
41 }
42 intptr_t testModel3(pinocchio::Model const& model, int i) {
43  std::cout << "testModel3: " << &model << ' ' << i << std::endl;
44  return reinterpret_cast<intptr_t>(&model);
45 }
46 
47 void testModel_manual(pybind11::object model) {
48  testModel1(pinocchio::python::from<pinocchio::Model&>(model));
49 }
50 
52 
53 PYBIND11_MODULE(cpp2pybind11, m) {
54  using namespace pybind11::literals; // For _a
55 
56  pybind11::module::import("pinocchio");
57  m.def("testModel_manual", testModel_manual);
58 
59  m.def("test1", make_pybind11_function(&test1));
60 
61  m.def("make_model", make_pybind11_function(&make_model));
62  m.def("return_same_model_broken", make_pybind11_function(&return_same_model_copy),
63  pybind11::return_value_policy::reference);
64  m.def("return_same_model", make_pybind11_function(&return_same_model_nocopy),
65  pybind11::return_value_policy::reference);
66 
67  m.def("get_ptr", make_pybind11_function(&get_ptr<pinocchio::Model>));
68  m.def("get_se3_ptr", make_pybind11_function(&get_ptr<pinocchio::SE3>));
69 
70  m.def("multiply_se3_1", make_pybind11_function(&multiply_se3), "a"_a, "b"_a);
71  m.def("multiply_se3", make_pybind11_function(&multiply_se3), "a"_a,
73  m.def("testModel1", make_pybind11_function(&testModel1));
74  m.def("testModel2", make_pybind11_function(&testModel2));
75  m.def("testModel3", make_pybind11_function(&testModel3));
76 
77  pybind11::module no_wrapper = m.def_submodule("no_wrapper");
78  no_wrapper.def("multiply_se3", &multiply_se3, "a"_a,
79  "b"_a
80  // does not work = pinocchio::SE3::Identity()
81  );
82  no_wrapper.def("testModel1", &testModel1);
83  no_wrapper.def("testModel2", &testModel2);
84  no_wrapper.def("testModel3", &testModel3);
85 }
m
float m
pinocchio::python::make_pybind11_function
internal::function_wrapper< R(*)(Args...)> make_pybind11_function(R(*func)(Args...))
Creates a function wrapper.
Definition: pybind11.hpp:161
PYBIND11_MODULE
PYBIND11_MODULE(cpp2pybind11, m)
Definition: cpp2pybind11.cpp:53
simulation-pendulum.T
int T
Definition: simulation-pendulum.py:113
pinocchio::SE3Tpl< double, 0 >
inverse-kinematics.i
int i
Definition: inverse-kinematics.py:20
testModel1
void testModel1(pinocchio::Model &model)
Definition: cpp2pybind11.cpp:33
testModel2
intptr_t testModel2(pinocchio::Model &model, int i)
Definition: cpp2pybind11.cpp:37
append-urdf-model-with-another-model.model
model
Definition: append-urdf-model-with-another-model.py:59
return_same_model_copy
pinocchio::Model & return_same_model_copy(pinocchio::Model &m)
Definition: cpp2pybind11.cpp:19
b
Vec3f b
pinocchio::python::default_arg
py::object default_arg(T t)
Definition: pybind11.hpp:169
testModel3
intptr_t testModel3(pinocchio::Model const &model, int i)
Definition: cpp2pybind11.cpp:42
pybind11-all.hpp
a
Vec3f a
pinocchio::Model
ModelTpl< double > Model
Definition: multibody/fwd.hpp:35
multiply_se3
pinocchio::SE3 multiply_se3(pinocchio::SE3 const &a, pinocchio::SE3 const &b)
Definition: cpp2pybind11.cpp:22
return_same_model_nocopy
pinocchio::Model * return_same_model_nocopy(pinocchio::Model &m)
Definition: cpp2pybind11.cpp:20
make_model
pinocchio::Model * make_model()
Definition: cpp2pybind11.cpp:13
pinocchio::SE3Tpl< double, 0 >::Identity
static SE3Tpl Identity()
Definition: spatial/se3-tpl.hpp:106
test1
void test1(int i)
Definition: cpp2pybind11.cpp:32
get_ptr
intptr_t get_ptr(T &m)
Definition: cpp2pybind11.cpp:27
pybind11.hpp
pinocchio::ModelTpl
Definition: multibody/fwd.hpp:23
testModel_manual
void testModel_manual(pybind11::object model)
Definition: cpp2pybind11.cpp:47


pinocchio
Author(s):
autogenerated on Tue Feb 13 2024 03:43:58