GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/pinocchio/bindings/python/multibody/geometry-model.hpp Lines: 30 30 100.0 %
Date: 2024-04-26 13:14:21 Branches: 35 70 50.0 %

Line Branch Exec Source
1
//
2
// Copyright (c) 2015-2021 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/printable.hpp"
11
#include "pinocchio/bindings/python/utils/copyable.hpp"
12
#include "pinocchio/multibody/geometry.hpp"
13
14
#if EIGENPY_VERSION_AT_MOST(2,8,1)
15
EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(pinocchio::GeometryModel)
16
#endif
17
18
namespace pinocchio
19
{
20
  namespace python
21
  {
22
    namespace bp = boost::python;
23
24
    struct GeometryModelPythonVisitor
25
    : public boost::python::def_visitor< GeometryModelPythonVisitor >
26
    {
27
    public:
28
29
      /* --- Exposing C++ API to python through the handler ----------------- */
30
      template<class PyClass>
31
19
      void visit(PyClass& cl) const
32
      {
33
19
        cl
34
        .def(bp::init<>(bp::arg("self"),"Default constructor"))
35

19
        .add_property("ngeoms", &GeometryModel::ngeoms, "Number of geometries contained in the Geometry Model.")
36
19
        .add_property("geometryObjects",
37
                      &GeometryModel::geometryObjects,"Vector of geometries objects.")
38
39
19
        .def("addGeometryObject",
40
             static_cast <GeometryModel::GeomIndex (GeometryModel::*)(const GeometryObject &)>(&GeometryModel::addGeometryObject),
41
             bp::args("self","geometry_object"),
42
             "Add a GeometryObject to a GeometryModel.\n"
43
             "Parameters\n"
44
             "\tgeometry_object : a GeometryObject\n")
45

38
        .def("addGeometryObject",
46
             static_cast <GeometryModel::GeomIndex (GeometryModel::*)(const GeometryObject &,
47
                                                                      const Model &)>(&GeometryModel::addGeometryObject),
48
             bp::args("self","geometry_object","model"),
49
             "Add a GeometryObject to a GeometryModel and set its parent joint by reading its value in the model.\n"
50
             "Parameters\n"
51
             "\tgeometry_object : a GeometryObject\n"
52
             "\tmodel : a Model of the system\n")
53

38
         .def("removeGeometryObject",
54
             &GeometryModel::removeGeometryObject,
55
             bp::args("self","name"),
56
             "Remove a GeometryObject. Remove also the collision pairs that contain the object.")
57
38
        .def("getGeometryId",
58
             &GeometryModel::getGeometryId,
59
             bp::args("self","name"),
60
             "Returns the index of a GeometryObject given by its name.")
61

38
        .def("existGeometryName",
62
             &GeometryModel::existGeometryName,
63
             bp::args("self","name"),
64
             "Checks if a GeometryObject  given by its name exists.")
65

38
        .def("createData",
66
             &GeometryModelPythonVisitor::createData,
67
             bp::arg("self"),
68
             "Create a GeometryData associated to the current model.")
69

38
        .add_property("collisionPairs",
70
                      &GeometryModel::collisionPairs,
71
                      "Vector of collision pairs.")
72
19
        .def("addCollisionPair",&GeometryModel::addCollisionPair,
73
             bp::args("self","collision_pair"),
74
             "Add a collision pair given by the index of the two collision objects.")
75
38
        .def("addAllCollisionPairs",&GeometryModel::addAllCollisionPairs,
76
             "Add all collision pairs.\n"
77
             "note : collision pairs between geometries having the same parent joint are not added.")
78
19
        .def("setCollisionPairs",
79
             &GeometryModel::setCollisionPairs,
80
             setCollisionPairs_overload(bp::args("self","collision_map","upper"),
81
                                        "Set the collision pairs from a given input array.\n"
82
                                        "Each entry of the input matrix defines the activation of a given collision pair"
83
                                        "(map[i,j] == True means that the pair (i,j) is active)."))
84

38
        .def("removeCollisionPair",&GeometryModel::removeCollisionPair,
85
             bp::args("self","collision_pair"),
86
             "Remove a collision pair.")
87

38
        .def("removeAllCollisionPairs",&GeometryModel::removeAllCollisionPairs,
88
             "Remove all collision pairs.")
89
19
        .def("existCollisionPair",&GeometryModel::existCollisionPair,
90
             bp::args("self","collision_pair"),
91
             "Check if a collision pair exists.")
92

38
        .def("findCollisionPair", &GeometryModel::findCollisionPair,
93
             bp::args("self","collision_pair"),
94
             "Return the index of a collision pair.")
95
96

57
        .def(bp::self == bp::self)
97

57
        .def(bp::self != bp::self)
98
        ;
99
19
      }
100
101
22
      static GeometryData createData(const GeometryModel & geomModel)
102
      {
103
22
        return GeometryData(geomModel);
104
      }
105
106
      /* --- Expose --------------------------------------------------------- */
107
19
      static void expose()
108
      {
109
19
        bp::class_<GeometryModel>("GeometryModel",
110
                                  "Geometry model containing the collision or visual geometries associated to a model.",
111
                                  bp::no_init)
112
19
        .def(GeometryModelPythonVisitor())
113
19
        .def(PrintableVisitor<GeometryModel>())
114
19
        .def(CopyableVisitor<GeometryModel>())
115
        ;
116
19
      }
117
118
    protected:
119
120
38
      BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(setCollisionPairs_overload,GeometryModel::setCollisionPairs,1,2)
121
122
    };
123
124
  } // namespace python
125
} // namespace pinocchio
126
127
#endif // ifndef __pinocchio_python_geometry_model_hpp__