| Directory: | ./ |
|---|---|
| File: | include/pinocchio/bindings/python/multibody/geometry-object.hpp |
| Date: | 2025-02-12 21:03:38 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 73 | 79 | 92.4% |
| Branches: | 98 | 222 | 44.1% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2017-2023 CNRS INRIA | ||
| 3 | // | ||
| 4 | |||
| 5 | #ifndef __pinocchio_python_geometry_object_hpp__ | ||
| 6 | #define __pinocchio_python_geometry_object_hpp__ | ||
| 7 | |||
| 8 | #include <eigenpy/memory.hpp> | ||
| 9 | #include <eigenpy/eigen-from-python.hpp> | ||
| 10 | #include <eigenpy/eigen-to-python.hpp> | ||
| 11 | #include <eigenpy/variant.hpp> | ||
| 12 | |||
| 13 | #include "pinocchio/bindings/python/utils/address.hpp" | ||
| 14 | #include "pinocchio/bindings/python/utils/copyable.hpp" | ||
| 15 | #include "pinocchio/bindings/python/utils/registration.hpp" | ||
| 16 | #include "pinocchio/bindings/python/utils/deprecation.hpp" | ||
| 17 | #include "pinocchio/bindings/python/utils/pickle.hpp" | ||
| 18 | #include "pinocchio/bindings/python/serialization/serializable.hpp" | ||
| 19 | |||
| 20 | #include "pinocchio/multibody/geometry.hpp" | ||
| 21 | |||
| 22 | #if EIGENPY_VERSION_AT_MOST(2, 8, 1) | ||
| 23 | EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(pinocchio::GeometryObject) | ||
| 24 | #endif | ||
| 25 | |||
| 26 | namespace pinocchio | ||
| 27 | { | ||
| 28 | namespace python | ||
| 29 | { | ||
| 30 | namespace bp = boost::python; | ||
| 31 | |||
| 32 | struct GeometryObjectPythonVisitor | ||
| 33 | : public boost::python::def_visitor<GeometryObjectPythonVisitor> | ||
| 34 | { | ||
| 35 | |||
| 36 | typedef GeometryObject::CollisionGeometryPtr CollisionGeometryPtr; | ||
| 37 | |||
| 38 | template<class PyClass> | ||
| 39 | 65 | void visit(PyClass & cl) const | |
| 40 | { | ||
| 41 | typedef eigenpy::VariantConverter<GeometryMaterial> Converter; | ||
| 42 | 65 | Converter::registration(); | |
| 43 | |||
| 44 |
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< |
| 45 | std::string, JointIndex, FrameIndex, const SE3 &, CollisionGeometryPtr, | ||
| 46 | bp::optional< | ||
| 47 | std::string, const Eigen::Vector3d &, bool, const Eigen::Vector4d &, std::string, | ||
| 48 | GeometryMaterial>>( | ||
| 49 | bp::args( | ||
| 50 | "self", "name", "parent_joint", "parent_frame", "placement", | ||
| 51 | "collision_geometry", "mesh_path", "mesh_scale", "override_material", | ||
| 52 | "mesh_color", "mesh_texture_path", "mesh_material"), | ||
| 53 | "Full constructor of a GeometryObject.")) | ||
| 54 |
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< |
| 55 | std::string, JointIndex, const SE3 &, CollisionGeometryPtr, | ||
| 56 | bp::optional< | ||
| 57 | std::string, const Eigen::Vector3d &, bool, const Eigen::Vector4d &, std::string, | ||
| 58 | GeometryMaterial>>( | ||
| 59 | bp::args( | ||
| 60 | "self", "name", "parent_joint", "placement", "collision_geometry", "mesh_path", | ||
| 61 | "mesh_scale", "override_material", "mesh_color", "mesh_texture_path", | ||
| 62 | "mesh_material"), | ||
| 63 | "Reduced constructor of a GeometryObject. This constructor does not require to specify " | ||
| 64 | "the parent frame index.")) | ||
| 65 |
4/8✓ 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.
|
195 | .def(bp::init< |
| 66 | std::string, FrameIndex, JointIndex, CollisionGeometryPtr, const SE3 &, | ||
| 67 | bp::optional< | ||
| 68 | std::string, const Eigen::Vector3d &, bool, const Eigen::Vector4d &, std::string, | ||
| 69 | GeometryMaterial>>( | ||
| 70 | bp::args( | ||
| 71 | "self", "name", "parent_frame", "parent_joint", "collision_geometry", "placement", | ||
| 72 | "mesh_path", "mesh_scale", "override_material", "mesh_color", | ||
| 73 | "mesh_texture_path" | ||
| 74 | "mesh_material"), | ||
| 75 |
2/4✓ Branch 2 taken 65 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 65 times.
✗ Branch 6 not taken.
|
130 | "Deprecated. Full constructor of a GeometryObject.")[deprecated_function<>()]) |
| 76 |
4/8✓ 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.
|
195 | .def(bp::init< |
| 77 | std::string, JointIndex, CollisionGeometryPtr, const SE3 &, | ||
| 78 | bp::optional< | ||
| 79 | std::string, const Eigen::Vector3d &, bool, const Eigen::Vector4d &, std::string, | ||
| 80 | GeometryMaterial>>( | ||
| 81 | bp::args( | ||
| 82 | "self", "name", "parent_joint", "collision_geometry", "placement", "mesh_path", | ||
| 83 | "mesh_scale", "override_material", "mesh_color", "mesh_texture_path", | ||
| 84 | "mesh_material"), | ||
| 85 | "Deprecated. Reduced constructor of a GeometryObject. This constructor does not " | ||
| 86 |
2/4✓ Branch 2 taken 65 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 65 times.
✗ Branch 6 not taken.
|
130 | "require to specify the parent frame index.")[deprecated_function<>()]) |
| 87 |
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 GeometryObject &>( |
| 88 | bp::args("self", "otherGeometryObject"), "Copy constructor")) | ||
| 89 |
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 | .add_property( |
| 90 | "meshScale", | ||
| 91 | 65 | bp::make_getter(&GeometryObject::meshScale, bp::return_internal_reference<>()), | |
| 92 | bp::make_setter(&GeometryObject::meshScale), "Scaling parameter of the mesh.") | ||
| 93 |
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 | .add_property( |
| 94 | "meshColor", | ||
| 95 | 65 | bp::make_getter(&GeometryObject::meshColor, bp::return_internal_reference<>()), | |
| 96 | bp::make_setter(&GeometryObject::meshColor), "Color rgba of the mesh.") | ||
| 97 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def_readwrite( |
| 98 | "geometry", &GeometryObject::geometry, | ||
| 99 | "The FCL CollisionGeometry associated to the given GeometryObject.") | ||
| 100 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def_readwrite( |
| 101 | "name", &GeometryObject::name, "Name associated to the given GeometryObject.") | ||
| 102 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def_readwrite("parentJoint", &GeometryObject::parentJoint, "Index of the parent joint.") |
| 103 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def_readwrite("parentFrame", &GeometryObject::parentFrame, "Index of the parent frame.") |
| 104 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def_readwrite( |
| 105 | "placement", &GeometryObject::placement, | ||
| 106 | "Position of geometry object in parent joint's frame.") | ||
| 107 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def_readwrite("meshPath", &GeometryObject::meshPath, "Path to the mesh file.") |
| 108 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def_readwrite( |
| 109 | "overrideMaterial", &GeometryObject::overrideMaterial, | ||
| 110 | "Boolean that tells whether material information is stored inside the " | ||
| 111 | "given GeometryObject.") | ||
| 112 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def_readwrite( |
| 113 | "meshTexturePath", &GeometryObject::meshTexturePath, "Path to the mesh texture file.") | ||
| 114 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def_readwrite( |
| 115 | "disableCollision", &GeometryObject::disableCollision, | ||
| 116 | "If true, no collision or distance check will be done between the " | ||
| 117 | "Geometry and any other geometry.") | ||
| 118 | 130 | .def( | |
| 119 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
130 | "clone", &GeometryObject::clone, bp::arg("self"), |
| 120 | "Perform a deep copy of this. It will create a copy of the underlying FCL geometry.") | ||
| 121 |
4/8✓ 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.
|
130 | .add_property( |
| 122 | "meshMaterial", | ||
| 123 | 65 | bp::make_getter(&GeometryObject::meshMaterial, Converter::return_internal_reference()), | |
| 124 | bp::make_setter(&GeometryObject::meshMaterial), | ||
| 125 | "Material associated to the mesh (applied only if overrideMaterial is True)") | ||
| 126 | |||
| 127 |
1/2✓ Branch 2 taken 65 times.
✗ Branch 3 not taken.
|
65 | .def(bp::self == bp::self) |
| 128 |
1/2✓ Branch 2 taken 65 times.
✗ Branch 3 not taken.
|
130 | .def(bp::self != bp::self) |
| 129 | |||
| 130 | #ifdef PINOCCHIO_WITH_HPP_FCL | ||
| 131 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def("CreateCapsule", &GeometryObjectPythonVisitor::maker_capsule) |
| 132 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .staticmethod("CreateCapsule") |
| 133 | #endif // PINOCCHIO_WITH_HPP_FCL | ||
| 134 | ; | ||
| 135 | |||
| 136 | // Check registration | ||
| 137 | { | ||
| 138 | 65 | const bp::type_info info = bp::type_id<CollisionGeometryPtr>(); | |
| 139 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | const bp::converter::registration * reg = bp::converter::registry::query(info); |
| 140 | // We just need to check if the type shared_ptr<CollisionGeometry> exist in the registry | ||
| 141 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 65 times.
|
65 | if (!reg) |
| 142 | ✗ | bp::register_ptr_to_python<CollisionGeometryPtr>(); | |
| 143 | } | ||
| 144 | 65 | } | |
| 145 | |||
| 146 | #ifdef PINOCCHIO_WITH_HPP_FCL | ||
| 147 | ✗ | static GeometryObject maker_capsule(const double radius, const double length) | |
| 148 | { | ||
| 149 | return GeometryObject( | ||
| 150 | ✗ | "", JointIndex(0), FrameIndex(0), SE3::Identity(), | |
| 151 | ✗ | std::shared_ptr<fcl::CollisionGeometry>(new fcl::Capsule(radius, length))); | |
| 152 | } | ||
| 153 | #endif // PINOCCHIO_WITH_HPP_FCL | ||
| 154 | |||
| 155 | 65 | static void expose() | |
| 156 | { | ||
| 157 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | if (!register_symbolic_link_to_registered_type<GeometryObject>()) |
| 158 | { | ||
| 159 | 130 | bp::class_<GeometryObject>( | |
| 160 | "GeometryObject", | ||
| 161 | "A wrapper on a collision geometry including its parent " | ||
| 162 | "joint, parent frame, placement in parent joint's frame.\n\n", | ||
| 163 | bp::no_init) | ||
| 164 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def(GeometryObjectPythonVisitor()) |
| 165 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def(CopyableVisitor<GeometryObject>()) |
| 166 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def(AddressVisitor<GeometryObject>()) |
| 167 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def(SerializableVisitor<GeometryObject>()) |
| 168 | #ifndef PINOCCHIO_PYTHON_NO_SERIALIZATION | ||
| 169 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def_pickle(PickleFromStringSerialization<GeometryObject>()) |
| 170 | #endif | ||
| 171 | ; | ||
| 172 | } | ||
| 173 | |||
| 174 | #ifdef PINOCCHIO_WITH_HPP_FCL | ||
| 175 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | if (!register_symbolic_link_to_registered_type<CollisionObject>()) |
| 176 | { | ||
| 177 | 130 | bp::class_<CollisionObject, bp::bases<::hpp::fcl::CollisionObject>>( | |
| 178 | "CollisionObject", "A Pinocchio collision object derived from FCL CollisionObject.", | ||
| 179 | bp::no_init) | ||
| 180 |
2/4✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 65 times.
✗ Branch 5 not taken.
|
65 | .def(bp::init< |
| 181 | const std::shared_ptr<::hpp::fcl::CollisionGeometry> &, | ||
| 182 | bp::optional<const size_t, bool>>( | ||
| 183 |
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("self"), bp::arg("collision_geometry"), |
| 184 |
3/6✓ Branch 2 taken 65 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 65 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 65 times.
✗ Branch 9 not taken.
|
130 | bp::arg("geometryObjectIndex") = (std::numeric_limits<size_t>::max)(), |
| 185 |
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("compute_local_aabb") = true), |
| 186 | "Constructor")) | ||
| 187 |
2/4✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 65 times.
✗ Branch 5 not taken.
|
65 | .def(bp::init< |
| 188 | const std::shared_ptr<::hpp::fcl::CollisionGeometry> &, SE3, | ||
| 189 | bp::optional<const size_t, bool>>( | ||
| 190 |
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.
|
130 | (bp::arg("self"), bp::arg("collision_geometry"), bp::arg("placement"), |
| 191 |
3/6✓ Branch 2 taken 65 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 65 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 65 times.
✗ Branch 9 not taken.
|
195 | bp::arg("geometryObjectIndex") = (std::numeric_limits<size_t>::max)(), |
| 192 |
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("compute_local_aabb") = true), |
| 193 | "Constructor")); | ||
| 194 | } | ||
| 195 | #endif | ||
| 196 | |||
| 197 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | if (!register_symbolic_link_to_registered_type<GeometryNoMaterial>()) |
| 198 | { | ||
| 199 | /// Define material types | ||
| 200 |
1/2✓ Branch 2 taken 65 times.
✗ Branch 3 not taken.
|
130 | bp::class_<GeometryNoMaterial>("GeometryNoMaterial", bp::init<>()) |
| 201 |
2/4✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 65 times.
✗ Branch 5 not taken.
|
65 | .def(bp::init<GeometryNoMaterial>()); |
| 202 | } | ||
| 203 | |||
| 204 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | if (!register_symbolic_link_to_registered_type<GeometryPhongMaterial>()) |
| 205 | { | ||
| 206 |
1/2✓ Branch 2 taken 65 times.
✗ Branch 3 not taken.
|
130 | bp::class_<GeometryPhongMaterial>("GeometryPhongMaterial", bp::init<>()) |
| 207 |
2/4✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 65 times.
✗ Branch 5 not taken.
|
65 | .def(bp::init<GeometryPhongMaterial>()) |
| 208 |
2/4✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 65 times.
✗ Branch 5 not taken.
|
65 | .def(bp::init<Eigen::Vector4d, Eigen::Vector4d, double>()) |
| 209 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .add_property( |
| 210 | "meshEmissionColor", | ||
| 211 | ✗ | bp::make_getter( | |
| 212 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | &GeometryPhongMaterial::meshEmissionColor, bp::return_internal_reference<>()), |
| 213 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
130 | bp::make_setter(&GeometryPhongMaterial::meshEmissionColor), |
| 214 | "RGBA emission (ambient) color value of the mesh") | ||
| 215 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .add_property( |
| 216 | "meshSpecularColor", | ||
| 217 | ✗ | bp::make_getter( | |
| 218 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | &GeometryPhongMaterial::meshSpecularColor, bp::return_internal_reference<>()), |
| 219 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
130 | bp::make_setter(&GeometryPhongMaterial::meshSpecularColor), |
| 220 | "RGBA specular value of the mesh") | ||
| 221 | 65 | .def_readwrite( | |
| 222 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | "meshShininess", &GeometryPhongMaterial::meshShininess, |
| 223 | "Shininess associated to the specular lighting model (between 0 and 1)"); | ||
| 224 | } | ||
| 225 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | if (!register_symbolic_link_to_registered_type<GeometryType>()) |
| 226 | { | ||
| 227 | 130 | bp::enum_<GeometryType>("GeometryType") | |
| 228 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .value("VISUAL", VISUAL) |
| 229 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .value("COLLISION", COLLISION) |
| 230 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .export_values(); |
| 231 | } | ||
| 232 | 65 | } | |
| 233 | }; | ||
| 234 | |||
| 235 | } // namespace python | ||
| 236 | } // namespace pinocchio | ||
| 237 | |||
| 238 | #endif // ifndef __pinocchio_python_geometry_object_hpp__ | ||
| 239 |