GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/pinocchio/bindings/python/multibody/joint/joints-models.hpp Lines: 32 54 59.3 %
Date: 2024-01-23 21:41:47 Branches: 29 68 42.6 %

Line Branch Exec Source
1
//
2
// Copyright (c) 2015-2021 CNRS INRIA
3
//
4
5
#ifndef __pinocchio_python_joints_models_hpp__
6
#define __pinocchio_python_joints_models_hpp__
7
8
#include <boost/python.hpp>
9
10
#include "pinocchio/multibody/joint/joint-collection.hpp"
11
#include "pinocchio/multibody/joint/joint-composite.hpp"
12
#include "pinocchio/multibody/joint/joint-generic.hpp"
13
14
#include <eigenpy/eigen-to-python.hpp>
15
16
namespace pinocchio
17
{
18
  namespace python
19
  {
20
    namespace bp = boost::python;
21
22
23
    // generic expose_joint_model : do nothing special
24
    template <class T>
25
684
    inline bp::class_<T>& expose_joint_model(bp::class_<T>& cl)
26
    {
27
684
      return cl;
28
    }
29
30
    // specialization for JointModelRevoluteUnaligned
31
    template<>
32
19
    inline bp::class_<JointModelRevoluteUnaligned>& expose_joint_model<JointModelRevoluteUnaligned> (bp::class_<JointModelRevoluteUnaligned> & cl)
33
    {
34
      return cl
35
38
               .def(bp::init<double, double, double> (bp::args("self","x", "y", "z"),
36
19
                                                      "Init JointModelRevoluteUnaligned from the components x, y, z of the axis"))
37

38
               .def(bp::init<Eigen::Vector3d> (bp::args("self","axis"),
38
19
                                               "Init JointModelRevoluteUnaligned from an axis with x-y-z components"))
39
               .def_readwrite("axis",&JointModelRevoluteUnaligned::axis,
40
38
                              "Rotation axis of the JointModelRevoluteUnaligned.")
41
               ;
42
    }
43
44
    // specialization for JointModelPrismaticUnaligned
45
    template<>
46
19
    inline bp::class_<JointModelPrismaticUnaligned>& expose_joint_model<JointModelPrismaticUnaligned> (bp::class_<JointModelPrismaticUnaligned> & cl)
47
    {
48
      return cl
49
38
               .def(bp::init<double, double, double> (bp::args("self","x", "y", "z"),
50
19
                                                      "Init JointModelPrismaticUnaligned from the components x, y, z of the axis"))
51

38
               .def(bp::init<Eigen::Vector3d> (bp::args("self","axis"),
52
19
                                               "Init JointModelPrismaticUnaligned from an axis with x-y-z components"))
53
               .def_readwrite("axis",&JointModelPrismaticUnaligned::axis,
54
38
                              "Translation axis of the JointModelPrismaticUnaligned.")
55
               ;
56
    }
57
58
    // specialization for JointModelComposite
59
60
    struct JointModelCompositeAddJointVisitor : public boost::static_visitor<JointModelComposite &>
61
    {
62
      JointModelComposite & m_joint_composite;
63
      const SE3 & m_joint_placement;
64
65
      JointModelCompositeAddJointVisitor(JointModelComposite & joint_composite,
66
                                         const SE3 & joint_placement)
67
      : m_joint_composite(joint_composite)
68
      , m_joint_placement(joint_placement)
69
      {}
70
71
      template <typename JointModelDerived>
72
      JointModelComposite & operator()(JointModelDerived & jmodel) const
73
      {
74
        return m_joint_composite.addJoint(jmodel,m_joint_placement);
75
      }
76
    }; // struct JointModelCompositeAddJointVisitor
77
78
    static JointModelComposite & addJoint_proxy(JointModelComposite & joint_composite,
79
                                                const JointModel & jmodel,
80
                                                const SE3 & joint_placement = SE3::Identity())
81
    {
82
      return boost::apply_visitor(JointModelCompositeAddJointVisitor(joint_composite,joint_placement),
83
                                  jmodel.toVariant());
84
    }
85
86
38
    BOOST_PYTHON_FUNCTION_OVERLOADS(addJoint_proxy_overloads,addJoint_proxy,2,3)
87
88
    struct JointModelCompositeConstructorVisitor : public boost::static_visitor<JointModelComposite* >
89
    {
90
      const SE3 & m_joint_placement;
91
92
      JointModelCompositeConstructorVisitor(const SE3 & joint_placement)
93
      : m_joint_placement(joint_placement)
94
      {}
95
96
      template <typename JointModelDerived>
97
      JointModelComposite* operator()(JointModelDerived & jmodel) const
98
      {
99
        return new JointModelComposite(jmodel,m_joint_placement);
100
      }
101
    }; // struct JointModelCompositeConstructorVisitor
102
103
    static JointModelComposite* init_proxy1(const JointModel & jmodel)
104
    {
105
      return boost::apply_visitor(JointModelCompositeConstructorVisitor(SE3::Identity()),
106
                                  jmodel);
107
    }
108
109
    static JointModelComposite* init_proxy2(const JointModel & jmodel,
110
                                            const SE3 & joint_placement)
111
    {
112
      return boost::apply_visitor(JointModelCompositeConstructorVisitor(joint_placement),
113
                                  jmodel);
114
    }
115
116
    template<>
117
19
    bp::class_<JointModelComposite> & expose_joint_model<JointModelComposite>(bp::class_<JointModelComposite> & cl)
118
    {
119
      return cl
120
38
      .def(bp::init<const size_t> (bp::args("self","size"),
121
19
                                   "Init JointModelComposite with a defined size"))
122
      .def("__init__",
123
19
           bp::make_constructor(init_proxy1,
124
                                bp::default_call_policies(),
125
38
                                bp::args("joint_model")
126
                                ),
127
           "Init JointModelComposite from a joint"
128
19
           )
129
      .def("__init__",
130
19
           bp::make_constructor(init_proxy2,
131
                                bp::default_call_policies(),
132
38
                                bp::args("joint_model","joint_placement")
133
                                ),
134
           "Init JointModelComposite from a joint and a placement"
135
19
           )
136
19
      .add_property("joints",&JointModelComposite::joints)
137
19
      .add_property("jointPlacements",&JointModelComposite::jointPlacements)
138
19
      .add_property("njoints",&JointModelComposite::njoints)
139
      .def("addJoint",
140
           &addJoint_proxy,
141

19
           addJoint_proxy_overloads(bp::args("self","joint_model","joint_placement"),
142
                                    "Add a joint to the vector of joints."
143
38
                                    )[bp::return_internal_reference<>()]
144
19
           )
145
146
19
      .def(bp::self == bp::self)
147
38
      .def(bp::self != bp::self)
148
149
      ;
150
    }
151
  } // namespace python
152
} // namespace pinocchio
153
154
#endif // ifndef __pinocchio_python_joint_models_hpp__