pinocchio  3.7.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
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)
23EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(pinocchio::GeometryObject)
24#endif
25
26namespace 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 void visit(PyClass & cl) const
40 {
41 typedef eigenpy::VariantConverter<GeometryMaterial> Converter;
42 Converter::registration();
43
44 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 .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 .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 "Deprecated. Full constructor of a GeometryObject.")[deprecated_function<>()])
76 .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 "require to specify the parent frame index.")[deprecated_function<>()])
87 .def(bp::init<const GeometryObject &>(
88 bp::args("self", "otherGeometryObject"), "Copy constructor"))
89 .add_property(
90 "meshScale",
91 bp::make_getter(&GeometryObject::meshScale, bp::return_internal_reference<>()),
92 bp::make_setter(&GeometryObject::meshScale), "Scaling parameter of the mesh.")
93 .add_property(
94 "meshColor",
95 bp::make_getter(&GeometryObject::meshColor, bp::return_internal_reference<>()),
96 bp::make_setter(&GeometryObject::meshColor), "Color rgba of the mesh.")
97 .def_readwrite(
98 "geometry", &GeometryObject::geometry,
99 "The FCL CollisionGeometry associated to the given GeometryObject.")
100 .def_readwrite(
101 "name", &GeometryObject::name, "Name associated to the given GeometryObject.")
102 .def_readwrite("parentJoint", &GeometryObject::parentJoint, "Index of the parent joint.")
103 .def_readwrite("parentFrame", &GeometryObject::parentFrame, "Index of the parent frame.")
104 .def_readwrite(
105 "placement", &GeometryObject::placement,
106 "Position of geometry object in parent joint's frame.")
107 .def_readwrite("meshPath", &GeometryObject::meshPath, "Path to the mesh file.")
108 .def_readwrite(
109 "overrideMaterial", &GeometryObject::overrideMaterial,
110 "Boolean that tells whether material information is stored inside the "
111 "given GeometryObject.")
112 .def_readwrite(
113 "meshTexturePath", &GeometryObject::meshTexturePath, "Path to the mesh texture file.")
114 .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 .def(
119 "clone", &GeometryObject::clone, bp::arg("self"),
120 "Perform a deep copy of this. It will create a copy of the underlying FCL geometry.")
121 .add_property(
122 "meshMaterial",
123 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 .def(bp::self == bp::self)
128 .def(bp::self != bp::self)
129
130#ifdef PINOCCHIO_WITH_HPP_FCL
131 .def("CreateCapsule", &GeometryObjectPythonVisitor::maker_capsule)
132 .staticmethod("CreateCapsule")
133#endif // PINOCCHIO_WITH_HPP_FCL
134 ;
135
136 // Check registration
137 {
138 const bp::type_info info = bp::type_id<CollisionGeometryPtr>();
139 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 if (!reg)
142 bp::register_ptr_to_python<CollisionGeometryPtr>();
143 }
144 }
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 static void expose()
156 {
157 if (!register_symbolic_link_to_registered_type<GeometryObject>())
158 {
159 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 .def(GeometryObjectPythonVisitor())
165 .def(CopyableVisitor<GeometryObject>())
166 .def(AddressVisitor<GeometryObject>())
167 .def(SerializableVisitor<GeometryObject>())
168#ifndef PINOCCHIO_PYTHON_NO_SERIALIZATION
169 .def_pickle(PickleFromStringSerialization<GeometryObject>())
170#endif
171 ;
172 }
173
174#ifdef PINOCCHIO_WITH_HPP_FCL
175 if (!register_symbolic_link_to_registered_type<CollisionObject>())
176 {
177 bp::class_<CollisionObject, bp::bases<::hpp::fcl::CollisionObject>>(
178 "CollisionObject", "A Pinocchio collision object derived from FCL CollisionObject.",
179 bp::no_init)
180 .def(bp::init<
181 const std::shared_ptr<::hpp::fcl::CollisionGeometry> &,
182 bp::optional<const size_t, bool>>(
183 (bp::arg("self"), bp::arg("collision_geometry"),
184 bp::arg("geometryObjectIndex") = (std::numeric_limits<size_t>::max)(),
185 bp::arg("compute_local_aabb") = true),
186 "Constructor"))
187 .def(bp::init<
188 const std::shared_ptr<::hpp::fcl::CollisionGeometry> &, SE3,
189 bp::optional<const size_t, bool>>(
190 (bp::arg("self"), bp::arg("collision_geometry"), bp::arg("placement"),
191 bp::arg("geometryObjectIndex") = (std::numeric_limits<size_t>::max)(),
192 bp::arg("compute_local_aabb") = true),
193 "Constructor"));
194 }
195#endif
196
197 if (!register_symbolic_link_to_registered_type<GeometryNoMaterial>())
198 {
200 bp::class_<GeometryNoMaterial>("GeometryNoMaterial", bp::init<>())
201 .def(bp::init<GeometryNoMaterial>());
202 }
203
204 if (!register_symbolic_link_to_registered_type<GeometryPhongMaterial>())
205 {
206 bp::class_<GeometryPhongMaterial>("GeometryPhongMaterial", bp::init<>())
207 .def(bp::init<GeometryPhongMaterial>())
208 .def(bp::init<Eigen::Vector4d, Eigen::Vector4d, double>())
209 .add_property(
210 "meshEmissionColor",
211 bp::make_getter(
212 &GeometryPhongMaterial::meshEmissionColor, bp::return_internal_reference<>()),
214 "RGBA emission (ambient) color value of the mesh")
215 .add_property(
216 "meshSpecularColor",
217 bp::make_getter(
218 &GeometryPhongMaterial::meshSpecularColor, bp::return_internal_reference<>()),
220 "RGBA specular value of the mesh")
221 .def_readwrite(
222 "meshShininess", &GeometryPhongMaterial::meshShininess,
223 "Shininess associated to the specular lighting model (between 0 and 1)");
224 }
225 if (!register_symbolic_link_to_registered_type<GeometryType>())
226 {
227 bp::enum_<GeometryType>("GeometryType")
228 .value("VISUAL", VISUAL)
229 .value("COLLISION", COLLISION)
230 .export_values();
231 }
232 }
233 };
234
235 } // namespace python
236} // namespace pinocchio
237
238#endif // ifndef __pinocchio_python_geometry_object_hpp__
Main pinocchio namespace.
Definition treeview.dox:11
Eigen::Vector4d meshColor
RGBA color value of the GeometryObject::geometry object.
GeometryMaterial meshMaterial
Material associated to the mesh. This material should be used only if overrideMaterial is set to true...
std::string meshPath
Absolute path to the mesh file (if the geometry pointee is also a Mesh)
bool overrideMaterial
Decide whether to override the Material.
bool disableCollision
If true, no collision or distance check will be done between the Geometry and any other geometry.
Eigen::Vector3d meshScale
Scaling vector applied to the GeometryObject::geometry object.
GeometryObject clone() const
Perform a deep copy of this. It will create a copy of the underlying FCL geometry.
std::string meshTexturePath
Absolute path to the mesh texture file.
CollisionGeometryPtr geometry
The FCL CollisionGeometry (might be a Mesh, a Geometry Primitive, etc.)
Eigen::Vector4d meshSpecularColor
RGBA specular color value of the GeometryObject::geometry object.
double meshShininess
Shininess associated to the specular lighting model.
Eigen::Vector4d meshEmissionColor
RGBA emission (ambient) color value of the GeometryObject::geometry object.
FrameIndex parentFrame
Index of the parent frame.
JointIndex parentJoint
Index of the parent joint.
std::string name
Name of the kinematic element.
SE3 placement
Position of kinematic element in parent joint frame.