pinocchio  3.7.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
 
Loading...
Searching...
No Matches
geometry-model.hpp
1//
2// Copyright (c) 2015-2023 CNRS INRIA
3//
4
5#ifndef __pinocchio_python_geometry_model_hpp__
6#define __pinocchio_python_geometry_model_hpp__
7
8#include <eigenpy/memory.hpp>
9
10#include "pinocchio/bindings/python/utils/address.hpp"
11#include "pinocchio/bindings/python/utils/printable.hpp"
12#include "pinocchio/bindings/python/utils/copyable.hpp"
13#include "pinocchio/bindings/python/utils/registration.hpp"
14#include "pinocchio/bindings/python/utils/pickle.hpp"
15#include "pinocchio/bindings/python/serialization/serializable.hpp"
16
17#include "pinocchio/multibody/geometry.hpp"
18
19#if EIGENPY_VERSION_AT_MOST(2, 8, 1)
20EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(pinocchio::GeometryModel)
21#endif
22
23namespace pinocchio
24{
25 namespace python
26 {
27 namespace bp = boost::python;
28
29 struct GeometryModelPythonVisitor
30 : public boost::python::def_visitor<GeometryModelPythonVisitor>
31 {
32 public:
33 /* --- Exposing C++ API to python through the handler ----------------- */
34 template<class PyClass>
35 void visit(PyClass & cl) const
36 {
37 cl.def(bp::init<>(bp::arg("self"), "Default constructor"))
38 .def(bp::init<const GeometryModel &>(bp::args("self", "other"), "Copy constructor"))
39
40 .add_property(
41 "ngeoms", &GeometryModel::ngeoms,
42 "Number of geometries contained in the Geometry Model.")
43 .add_property(
44 "geometryObjects", &GeometryModel::geometryObjects, "Vector of geometries objects.")
45
46 .def(
47 "addGeometryObject",
48 static_cast<GeometryModel::GeomIndex (GeometryModel::*)(const GeometryObject &)>(
50 bp::args("self", "geometry_object"),
51 "Add a GeometryObject to a GeometryModel.\n"
52 "Parameters\n"
53 "\tgeometry_object : a GeometryObject\n")
54 .def(
55 "addGeometryObject",
56 static_cast<GeometryModel::GeomIndex (GeometryModel::*)(
57 const GeometryObject &, const Model &)>(&GeometryModel::addGeometryObject),
58 bp::args("self", "geometry_object", "model"),
59 "Add a GeometryObject to a GeometryModel and set its parent joint by reading its "
60 "value in the model.\n"
61 "Parameters\n"
62 "\tgeometry_object : a GeometryObject\n"
63 "\tmodel : a Model of the system\n")
64 .def(
65 "removeGeometryObject", &GeometryModel::removeGeometryObject, bp::args("self", "name"),
66 "Remove a GeometryObject. Remove also the collision pairs that contain the object.")
67 .def(
68 "getGeometryId", &GeometryModel::getGeometryId, bp::args("self", "name"),
69 "Returns the index of a GeometryObject given by its name.")
70 .def(
71 "existGeometryName", &GeometryModel::existGeometryName, bp::args("self", "name"),
72 "Checks if a GeometryObject given by its name exists.")
73 .def(
74 "createData", &GeometryModelPythonVisitor::createData, bp::arg("self"),
75 "Create a GeometryData associated to the current model.")
76 .def("clone", &GeometryModel::clone, bp::arg("self"), "Create a deep copy of *this.")
77 .add_property(
78 "collisionPairs", &GeometryModel::collisionPairs, "Vector of collision pairs.")
79 .add_property(
80 "collisionPairMapping", &GeometryModel::collisionPairMapping,
81 "Matrix relating the collision pair ID to a pair of two GeometryObject indexes.")
82 .def(
83 "addCollisionPair", &GeometryModel::addCollisionPair,
84 bp::args("self", "collision_pair"),
85 "Add a collision pair given by the index of the two collision objects.")
86 .def(
87 "addAllCollisionPairs", &GeometryModel::addAllCollisionPairs,
88 "Add all collision pairs.\n"
89 "note : collision pairs between geometries having the same parent joint are not added.")
90 .def(
91 "setCollisionPairs", &GeometryModel::setCollisionPairs,
92 (bp::arg("self"), bp::arg("collision_map"), bp::arg("upper") = true),
93 "Set the collision pairs from a given input array.\n"
94 "Each entry of the input matrix defines the activation of a given collision pair"
95 "(map[i,j] == True means that the pair (i,j) is active).")
96 .def(
97 "removeCollisionPair", &GeometryModel::removeCollisionPair,
98 bp::args("self", "collision_pair"), "Remove a collision pair.")
99 .def(
100 "removeAllCollisionPairs", &GeometryModel::removeAllCollisionPairs,
101 "Remove all collision pairs.")
102 .def(
103 "existCollisionPair", &GeometryModel::existCollisionPair,
104 bp::args("self", "collision_pair"), "Check if a collision pair exists.")
105 .def(
106 "findCollisionPair", &GeometryModel::findCollisionPair,
107 bp::args("self", "collision_pair"), "Return the index of a collision pair.")
108
109 .def(bp::self == bp::self)
110 .def(bp::self != bp::self);
111
112 bp::register_ptr_to_python<std::shared_ptr<GeometryModel>>();
113 }
114
115 static GeometryData createData(const GeometryModel & geomModel)
116 {
117 return GeometryData(geomModel);
118 }
119
120 /* --- Expose --------------------------------------------------------- */
121 static void expose()
122 {
123 if (!register_symbolic_link_to_registered_type<GeometryModel>())
124 {
125 bp::class_<GeometryModel>(
126 "GeometryModel",
127 "Geometry model containing the collision or visual geometries associated to a model.",
128 bp::no_init)
129 .def(GeometryModelPythonVisitor())
130 .def(PrintableVisitor<GeometryModel>())
131 .def(SerializableVisitor<GeometryModel>())
132 .def(CopyableVisitor<GeometryModel>())
133 .def(AddressVisitor<GeometryModel>())
134#ifndef PINOCCHIO_PYTHON_NO_SERIALIZATION
135 .def_pickle(PickleFromStringSerialization<GeometryModel>())
136#endif
137 ;
138 }
139 }
140 };
141
142 } // namespace python
143} // namespace pinocchio
144
145#endif // ifndef __pinocchio_python_geometry_model_hpp__
Main pinocchio namespace.
Definition treeview.dox:11
void setCollisionPairs(const MatrixXb &collision_map, const bool upper=true)
Set the collision pairs from a given input array. Each entry of the input matrix defines the activati...
GeomIndex addGeometryObject(const GeometryObject &object, const ModelTpl< S2, O2, _JointCollectionTpl > &model)
Add a geometry object to a GeometryModel and set its parent joint.
PairIndex findCollisionPair(const CollisionPair &pair) const
Return the index of a given collision pair in collisionPairs.
bool existCollisionPair(const CollisionPair &pair) const
Check if a collision pair exists in collisionPairs. See also findCollisitionPair(const CollisionPair ...
void removeAllCollisionPairs()
Remove all collision pairs from collisionPairs. Same as collisionPairs.clear().
void addCollisionPair(const CollisionPair &pair)
Add a collision pair into the vector of collision_pairs. The method check before if the given Collisi...
GeometryObjectVector geometryObjects
Vector of GeometryObjects used for collision computations.
Definition geometry.hpp:221
GeomIndex getGeometryId(const std::string &name) const
Return the index of a GeometryObject given by its name.
bool existGeometryName(const std::string &name) const
Check if a GeometryObject given by its name exists.
MatrixXi collisionPairMapping
Matrix relating the collision pair ID to a pair of two GeometryObject indexes.
Definition geometry.hpp:227
void addAllCollisionPairs()
Add all possible collision pairs.
void removeGeometryObject(const std::string &name)
Remove a GeometryObject.
Index ngeoms
The number of GeometryObjects.
Definition geometry.hpp:218
GeometryModel clone() const
Create a deep copy of *this.
CollisionPairVector collisionPairs
Vector of collision pairs.
Definition geometry.hpp:224
void removeCollisionPair(const CollisionPair &pair)
Remove if exists the CollisionPair from the vector collision_pairs.