Directory: | ./ |
---|---|
File: | include/pinocchio/bindings/python/multibody/geometry-model.hpp |
Date: | 2025-02-12 21:03:38 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 39 | 39 | 100.0% |
Branches: | 49 | 98 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | // | ||
2 | // Copyright (c) 2015-2023 CNRS INRIA | ||
3 | // | ||
4 | |||
5 | #ifndef __pinocchio_python_geometry_model_hpp__ | ||
6 | #define __pinocchio_python_geometry_model_hpp__ | ||
7 | |||
8 | #include <eigenpy/memory.hpp> | ||
9 | |||
10 | #include "pinocchio/bindings/python/utils/address.hpp" | ||
11 | #include "pinocchio/bindings/python/utils/printable.hpp" | ||
12 | #include "pinocchio/bindings/python/utils/copyable.hpp" | ||
13 | #include "pinocchio/bindings/python/utils/registration.hpp" | ||
14 | #include "pinocchio/bindings/python/utils/pickle.hpp" | ||
15 | #include "pinocchio/bindings/python/serialization/serializable.hpp" | ||
16 | |||
17 | #include "pinocchio/multibody/geometry.hpp" | ||
18 | |||
19 | #if EIGENPY_VERSION_AT_MOST(2, 8, 1) | ||
20 | EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(pinocchio::GeometryModel) | ||
21 | #endif | ||
22 | |||
23 | namespace pinocchio | ||
24 | { | ||
25 | namespace python | ||
26 | { | ||
27 | namespace bp = boost::python; | ||
28 | |||
29 | struct GeometryModelPythonVisitor | ||
30 | : public boost::python::def_visitor<GeometryModelPythonVisitor> | ||
31 | { | ||
32 | public: | ||
33 | /* --- Exposing C++ API to python through the handler ----------------- */ | ||
34 | template<class PyClass> | ||
35 | 65 | void visit(PyClass & cl) const | |
36 | { | ||
37 |
2/4✓ Branch 2 taken 65 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 65 times.
✗ Branch 6 not taken.
|
65 | cl.def(bp::init<>(bp::arg("self"), "Default constructor")) |
38 |
3/6✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 65 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 65 times.
✗ Branch 8 not taken.
|
130 | .def(bp::init<const GeometryModel &>(bp::args("self", "other"), "Copy constructor")) |
39 | |||
40 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .add_property( |
41 | "ngeoms", &GeometryModel::ngeoms, | ||
42 | "Number of geometries contained in the Geometry Model.") | ||
43 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .add_property( |
44 | "geometryObjects", &GeometryModel::geometryObjects, "Vector of geometries objects.") | ||
45 | |||
46 |
2/4✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 65 times.
✗ Branch 5 not taken.
|
130 | .def( |
47 | "addGeometryObject", | ||
48 | static_cast<GeometryModel::GeomIndex (GeometryModel::*)(const GeometryObject &)>( | ||
49 | &GeometryModel::addGeometryObject), | ||
50 | bp::args("self", "geometry_object"), | ||
51 | "Add a GeometryObject to a GeometryModel.\n" | ||
52 | "Parameters\n" | ||
53 | "\tgeometry_object : a GeometryObject\n") | ||
54 |
2/4✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 65 times.
✗ Branch 5 not taken.
|
130 | .def( |
55 | "addGeometryObject", | ||
56 | static_cast<GeometryModel::GeomIndex (GeometryModel::*)( | ||
57 | const GeometryObject &, const Model &)>(&GeometryModel::addGeometryObject), | ||
58 | bp::args("self", "geometry_object", "model"), | ||
59 | "Add a GeometryObject to a GeometryModel and set its parent joint by reading its " | ||
60 | "value in the model.\n" | ||
61 | "Parameters\n" | ||
62 | "\tgeometry_object : a GeometryObject\n" | ||
63 | "\tmodel : a Model of the system\n") | ||
64 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
130 | .def( |
65 | "removeGeometryObject", &GeometryModel::removeGeometryObject, bp::args("self", "name"), | ||
66 | "Remove a GeometryObject. Remove also the collision pairs that contain the object.") | ||
67 |
2/4✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 65 times.
✗ Branch 5 not taken.
|
130 | .def( |
68 | "getGeometryId", &GeometryModel::getGeometryId, bp::args("self", "name"), | ||
69 | "Returns the index of a GeometryObject given by its name.") | ||
70 |
2/4✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 65 times.
✗ Branch 5 not taken.
|
130 | .def( |
71 | "existGeometryName", &GeometryModel::existGeometryName, bp::args("self", "name"), | ||
72 | "Checks if a GeometryObject given by its name exists.") | ||
73 |
2/4✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 65 times.
✗ Branch 5 not taken.
|
130 | .def( |
74 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
130 | "createData", &GeometryModelPythonVisitor::createData, bp::arg("self"), |
75 | "Create a GeometryData associated to the current model.") | ||
76 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
130 | .def("clone", &GeometryModel::clone, bp::arg("self"), "Create a deep copy of *this.") |
77 |
2/4✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 65 times.
✗ Branch 5 not taken.
|
65 | .add_property( |
78 | "collisionPairs", &GeometryModel::collisionPairs, "Vector of collision pairs.") | ||
79 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .add_property( |
80 | "collisionPairMapping", &GeometryModel::collisionPairMapping, | ||
81 | "Matrix relating the collision pair ID to a pair of two GeometryObject indexes.") | ||
82 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
130 | .def( |
83 | "addCollisionPair", &GeometryModel::addCollisionPair, | ||
84 | bp::args("self", "collision_pair"), | ||
85 | "Add a collision pair given by the index of the two collision objects.") | ||
86 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def( |
87 | "addAllCollisionPairs", &GeometryModel::addAllCollisionPairs, | ||
88 | "Add all collision pairs.\n" | ||
89 | "note : collision pairs between geometries having the same parent joint are not added.") | ||
90 |
2/4✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 65 times.
✗ Branch 5 not taken.
|
130 | .def( |
91 | "setCollisionPairs", &GeometryModel::setCollisionPairs, | ||
92 |
5/10✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 65 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 65 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 65 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 65 times.
✗ Branch 14 not taken.
|
195 | (bp::arg("self"), bp::arg("collision_map"), bp::arg("upper") = true), |
93 | "Set the collision pairs from a given input array.\n" | ||
94 | "Each entry of the input matrix defines the activation of a given collision pair" | ||
95 | "(map[i,j] == True means that the pair (i,j) is active).") | ||
96 |
2/4✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 65 times.
✗ Branch 5 not taken.
|
130 | .def( |
97 | "removeCollisionPair", &GeometryModel::removeCollisionPair, | ||
98 | bp::args("self", "collision_pair"), "Remove a collision pair.") | ||
99 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def( |
100 | "removeAllCollisionPairs", &GeometryModel::removeAllCollisionPairs, | ||
101 | "Remove all collision pairs.") | ||
102 |
2/4✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 65 times.
✗ Branch 5 not taken.
|
130 | .def( |
103 | "existCollisionPair", &GeometryModel::existCollisionPair, | ||
104 | bp::args("self", "collision_pair"), "Check if a collision pair exists.") | ||
105 |
2/4✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 65 times.
✗ Branch 5 not taken.
|
130 | .def( |
106 | "findCollisionPair", &GeometryModel::findCollisionPair, | ||
107 | bp::args("self", "collision_pair"), "Return the index of a collision pair.") | ||
108 | |||
109 |
2/4✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 65 times.
✗ Branch 6 not taken.
|
65 | .def(bp::self == bp::self) |
110 |
1/2✓ Branch 2 taken 65 times.
✗ Branch 3 not taken.
|
65 | .def(bp::self != bp::self); |
111 | |||
112 | 65 | bp::register_ptr_to_python<std::shared_ptr<GeometryModel>>(); | |
113 | 65 | } | |
114 | |||
115 | 38 | static GeometryData createData(const GeometryModel & geomModel) | |
116 | { | ||
117 | 38 | return GeometryData(geomModel); | |
118 | } | ||
119 | |||
120 | /* --- Expose --------------------------------------------------------- */ | ||
121 | 65 | static void expose() | |
122 | { | ||
123 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | if (!register_symbolic_link_to_registered_type<GeometryModel>()) |
124 | { | ||
125 | 130 | bp::class_<GeometryModel>( | |
126 | "GeometryModel", | ||
127 | "Geometry model containing the collision or visual geometries associated to a model.", | ||
128 | bp::no_init) | ||
129 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def(GeometryModelPythonVisitor()) |
130 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def(PrintableVisitor<GeometryModel>()) |
131 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def(SerializableVisitor<GeometryModel>()) |
132 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def(CopyableVisitor<GeometryModel>()) |
133 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def(AddressVisitor<GeometryModel>()) |
134 | #ifndef PINOCCHIO_PYTHON_NO_SERIALIZATION | ||
135 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def_pickle(PickleFromStringSerialization<GeometryModel>()) |
136 | #endif | ||
137 | ; | ||
138 | } | ||
139 | 65 | } | |
140 | }; | ||
141 | |||
142 | } // namespace python | ||
143 | } // namespace pinocchio | ||
144 | |||
145 | #endif // ifndef __pinocchio_python_geometry_model_hpp__ | ||
146 |