Directory: | ./ |
---|---|
File: | include/pinocchio/bindings/python/multibody/geometry-model.hpp |
Date: | 2024-08-27 18:20:05 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 38 | 38 | 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 | 20 | void visit(PyClass & cl) const | |
36 | { | ||
37 |
2/4✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 20 times.
✗ Branch 6 not taken.
|
20 | cl.def(bp::init<>(bp::arg("self"), "Default constructor")) |
38 |
3/6✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
|
40 | .def(bp::init<const GeometryModel &>(bp::args("self", "other"), "Copy constructor")) |
39 | |||
40 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | .add_property( |
41 | "ngeoms", &GeometryModel::ngeoms, | ||
42 | "Number of geometries contained in the Geometry Model.") | ||
43 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | .add_property( |
44 | "geometryObjects", &GeometryModel::geometryObjects, "Vector of geometries objects.") | ||
45 | |||
46 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
40 | .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 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
40 | .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 20 times.
✗ Branch 2 not taken.
|
40 | .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 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
40 | .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 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
40 | .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 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
40 | .def( |
74 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
40 | "createData", &GeometryModelPythonVisitor::createData, bp::arg("self"), |
75 | "Create a GeometryData associated to the current model.") | ||
76 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
40 | .def("clone", &GeometryModel::clone, bp::arg("self"), "Create a deep copy of *this.") |
77 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
20 | .add_property( |
78 | "collisionPairs", &GeometryModel::collisionPairs, "Vector of collision pairs.") | ||
79 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | .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 20 times.
✗ Branch 2 not taken.
|
40 | .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 20 times.
✗ Branch 2 not taken.
|
20 | .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 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
40 | .def( |
91 | "setCollisionPairs", &GeometryModel::setCollisionPairs, | ||
92 |
5/10✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 20 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 20 times.
✗ Branch 14 not taken.
|
60 | (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 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
40 | .def( |
97 | "removeCollisionPair", &GeometryModel::removeCollisionPair, | ||
98 | bp::args("self", "collision_pair"), "Remove a collision pair.") | ||
99 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | .def( |
100 | "removeAllCollisionPairs", &GeometryModel::removeAllCollisionPairs, | ||
101 | "Remove all collision pairs.") | ||
102 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
40 | .def( |
103 | "existCollisionPair", &GeometryModel::existCollisionPair, | ||
104 | bp::args("self", "collision_pair"), "Check if a collision pair exists.") | ||
105 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
40 | .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 20 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 20 times.
✗ Branch 6 not taken.
|
20 | .def(bp::self == bp::self) |
110 |
1/2✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
20 | .def(bp::self != bp::self); |
111 | 20 | } | |
112 | |||
113 | 12 | static GeometryData createData(const GeometryModel & geomModel) | |
114 | { | ||
115 | 12 | return GeometryData(geomModel); | |
116 | } | ||
117 | |||
118 | /* --- Expose --------------------------------------------------------- */ | ||
119 | 20 | static void expose() | |
120 | { | ||
121 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | if (!register_symbolic_link_to_registered_type<GeometryModel>()) |
122 | { | ||
123 | 40 | bp::class_<GeometryModel>( | |
124 | "GeometryModel", | ||
125 | "Geometry model containing the collision or visual geometries associated to a model.", | ||
126 | bp::no_init) | ||
127 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | .def(GeometryModelPythonVisitor()) |
128 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | .def(PrintableVisitor<GeometryModel>()) |
129 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | .def(SerializableVisitor<GeometryModel>()) |
130 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | .def(CopyableVisitor<GeometryModel>()) |
131 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | .def(AddressVisitor<GeometryModel>()) |
132 | #ifndef PINOCCHIO_PYTHON_NO_SERIALIZATION | ||
133 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | .def_pickle(PickleFromStringSerialization<GeometryModel>()) |
134 | #endif | ||
135 | ; | ||
136 | } | ||
137 | 20 | } | |
138 | }; | ||
139 | |||
140 | } // namespace python | ||
141 | } // namespace pinocchio | ||
142 | |||
143 | #endif // ifndef __pinocchio_python_geometry_model_hpp__ | ||
144 |