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