Directory: | ./ |
---|---|
File: | include/pinocchio/bindings/python/multibody/geometry-data.hpp |
Date: | 2025-02-12 21:03:38 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 50 | 50 | 100.0% |
Branches: | 66 | 132 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | // | ||
2 | // Copyright (c) 2015-2022 CNRS INRIA | ||
3 | // | ||
4 | |||
5 | #ifndef __pinocchio_python_geometry_data_hpp__ | ||
6 | #define __pinocchio_python_geometry_data_hpp__ | ||
7 | |||
8 | #include <eigenpy/memory.hpp> | ||
9 | |||
10 | #include "pinocchio/serialization/geometry.hpp" | ||
11 | |||
12 | #include "pinocchio/bindings/python/utils/address.hpp" | ||
13 | #include "pinocchio/bindings/python/utils/printable.hpp" | ||
14 | #include "pinocchio/bindings/python/utils/copyable.hpp" | ||
15 | #include "pinocchio/bindings/python/utils/std-vector.hpp" | ||
16 | #include "pinocchio/bindings/python/utils/registration.hpp" | ||
17 | #include "pinocchio/bindings/python/serialization/serializable.hpp" | ||
18 | |||
19 | #if EIGENPY_VERSION_AT_MOST(2, 8, 1) | ||
20 | EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(pinocchio::GeometryData) | ||
21 | #endif | ||
22 | |||
23 | namespace pinocchio | ||
24 | { | ||
25 | namespace python | ||
26 | { | ||
27 | namespace bp = boost::python; | ||
28 | |||
29 | /* --- COLLISION PAIR --------------------------------------------------- */ | ||
30 | /* --- COLLISION PAIR --------------------------------------------------- */ | ||
31 | /* --- COLLISION PAIR --------------------------------------------------- */ | ||
32 | struct CollisionPairPythonVisitor | ||
33 | : public boost::python::def_visitor<CollisionPairPythonVisitor> | ||
34 | { | ||
35 | 65 | static void expose() | |
36 | { | ||
37 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | if (!register_symbolic_link_to_registered_type<CollisionPair>()) |
38 | { | ||
39 | 65 | bp::class_<CollisionPair>( | |
40 | "CollisionPair", "Pair of ordered index defining a pair of collisions", bp::no_init) | ||
41 |
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<>(bp::args("self"), "Empty constructor.")) |
42 |
2/4✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 65 times.
✗ Branch 5 not taken.
|
65 | .def(bp::init<const GeomIndex &, const GeomIndex &>( |
43 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
130 | bp::args("self", "index1", "index2"), "Initializer of collision pair.")) |
44 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def(PrintableVisitor<CollisionPair>()) |
45 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def(CopyableVisitor<CollisionPair>()) |
46 |
1/2✓ Branch 2 taken 65 times.
✗ Branch 3 not taken.
|
65 | .def(bp::self == bp::self) |
47 |
1/2✓ Branch 2 taken 65 times.
✗ Branch 3 not taken.
|
65 | .def(bp::self != bp::self) |
48 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def_readwrite("first", &CollisionPair::first) |
49 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def_readwrite("second", &CollisionPair::second); |
50 | |||
51 |
3/6✓ Branch 2 taken 65 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 65 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 65 times.
✗ Branch 10 not taken.
|
65 | StdVectorPythonVisitor<std::vector<CollisionPair>>::expose("StdVec_CollisionPair"); |
52 | 65 | serialize<std::vector<CollisionPair>>(); | |
53 | } | ||
54 | 65 | } | |
55 | }; // struct CollisionPairPythonVisitor | ||
56 | |||
57 | struct GeometryDataPythonVisitor : public boost::python::def_visitor<GeometryDataPythonVisitor> | ||
58 | { | ||
59 | |||
60 | /* --- Exposing C++ API to python through the handler ----------------- */ | ||
61 | template<class PyClass> | ||
62 | 65 | void visit(PyClass & cl) const | |
63 | { | ||
64 | cl | ||
65 |
2/4✓ Branch 2 taken 65 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 65 times.
✗ Branch 6 not taken.
|
65 | .def(bp::init<const GeometryModel &>( |
66 | bp::args("self", "geometry_model"), "Default constructor from a given GeometryModel.")) | ||
67 | |||
68 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def_readwrite( |
69 | "oMg", &GeometryData::oMg, | ||
70 | "Vector of collision objects placement relative to the world frame.\n" | ||
71 | "note: These quantities have to be updated by calling updateGeometryPlacements.") | ||
72 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def_readwrite( |
73 | "activeCollisionPairs", &GeometryData::activeCollisionPairs, | ||
74 | "Vector of active CollisionPairs") | ||
75 | |||
76 | #ifdef PINOCCHIO_WITH_HPP_FCL | ||
77 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def_readwrite( |
78 | "distanceRequests", &GeometryData::distanceRequests, | ||
79 | "Defines which information should be computed by FCL for distance computations") | ||
80 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def_readwrite( |
81 | "distanceResults", &GeometryData::distanceResults, "Vector of distance results.") | ||
82 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def_readwrite( |
83 | "collisionRequests", &GeometryData::collisionRequests, | ||
84 | "Defines which information should be computed by FCL for collision computations.\n\n" | ||
85 | "Note: it is possible to define a security_margin and a break_distance for a collision " | ||
86 | "request.\n" | ||
87 | "Most likely, for robotics application, these thresholds will be different for each " | ||
88 | "collision pairs\n" | ||
89 | "(e.g. the two hands can have a large security margin while the two hips cannot.)") | ||
90 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def_readwrite( |
91 | "collisionResults", &GeometryData::collisionResults, "Vector of collision results.") | ||
92 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def_readwrite( |
93 | "collision_functors", &GeometryData::collision_functors, | ||
94 | "Vector of collision functors.") | ||
95 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def_readwrite( |
96 | "distance_functors", &GeometryData::distance_functors, "Vector of distance functors.") | ||
97 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def_readwrite( |
98 | "radius", &GeometryData::radius, | ||
99 | "Vector of radius of bodies, i.e. the distance between the further point of the " | ||
100 | "geometry object from the joint center.\n" | ||
101 | "note: This radius information might be usuful in continuous collision checking") | ||
102 | #endif // PINOCCHIO_WITH_HPP_FCL | ||
103 | |||
104 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
130 | .def( |
105 | "fillInnerOuterObjectMaps", &GeometryData::fillInnerOuterObjectMaps, | ||
106 | bp::args("self", "geometry_model"), "Fill inner and outer objects maps") | ||
107 |
2/4✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 65 times.
✗ Branch 5 not taken.
|
130 | .def( |
108 | "activateCollisionPair", | ||
109 | static_cast<void (GeometryData::*)(const PairIndex)>( | ||
110 | &GeometryData::activateCollisionPair), | ||
111 | bp::args("self", "pair_id"), | ||
112 | "Activate the collsion pair pair_id in geomModel.collisionPairs if it exists.\n" | ||
113 | "note: Only active pairs are check for collision and distance computations.") | ||
114 |
2/4✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 65 times.
✗ Branch 5 not taken.
|
130 | .def( |
115 | "setGeometryCollisionStatus", &GeometryData::setGeometryCollisionStatus, | ||
116 | bp::args("self", "geom_model", "geom_id", "enable_collision"), | ||
117 | "Enable or disable collision for the given geometry given by its geometry id with " | ||
118 | "all the other geometries registered in the list of collision pairs.") | ||
119 |
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.
|
195 | .def( |
120 | "setActiveCollisionPairs", &GeometryData::setActiveCollisionPairs, | ||
121 |
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.
|
195 | (bp::arg("self"), bp::arg("geometry_model"), bp::arg("collision_map"), |
122 |
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 | bp::arg("upper") = true), |
123 | "Set the collision pair association from a given input array.\n" | ||
124 | "Each entry of the input matrix defines the activation of a given collision pair.") | ||
125 |
2/4✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 65 times.
✗ Branch 5 not taken.
|
130 | .def( |
126 | "deactivateCollisionPair", &GeometryData::deactivateCollisionPair, | ||
127 | bp::args("self", "pair_id"), | ||
128 | "Deactivate the collsion pair pair_id in geomModel.collisionPairs if it exists.") | ||
129 |
2/4✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 65 times.
✗ Branch 5 not taken.
|
130 | .def( |
130 | "deactivateAllCollisionPairs", &GeometryData::deactivateAllCollisionPairs, | ||
131 | bp::args("self"), "Deactivate all collision pairs.") | ||
132 | #ifdef PINOCCHIO_WITH_HPP_FCL | ||
133 |
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.
|
195 | .def( |
134 | "setSecurityMargins", &GeometryData::setSecurityMargins, | ||
135 |
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.
|
195 | (bp::arg("self"), bp::arg("geometry_model"), bp::arg("security_margin_map"), |
136 |
6/12✓ 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.
✓ Branch 16 taken 65 times.
✗ Branch 17 not taken.
|
130 | bp::arg("upper") = true, bp::arg("sync_distance_upper_bound") = true), |
137 | "Set the security margin of all the collision request in a row, according to the " | ||
138 | "values stored in the associative map.") | ||
139 | #endif // PINOCCHIO_WITH_HPP_FCL | ||
140 | |||
141 |
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) |
142 |
1/2✓ Branch 2 taken 65 times.
✗ Branch 3 not taken.
|
65 | .def(bp::self != bp::self) |
143 | |||
144 | ; | ||
145 | |||
146 | 65 | bp::register_ptr_to_python<std::shared_ptr<GeometryData>>(); | |
147 | 65 | } | |
148 | |||
149 | /* --- Expose --------------------------------------------------------- */ | ||
150 | 65 | static void expose() | |
151 | { | ||
152 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | if (!register_symbolic_link_to_registered_type<GeometryData>()) |
153 | { | ||
154 | 130 | bp::class_<GeometryData>( | |
155 | "GeometryData", "Geometry data linked to a Geometry Model and a Data struct.", | ||
156 | bp::no_init) | ||
157 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def(GeometryDataPythonVisitor()) |
158 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def(PrintableVisitor<GeometryData>()) |
159 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def(CopyableVisitor<GeometryData>()) |
160 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def(SerializableVisitor<GeometryData>()) |
161 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def(AddressVisitor<GeometryModel>()); |
162 | } | ||
163 | 65 | } | |
164 | }; | ||
165 | |||
166 | } // namespace python | ||
167 | } // namespace pinocchio | ||
168 | |||
169 | #endif // ifndef __pinocchio_python_geometry_data_hpp__ | ||
170 |