bindings/python/multibody/geometry-object.hpp
Go to the documentation of this file.
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>
11 
18 
20 
21 #if EIGENPY_VERSION_AT_MOST(2, 8, 1)
23 #endif
24 
25 namespace pinocchio
26 {
27  namespace python
28  {
29  namespace bp = boost::python;
30 
31  namespace
32  {
35  struct GeometryMaterialValueToObject : boost::static_visitor<PyObject *>
36  {
37  static result_type convert(GeometryMaterial const & gm)
38  {
39  return apply_visitor(GeometryMaterialValueToObject(), gm);
40  }
41 
42  template<typename T>
43  result_type operator()(T & t) const
44  {
45  return bp::incref(bp::object(t).ptr());
46  }
47  };
48 
53  struct GeometryMaterialRefToObject : boost::static_visitor<PyObject *>
54  {
55  static result_type convert(GeometryMaterial const & gm)
56  {
57  return apply_visitor(GeometryMaterialRefToObject(), gm);
58  }
59 
60  template<typename T>
61  result_type operator()(T & t) const
62  {
63  return bp::detail::make_reference_holder::execute(&t);
64  }
65  };
66 
70  struct GeometryMaterialConverter
71  {
72  template<class T>
73  struct apply
74  {
75  struct type
76  {
77  inline PyObject * operator()(const GeometryMaterial & gm) const
78  {
79  return GeometryMaterialRefToObject::convert(gm);
80  }
81 
82 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
83  inline PyTypeObject const * get_pytype() const
84  {
85  return bp::converter::registered_pytype<GeometryMaterial>::get_pytype();
86  }
87 #endif
88  };
89  };
90  };
91 
94  struct GeometryMaterialReturnInternalVariant : bp::return_internal_reference<>
95  {
96  public:
97  typedef GeometryMaterialConverter result_converter;
98  };
99  } // namespace
100 
102  : public boost::python::def_visitor<GeometryObjectPythonVisitor>
103  {
104 
106 
107  template<class PyClass>
108  void visit(PyClass & cl) const
109  {
110  cl.def(bp::init<
111  std::string, JointIndex, FrameIndex, const SE3 &, CollisionGeometryPtr,
112  bp::optional<
113  std::string, const Eigen::Vector3d &, bool, const Eigen::Vector4d &, std::string,
115  bp::args(
116  "self", "name", "parent_joint", "parent_frame", "placement",
117  "collision_geometry", "mesh_path", "mesh_scale", "override_material",
118  "mesh_color", "mesh_texture_path", "mesh_material"),
119  "Full constructor of a GeometryObject."))
120  .def(bp::init<
121  std::string, JointIndex, const SE3 &, CollisionGeometryPtr,
122  bp::optional<
123  std::string, const Eigen::Vector3d &, bool, const Eigen::Vector4d &, std::string,
125  bp::args(
126  "self", "name", "parent_joint", "placement", "collision_geometry", "mesh_path",
127  "mesh_scale", "override_material", "mesh_color", "mesh_texture_path",
128  "mesh_material"),
129  "Reduced constructor of a GeometryObject. This constructor does not require to specify "
130  "the parent frame index."))
131  .def(bp::init<
132  std::string, FrameIndex, JointIndex, CollisionGeometryPtr, const SE3 &,
133  bp::optional<
134  std::string, const Eigen::Vector3d &, bool, const Eigen::Vector4d &, std::string,
136  bp::args(
137  "self", "name", "parent_frame", "parent_joint", "collision_geometry", "placement",
138  "mesh_path", "mesh_scale", "override_material", "mesh_color",
139  "mesh_texture_path"
140  "mesh_material"),
141  "Deprecated. Full constructor of a GeometryObject.")[deprecated_function<>()])
142  .def(bp::init<
143  std::string, JointIndex, CollisionGeometryPtr, const SE3 &,
144  bp::optional<
145  std::string, const Eigen::Vector3d &, bool, const Eigen::Vector4d &, std::string,
147  bp::args(
148  "self", "name", "parent_joint", "collision_geometry", "placement", "mesh_path",
149  "mesh_scale", "override_material", "mesh_color", "mesh_texture_path",
150  "mesh_material"),
151  "Deprecated. Reduced constructor of a GeometryObject. This constructor does not "
152  "require to specify the parent frame index.")[deprecated_function<>()])
153  .def(bp::init<const GeometryObject &>(
154  bp::args("self", "otherGeometryObject"), "Copy constructor"))
155  .add_property(
156  "meshScale",
157  bp::make_getter(&GeometryObject::meshScale, bp::return_internal_reference<>()),
158  bp::make_setter(&GeometryObject::meshScale), "Scaling parameter of the mesh.")
159  .add_property(
160  "meshColor",
161  bp::make_getter(&GeometryObject::meshColor, bp::return_internal_reference<>()),
162  bp::make_setter(&GeometryObject::meshColor), "Color rgba of the mesh.")
163  .def_readwrite(
164  "geometry", &GeometryObject::geometry,
165  "The FCL CollisionGeometry associated to the given GeometryObject.")
166  .def_readwrite(
167  "name", &GeometryObject::name, "Name associated to the given GeometryObject.")
168  .def_readwrite("parentJoint", &GeometryObject::parentJoint, "Index of the parent joint.")
169  .def_readwrite("parentFrame", &GeometryObject::parentFrame, "Index of the parent frame.")
170  .def_readwrite(
171  "placement", &GeometryObject::placement,
172  "Position of geometry object in parent joint's frame.")
173  .def_readwrite("meshPath", &GeometryObject::meshPath, "Path to the mesh file.")
174  .def_readwrite(
175  "overrideMaterial", &GeometryObject::overrideMaterial,
176  "Boolean that tells whether material information is stored inside the "
177  "given GeometryObject.")
178  .def_readwrite(
179  "meshTexturePath", &GeometryObject::meshTexturePath, "Path to the mesh texture file.")
180  .def_readwrite(
181  "disableCollision", &GeometryObject::disableCollision,
182  "If true, no collision or distance check will be done between the "
183  "Geometry and any other geometry.")
184  .def(
185  "clone", &GeometryObject::clone, bp::arg("self"),
186  "Perform a deep copy of this. It will create a copy of the underlying FCL geometry.")
187  .add_property(
188  "meshMaterial",
189  bp::make_getter(&GeometryObject::meshMaterial, GeometryMaterialReturnInternalVariant()),
190  bp::make_setter(&GeometryObject::meshMaterial),
191  "Material associated to the mesh (applied only if overrideMaterial is True)")
192 
193  .def(bp::self == bp::self)
194  .def(bp::self != bp::self)
195 
196 #ifdef PINOCCHIO_WITH_HPP_FCL
197  .def("CreateCapsule", &GeometryObjectPythonVisitor::maker_capsule)
198  .staticmethod("CreateCapsule")
199 #endif // PINOCCHIO_WITH_HPP_FCL
200  ;
201 
202  // Check registration
203  {
204  const bp::type_info info = bp::type_id<CollisionGeometryPtr>();
205  const bp::converter::registration * reg = bp::converter::registry::query(info);
206  // We just need to check if the type shared_ptr<CollisionGeometry> exist in the registry
207  if (!reg)
208  bp::register_ptr_to_python<CollisionGeometryPtr>();
209  }
210  }
211 
212 #ifdef PINOCCHIO_WITH_HPP_FCL
213  static GeometryObject maker_capsule(const double radius, const double length)
214  {
215  return GeometryObject(
216  "", JointIndex(0), FrameIndex(0), SE3::Identity(),
217  std::shared_ptr<fcl::CollisionGeometry>(new fcl::Capsule(radius, length)));
218  }
219 #endif // PINOCCHIO_WITH_HPP_FCL
220 
221  static void expose()
222  {
223  if (!register_symbolic_link_to_registered_type<GeometryObject>())
224  {
225  bp::class_<GeometryObject>(
226  "GeometryObject",
227  "A wrapper on a collision geometry including its parent "
228  "joint, parent frame, placement in parent joint's frame.\n\n",
229  bp::no_init)
234 #ifndef PINOCCHIO_PYTHON_NO_SERIALIZATION
236 #endif
237  ;
238  }
239 
240 #ifdef PINOCCHIO_WITH_HPP_FCL
241  if (!register_symbolic_link_to_registered_type<CollisionObject>())
242  {
243  bp::class_<CollisionObject, bp::bases<::hpp::fcl::CollisionObject>>(
244  "CollisionObject", "A Pinocchio collision object derived from FCL CollisionObject.",
245  bp::no_init)
246  .def(bp::init<
247  const std::shared_ptr<::hpp::fcl::CollisionGeometry> &,
248  bp::optional<const size_t, bool>>(
249  (bp::arg("self"), bp::arg("collision_geometry"),
250  bp::arg("geometryObjectIndex") = (std::numeric_limits<size_t>::max)(),
251  bp::arg("compute_local_aabb") = true),
252  "Constructor"))
253  .def(bp::init<
254  const std::shared_ptr<::hpp::fcl::CollisionGeometry> &, SE3,
255  bp::optional<const size_t, bool>>(
256  (bp::arg("self"), bp::arg("collision_geometry"), bp::arg("placement"),
257  bp::arg("geometryObjectIndex") = (std::numeric_limits<size_t>::max)(),
258  bp::arg("compute_local_aabb") = true),
259  "Constructor"));
260  }
261 #endif
262 
263  if (!register_symbolic_link_to_registered_type<GeometryNoMaterial>())
264  {
266  bp::class_<GeometryNoMaterial>("GeometryNoMaterial", bp::init<>())
267  .def(bp::init<GeometryNoMaterial>());
268  }
269 
270  if (!register_symbolic_link_to_registered_type<GeometryPhongMaterial>())
271  {
272  bp::class_<GeometryPhongMaterial>("GeometryPhongMaterial", bp::init<>())
273  .def(bp::init<GeometryPhongMaterial>())
274  .def(bp::init<Eigen::Vector4d, Eigen::Vector4d, double>())
275  .add_property(
276  "meshEmissionColor",
277  bp::make_getter(
278  &GeometryPhongMaterial::meshEmissionColor, bp::return_internal_reference<>()),
280  "RGBA emission (ambient) color value of the mesh")
281  .add_property(
282  "meshSpecularColor",
283  bp::make_getter(
284  &GeometryPhongMaterial::meshSpecularColor, bp::return_internal_reference<>()),
286  "RGBA specular value of the mesh")
287  .def_readwrite(
288  "meshShininess", &GeometryPhongMaterial::meshShininess,
289  "Shininess associated to the specular lighting model (between 0 and 1)");
290  }
291 
293  bp::to_python_converter<GeometryMaterial, GeometryMaterialValueToObject>();
294 
296  bp::implicitly_convertible<GeometryNoMaterial, GeometryMaterial>();
297  bp::implicitly_convertible<GeometryPhongMaterial, GeometryMaterial>();
298 
299  if (!register_symbolic_link_to_registered_type<GeometryType>())
300  {
301  bp::enum_<GeometryType>("GeometryType")
302  .value("VISUAL", VISUAL)
303  .value("COLLISION", COLLISION)
304  .export_values();
305  }
306  }
307  };
308 
309  } // namespace python
310 } // namespace pinocchio
311 
312 #endif // ifndef __pinocchio_python_geometry_object_hpp__
simulation-contact-dynamics.T
int T
Definition: simulation-contact-dynamics.py:94
pinocchio::python::GeometryObjectPythonVisitor::CollisionGeometryPtr
GeometryObject::CollisionGeometryPtr CollisionGeometryPtr
Definition: bindings/python/multibody/geometry-object.hpp:105
init
void init(bool compute_local_aabb=true)
pinocchio::FrameIndex
Index FrameIndex
Definition: multibody/fwd.hpp:28
pinocchio::GeometryObject::overrideMaterial
bool overrideMaterial
Decide whether to override the Material.
Definition: multibody/geometry-object.hpp:119
boost::python
pinocchio::ModelItem< GeometryObject >::parentJoint
JointIndex parentJoint
Index of the parent joint.
Definition: model-item.hpp:28
pinocchio::GeometryObject::meshScale
Eigen::Vector3d meshScale
Scaling vector applied to the GeometryObject::geometry object.
Definition: multibody/geometry-object.hpp:116
pinocchio::python::PickleFromStringSerialization
Definition: pickle.hpp:17
registration.hpp
pinocchio::python::GeometryObjectPythonVisitor::expose
static void expose()
Definition: bindings/python/multibody/geometry-object.hpp:221
pinocchio::GeometryPhongMaterial::meshSpecularColor
Eigen::Vector4d meshSpecularColor
RGBA specular color value of the GeometryObject::geometry object.
Definition: multibody/geometry-object.hpp:65
eigen-from-python.hpp
pinocchio::SE3Tpl< context::Scalar, context::Options >
pinocchio::GeometryObject::meshColor
Eigen::Vector4d meshColor
RGBA color value of the GeometryObject::geometry object.
Definition: multibody/geometry-object.hpp:122
eigen-to-python.hpp
pinocchio::GeometryObject
Definition: multibody/geometry-object.hpp:87
pinocchio::python::deprecated_function
Definition: bindings/python/utils/deprecation.hpp:51
def
void def(const char *name, Func func)
simulation-pendulum.type
type
Definition: simulation-pendulum.py:18
pinocchio::VISUAL
@ VISUAL
Definition: multibody/geometry-object.hpp:26
pinocchio::GeometryPhongMaterial::meshShininess
double meshShininess
Shininess associated to the specular lighting model.
Definition: multibody/geometry-object.hpp:70
pinocchio::ModelItem< GeometryObject >::placement
SE3 placement
Position of kinematic element in parent joint frame.
Definition: model-item.hpp:39
pickle.hpp
deprecation.hpp
EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION
#define EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(...)
pinocchio::python::GeometryObjectPythonVisitor
Definition: bindings/python/multibody/geometry-object.hpp:101
pinocchio::ModelItem< GeometryObject >::parentFrame
FrameIndex parentFrame
Index of the parent frame.
Definition: model-item.hpp:36
pinocchio::GeometryObject::meshMaterial
GeometryMaterial meshMaterial
Material associated to the mesh. This material should be used only if overrideMaterial is set to true...
Definition: multibody/geometry-object.hpp:127
serializable.hpp
pinocchio::python::GeometryObjectPythonVisitor::visit
void visit(PyClass &cl) const
Definition: bindings/python/multibody/geometry-object.hpp:108
ocp.info
info
Definition: ocp.py:61
python
pinocchio::python::CopyableVisitor
Add the Python method copy to allow a copy of this by calling the copy constructor.
Definition: copyable.hpp:21
geometry.hpp
address.hpp
pinocchio::GeometryObject::meshPath
std::string meshPath
Absolute path to the mesh file (if the geometry pointee is also a Mesh)
Definition: multibody/geometry-object.hpp:113
pinocchio::GeometryMaterial
boost::variant< GeometryNoMaterial, GeometryPhongMaterial > GeometryMaterial
Definition: multibody/geometry-object.hpp:73
pinocchio::GeometryObject::meshTexturePath
std::string meshTexturePath
Absolute path to the mesh texture file.
Definition: multibody/geometry-object.hpp:130
pinocchio::GeometryObject::geometry
CollisionGeometryPtr geometry
The FCL CollisionGeometry (might be a Mesh, a Geometry Primitive, etc.)
Definition: multibody/geometry-object.hpp:110
copyable.hpp
pinocchio::GeometryObject::clone
GeometryObject clone() const
Perform a deep copy of this. It will create a copy of the underlying FCL geometry.
Definition: multibody/geometry-object.hpp:302
pinocchio::python::SerializableVisitor
Definition: bindings/python/serialization/serializable.hpp:19
Capsule
Capsule()
pinocchio::python::AddressVisitor
Add the Python method to extract the address of the underlying C++ object.
Definition: address.hpp:21
pinocchio::GeometryObject::disableCollision
bool disableCollision
If true, no collision or distance check will be done between the Geometry and any other geometry.
Definition: multibody/geometry-object.hpp:134
pinocchio::SE3Tpl< context::Scalar, context::Options >::Identity
static SE3Tpl Identity()
Definition: spatial/se3-tpl.hpp:136
cl
cl
memory.hpp
pinocchio::JointIndex
Index JointIndex
Definition: multibody/fwd.hpp:26
pinocchio::COLLISION
@ COLLISION
Definition: multibody/geometry-object.hpp:27
t
Transform3f t
pinocchio::GeometryObject::CollisionGeometryPtr
std::shared_ptr< fcl::CollisionGeometry > CollisionGeometryPtr
Definition: multibody/geometry-object.hpp:102
CppAD::max
AD< Scalar > max(const AD< Scalar > &x, const AD< Scalar > &y)
Definition: autodiff/cppad.hpp:180
length
FCL_REAL length[2]
pinocchio::ModelItem< GeometryObject >::name
std::string name
Name of the kinematic element.
Definition: model-item.hpp:25
radius
FCL_REAL radius
pinocchio::GeometryPhongMaterial::meshEmissionColor
Eigen::Vector4d meshEmissionColor
RGBA emission (ambient) color value of the GeometryObject::geometry object.
Definition: multibody/geometry-object.hpp:62
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27


pinocchio
Author(s):
autogenerated on Tue Jun 25 2024 02:42:37