GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/pinocchio/bindings/python/multibody/geometry-object.hpp Lines: 31 35 88.6 %
Date: 2023-08-09 08:43:58 Branches: 33 90 36.7 %

Line Branch Exec Source
1
//
2
// Copyright (c) 2017-2021 CNRS INRIA
3
//
4
5
#ifndef __pinocchio_python_geometry_object_hpp__
6
#define __pinocchio_python_geometry_object_hpp__
7
8
#include <boost/python.hpp>
9
#include <eigenpy/memory.hpp>
10
#include <eigenpy/eigen-to-python.hpp>
11
12
#include "pinocchio/multibody/geometry.hpp"
13
14
EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(pinocchio::GeometryObject)
15
16
namespace pinocchio
17
{
18
  namespace python
19
  {
20
    namespace bp = boost::python;
21
22
    struct GeometryObjectPythonVisitor
23
    : public boost::python::def_visitor< GeometryObjectPythonVisitor >
24
    {
25
      typedef GeometryObject::CollisionGeometryPtr CollisionGeometryPtr;
26
27
      template<class PyClass>
28
19
      void visit(PyClass& cl) const
29
      {
30
19
        cl
31
        .def(bp::init<std::string,FrameIndex,JointIndex,CollisionGeometryPtr,SE3,
32
                      bp::optional<std::string,Eigen::Vector3d,bool,Eigen::Vector4d,std::string> >
33
             (
34
             bp::args("self","name","parent_frame","parent_joint","collision_geometry",
35
                      "placement", "mesh_path", "mesh_scale", "override_material", "mesh_color", "mesh_texture_path"),
36
             "Full constructor of a GeometryObject."))
37

19
        .def(bp::init<std::string,JointIndex,CollisionGeometryPtr,SE3,
38
                      bp::optional<std::string,Eigen::Vector3d,bool,Eigen::Vector4d,std::string> >
39
             (
40
              bp::args("self","name","parent_joint","collision_geometry",
41
                       "placement", "mesh_path", "mesh_scale", "override_material", "mesh_color", "mesh_texture_path"),
42
              "Reduced constructor of a GeometryObject. This constructor does not require to specify the parent frame index."
43
              ))
44

38
        .def(bp::init<const GeometryObject&>
45
             (
46
              bp::args("self","otherGeometryObject"),
47
              "Copy constructor"
48
              ))
49

38
        .add_property("meshScale",
50
                      bp::make_getter(&GeometryObject::meshScale,
51
                                      bp::return_internal_reference<>()),
52
                      bp::make_setter(&GeometryObject::meshScale),
53
                       "Scaling parameter of the mesh.")
54

38
        .add_property("meshColor",
55
                      bp::make_getter(&GeometryObject::meshColor,
56
                                      bp::return_internal_reference<>()),
57
                      bp::make_setter(&GeometryObject::meshColor),
58
                      "Color rgba of the mesh.")
59

38
        .def_readwrite("geometry", &GeometryObject::geometry,
60
                       "The FCL CollisionGeometry associated to the given GeometryObject.")
61
19
        .def_readwrite("name", &GeometryObject::name,
62
                       "Name associated to the given GeometryObject.")
63
19
        .def_readwrite("parentJoint", &GeometryObject::parentJoint,
64
                       "Index of the parent joint.")
65
19
        .def_readwrite("parentFrame", &GeometryObject::parentFrame,
66
                       "Index of the parent frame.")
67
19
        .def_readwrite("placement",&GeometryObject::placement,
68
                       "Position of geometry object in parent joint's frame.")
69
19
        .def_readwrite("meshPath", &GeometryObject::meshPath,
70
                       "Path to the mesh file.")
71
19
        .def_readwrite("overrideMaterial", &GeometryObject::overrideMaterial,
72
                       "Boolean that tells whether material information is stored inside the given GeometryObject.")
73
19
        .def_readwrite("meshTexturePath", &GeometryObject::meshTexturePath,
74
                       "Path to the mesh texture file.")
75
19
        .def_readwrite("disableCollision", &GeometryObject::disableCollision,
76
                       "If true, no collision or distance check will be done between the Geometry and any other geometry.")
77
78
19
        .def(bp::self == bp::self)
79
38
        .def(bp::self != bp::self)
80
81
#ifdef PINOCCHIO_WITH_HPP_FCL
82
19
          .def("CreateCapsule", &GeometryObjectPythonVisitor::maker_capsule)
83

19
          .staticmethod("CreateCapsule")
84
#endif // PINOCCHIO_WITH_HPP_FCL
85
        ;
86
87
        // Check registration
88
        {
89
19
          const bp::type_info info = bp::type_id<CollisionGeometryPtr>();
90
19
          const bp::converter::registration* reg = bp::converter::registry::query(info);
91
          // We just need to check if the type shared_ptr<CollisionGeometry> exist in the registry
92
19
          if(!reg)
93
            bp::register_ptr_to_python<CollisionGeometryPtr>();
94
        }
95
19
      }
96
97
#ifdef PINOCCHIO_WITH_HPP_FCL
98
      static GeometryObject maker_capsule(const double radius, const double length)
99
      {
100
        return GeometryObject("",FrameIndex(0),JointIndex(0),
101
                              pinocchio::shared_ptr<fcl::CollisionGeometry>(new fcl::Capsule(radius, length)),
102
                              SE3::Identity());
103
104
      }
105
#endif // PINOCCHIO_WITH_HPP_FCL
106
107
19
      static void expose()
108
      {
109
19
        bp::class_<GeometryObject>("GeometryObject",
110
                                   "A wrapper on a collision geometry including its parent joint, parent frame, placement in parent joint's frame.\n\n",
111
                                   bp::no_init
112
                                   )
113
19
        .def(GeometryObjectPythonVisitor())
114
        ;
115
116
38
        bp::enum_<GeometryType>("GeometryType")
117
19
        .value("VISUAL",VISUAL)
118
19
        .value("COLLISION",COLLISION)
119
19
        .export_values()
120
        ;
121
19
      }
122
123
    };
124
125
126
  } // namespace python
127
} // namespace pinocchio
128
129
#endif // ifndef __pinocchio_python_geometry_object_hpp__