GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/pinocchio/bindings/python/multibody/geometry-model.hpp Lines: 30 30 100.0 %
Date: 2024-01-23 21:41:47 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
EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(pinocchio::GeometryModel)
15
16
namespace pinocchio
17
{
18
  namespace python
19
  {
20
    namespace bp = boost::python;
21
22
    struct GeometryModelPythonVisitor
23
    : public boost::python::def_visitor< GeometryModelPythonVisitor >
24
    {
25
    public:
26
27
      /* --- Exposing C++ API to python through the handler ----------------- */
28
      template<class PyClass>
29
19
      void visit(PyClass& cl) const
30
      {
31
19
        cl
32
        .def(bp::init<>(bp::arg("self"),"Default constructor"))
33

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

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

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

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

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

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

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

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

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

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

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