pinocchio  3.7.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
 
Loading...
Searching...
No Matches
geometry-data.hpp
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)
20EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(pinocchio::GeometryData)
21#endif
22
23namespace 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 static void expose()
36 {
37 if (!register_symbolic_link_to_registered_type<CollisionPair>())
38 {
39 bp::class_<CollisionPair>(
40 "CollisionPair", "Pair of ordered index defining a pair of collisions", bp::no_init)
41 .def(bp::init<>(bp::args("self"), "Empty constructor."))
42 .def(bp::init<const GeomIndex &, const GeomIndex &>(
43 bp::args("self", "index1", "index2"), "Initializer of collision pair."))
44 .def(PrintableVisitor<CollisionPair>())
45 .def(CopyableVisitor<CollisionPair>())
46 .def(bp::self == bp::self)
47 .def(bp::self != bp::self)
48 .def_readwrite("first", &CollisionPair::first)
49 .def_readwrite("second", &CollisionPair::second);
50
51 StdVectorPythonVisitor<std::vector<CollisionPair>>::expose("StdVec_CollisionPair");
52 serialize<std::vector<CollisionPair>>();
53 }
54 }
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 void visit(PyClass & cl) const
63 {
64 cl
65 .def(bp::init<const GeometryModel &>(
66 bp::args("self", "geometry_model"), "Default constructor from a given GeometryModel."))
67
68 .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 .def_readwrite(
73 "activeCollisionPairs", &GeometryData::activeCollisionPairs,
74 "Vector of active CollisionPairs")
75
76#ifdef PINOCCHIO_WITH_HPP_FCL
77 .def_readwrite(
78 "distanceRequests", &GeometryData::distanceRequests,
79 "Defines which information should be computed by FCL for distance computations")
80 .def_readwrite(
81 "distanceResults", &GeometryData::distanceResults, "Vector of distance results.")
82 .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 .def_readwrite(
91 "collisionResults", &GeometryData::collisionResults, "Vector of collision results.")
92 .def_readwrite(
93 "collision_functors", &GeometryData::collision_functors,
94 "Vector of collision functors.")
95 .def_readwrite(
96 "distance_functors", &GeometryData::distance_functors, "Vector of distance functors.")
97 .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 .def(
105 "fillInnerOuterObjectMaps", &GeometryData::fillInnerOuterObjectMaps,
106 bp::args("self", "geometry_model"), "Fill inner and outer objects maps")
107 .def(
108 "activateCollisionPair",
109 static_cast<void (GeometryData::*)(const PairIndex)>(
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 .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 .def(
120 "setActiveCollisionPairs", &GeometryData::setActiveCollisionPairs,
121 (bp::arg("self"), bp::arg("geometry_model"), bp::arg("collision_map"),
122 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 .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 .def(
130 "deactivateAllCollisionPairs", &GeometryData::deactivateAllCollisionPairs,
131 bp::args("self"), "Deactivate all collision pairs.")
132#ifdef PINOCCHIO_WITH_HPP_FCL
133 .def(
134 "setSecurityMargins", &GeometryData::setSecurityMargins,
135 (bp::arg("self"), bp::arg("geometry_model"), bp::arg("security_margin_map"),
136 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 .def(bp::self == bp::self)
142 .def(bp::self != bp::self)
143
144 ;
145
146 bp::register_ptr_to_python<std::shared_ptr<GeometryData>>();
147 }
148
149 /* --- Expose --------------------------------------------------------- */
150 static void expose()
151 {
152 if (!register_symbolic_link_to_registered_type<GeometryData>())
153 {
154 bp::class_<GeometryData>(
155 "GeometryData", "Geometry data linked to a Geometry Model and a Data struct.",
156 bp::no_init)
157 .def(GeometryDataPythonVisitor())
158 .def(PrintableVisitor<GeometryData>())
159 .def(CopyableVisitor<GeometryData>())
160 .def(SerializableVisitor<GeometryData>())
161 .def(AddressVisitor<GeometryModel>());
162 }
163 }
164 };
165
166 } // namespace python
167} // namespace pinocchio
168
169#endif // ifndef __pinocchio_python_geometry_data_hpp__
Main pinocchio namespace.
Definition treeview.dox:11
void deactivateCollisionPair(const PairIndex pair_id)
std::vector< fcl::CollisionRequest > collisionRequests
Defines what information should be computed by collision test. There is one request per pair of geome...
Definition geometry.hpp:292
void setActiveCollisionPairs(const GeometryModel &geom_model, const MatrixXb &collision_map, const bool upper=true)
Set the collision pair association from a given input array. Each entry of the input matrix defines t...
std::vector< Scalar > radius
Radius of the bodies, i.e. distance of the further point of the geometry model attached to the body f...
Definition geometry.hpp:303
void activateCollisionPair(const PairIndex pair_id)
void deactivateAllCollisionPairs()
Deactivate all collision pairs.
void setSecurityMargins(const GeometryModel &geom_model, const MatrixXs &security_margin_map, const bool upper=true, const bool sync_distance_upper_bound=false)
Set the security margin of all the collision request in a row, according to the values stored in the ...
std::vector< fcl::DistanceResult > distanceResults
Vector gathering the result of the distance computation for all the collision pairs.
Definition geometry.hpp:287
std::vector< bool > activeCollisionPairs
Vector of collision pairs.
Definition geometry.hpp:275
std::vector< fcl::CollisionResult > collisionResults
Vector gathering the result of the collision computation for all the collision pairs.
Definition geometry.hpp:297
std::vector< fcl::DistanceRequest > distanceRequests
Defines what information should be computed by distance computation. There is one request per pair of...
Definition geometry.hpp:282
void setGeometryCollisionStatus(const GeometryModel &geom_model, const GeomIndex geom_id, bool enable_collision)
Enable or disable collision for the given geometry given by its geometry id with all the other geomet...
void fillInnerOuterObjectMaps(const GeometryModel &geomModel)