pinocchio 4.1.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
Loading...
Searching...
No Matches
broadphase-manager.hpp
1//
2// Copyright (c) 2022-2025 INRIA
3//
4
5#pragma once
6
7#include <eigenpy/eigen-to-python.hpp>
8#include <eigenpy/copyable.hpp>
9
10#include "pinocchio/collision/pool/broadphase-manager.hpp"
11
12#include <boost/python/overloads.hpp>
13#include <boost/algorithm/string/replace.hpp>
14#include <eigenpy/memory.hpp>
15#include <eigenpy/exception.hpp>
16
17#include "pinocchio/algorithm/check.hpp"
18#include "pinocchio/bindings/python/utils/std-vector.hpp"
19
20namespace pinocchio
21{
22 namespace python
23 {
24 namespace bp = boost::python;
25
26 namespace helper
27 {
28 template<typename BroadPhaseManager>
30 {
31 static std::string get();
32 };
33
34 template<typename Manager>
35 struct base_class_name<BroadPhaseManagerTpl<Manager>>
36 {
37 static std::string get()
38 {
39 return "BroadPhaseManager";
40 }
41 };
42
43 template<typename Manager>
44 struct base_class_name<TreeBroadPhaseManagerTpl<Manager>>
45 {
46 static std::string get()
47 {
48 return "TreeBroadPhaseManager";
49 }
50 };
51 } // namespace helper
52
53 template<typename BroadPhaseManagerPool>
55 : public bp::def_visitor<BroadPhaseManagerPoolPythonVisitor<BroadPhaseManagerPool>>
56 {
57
58 typedef typename BroadPhaseManagerPool::Base Base;
59 typedef typename BroadPhaseManagerPool::Model Model;
60 typedef typename BroadPhaseManagerPool::GeometryModel GeometryModel;
61 typedef typename BroadPhaseManagerPool::GeometryData GeometryData;
62 typedef typename BroadPhaseManagerPool::BroadPhaseManagerVector BroadPhaseManagerVector;
63 typedef typename BroadPhaseManagerPool::BroadPhaseManager BroadPhaseManager;
64 typedef typename BroadPhaseManager::Manager Manager;
65
66 /* --- Exposing C++ API to python through the handler ----------------- */
67 template<class PyClass>
68 void visit(PyClass & cl) const
69 {
70 cl.def(
71 bp::init<const Model &, const GeometryModel &, bp::optional<size_t>>(
72 bp::args("self", "model", "geometry_model", "size"), "Default constructor."))
73 .def(
74 bp::init<const BroadPhaseManagerPool &>(bp::args("self", "other"), "Copy constructor."))
75
76 .def(
77 "getBroadPhaseManager",
78 (BroadPhaseManager & (BroadPhaseManagerPool::*)(const size_t))
79 & BroadPhaseManagerPool::getBroadPhaseManager,
80 bp::args("self", "index"), "Return a specific broadphase manager.",
81 bp::return_internal_reference<>())
82 .def(
83 "getBroadPhaseManagers",
84 (BroadPhaseManagerVector & (BroadPhaseManagerPool::*)())
85 & BroadPhaseManagerPool::getBroadPhaseManagers,
86 bp::arg("self"), "Returns the vector of broadphase managers.",
87 bp::return_internal_reference<>())
88
89 .def(
90 "update",
91 (void (BroadPhaseManagerPool::*)(const GeometryData &))&BroadPhaseManagerPool::update,
92 bp::args("self", "geometry_data"),
93 "Update all the geometry datas with the input geometry data value.")
94
95 .def(
96 "check", &BroadPhaseManagerPool::check, bp::arg("self"),
97 "Check whether the current pool is valid.")
98
99 .def(
100 "asGeometryPool", downcast, bp::arg("self"),
101 "Cast the object as GeometryPool (equivalent to a C++ static_cast).",
102 bp::return_self<>());
103 }
104
105 static PyObject * downcast(BroadPhaseManagerPool & self)
106 {
107 bp::type_info type = bp::type_id<Base>();
108 const bp::converter::registration * registration = bp::converter::registry::query(type);
109
110 return registration->to_python(static_cast<Base *>(&self));
111 }
112
113 static void expose()
114 {
115 std::string manager_name = boost::typeindex::type_id<Manager>().pretty_name();
116 boost::algorithm::replace_all(manager_name, "coal::", "");
117 const std::string broadphase_prefix = helper::base_class_name<BroadPhaseManager>::get();
118 const std::string class_name = broadphase_prefix + "Pool" + "_" + manager_name;
119
120 const std::string doc = "Pool containing a bunch of " + broadphase_prefix + ".";
121
122 bp::class_<BroadPhaseManagerPool, bp::bases<Base>>(
123 class_name.c_str(), doc.c_str(), bp::no_init)
125 .def(::eigenpy::CopyableVisitor<BroadPhaseManagerPool>());
126
127 const std::string vector_name = "StdVec_" + broadphase_prefix + "_" + manager_name;
128 StdVectorPythonVisitor<BroadPhaseManagerVector>::expose(vector_name);
129 }
130 };
131 } // namespace python
132} // namespace pinocchio
Main pinocchio namespace.
Definition treeview.dox:11