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 }
ModelTpl< double > Model
PYBIND11_MODULE(cpp2pybind11, m)
Vec3f b
internal::function_wrapper< R(*)(Args...)> make_pybind11_function(R(*func)(Args...))
Creates a function wrapper.
Definition: pybind11.hpp:161
pinocchio::SE3 multiply_se3(pinocchio::SE3 const &a, pinocchio::SE3 const &b)
void test1(int i)
pinocchio::Model * make_model()
pinocchio::Model * return_same_model_nocopy(pinocchio::Model &m)
intptr_t testModel2(pinocchio::Model &model, int i)
std::string name
Model name;.
pinocchio::Model & return_same_model_copy(pinocchio::Model &m)
intptr_t get_ptr(T &m)
intptr_t testModel3(pinocchio::Model const &model, int i)
void testModel1(pinocchio::Model &model)
void testModel_manual(pybind11::object model)
Vec3f a
float m
py::object default_arg(T t)
Definition: pybind11.hpp:169


pinocchio
Author(s):
autogenerated on Fri Jun 23 2023 02:38:29