GCC Code Coverage Report


Directory: ./
File: include/multicontact-api/bindings/python/scenario/contact-model.hpp
Date: 2025-03-10 16:17:01
Exec Total Coverage
Lines: 33 35 94.3%
Branches: 25 50 50.0%

Line Branch Exec Source
1 // Copyright (c) 2015-2018, CNRS
2 // Authors: Justin Carpentier <jcarpent@laas.fr>
3
4 #ifndef __multicontact_api_python_scenario_contact_model_planar_hpp__
5 #define __multicontact_api_python_scenario_contact_model_planar_hpp__
6
7 #include <eigenpy/eigenpy.hpp>
8 #include <string>
9
10 #include "multicontact-api/bindings/python/serialization/archive.hpp"
11 #include "multicontact-api/bindings/python/utils/printable.hpp"
12 #include "multicontact-api/scenario/contact-model.hpp"
13 #include "multicontact-api/scenario/fwd.hpp"
14
15 namespace multicontact_api {
16 namespace python {
17
18 namespace bp = boost::python;
19
20 template <typename ContactModel>
21 struct ContactModelPythonVisitor
22 : public boost::python::def_visitor<
23 ContactModelPythonVisitor<ContactModel> > {
24 typedef typename ContactModel::Scalar Scalar;
25 typedef scenario::ContactType ContactType;
26 typedef typename ContactModel::Matrix3X Matrix3X;
27 typedef typename ContactModel::Matrix6X Matrix6X;
28
29 template <class PyClass>
30 3 void visit(PyClass& cl) const {
31
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 cl.def(bp::init<>())
32
3/6
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
3 .def(bp::init<Scalar>(bp::args("mu")))
33
3/6
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
6 .def(bp::init<Scalar, ContactType>(bp::args("mu", "contact_type")))
34
3/6
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
6 .def(bp::init<ContactModel>(bp::args("other"), "Copy contructor."))
35
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 .def_readwrite("mu", &ContactModel::m_mu, "Friction coefficient.")
36
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 .def_readwrite("contact_type", &ContactModel::m_contact_type,
37 "Enum that define the type of contact.")
38
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 .add_property(
39 "num_contact_points", &getNumContact, &setNumContact,
40 "The number of contact points used to model this contact. \n"
41 "Changing this value will clear the contact_points_positions "
42 "matrix")
43
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 .add_property("contact_points_positions", &getContactPositions,
44 &setContactPositions,
45 "3xnum_contact_points matrix defining the contact points "
46 "positions in the frame of the contact "
47 "placement. \n"
48 "num_contact_points is automatically updated to the "
49 "number of columns of this matrix.")
50 6 .def("generatorMatrix", &ContactModel::generatorMatrix,
51 "generatorMatrix Return a 6x(num_contact_points*3) matrix"
52 "containing the generator used to compute contact forces.")
53
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
3 .def(bp::self == bp::self)
54
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
6 .def(bp::self != bp::self)
55
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 .def("copy", &copy, "Returns a copy of *this.");
56 3 }
57
58 3 static void expose(const std::string& class_name) {
59
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 std::string doc = "Contact Model";
60
1/2
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
3 bp::class_<ContactModel>(class_name.c_str(), doc.c_str(), bp::no_init)
61
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 .def(ContactModelPythonVisitor<ContactModel>())
62
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 .def(SerializableVisitor<ContactModel>())
63
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 .def(PrintableVisitor<ContactModel>());
64
65
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 ENABLE_SPECIFIC_MATRIX_TYPE(Matrix3X);
66
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 ENABLE_SPECIFIC_MATRIX_TYPE(Matrix6X);
67 3 }
68
69 private:
70 static ContactModel copy(const ContactModel& self) {
71 return ContactModel(self);
72 }
73 // define setter and getter
74 10 static size_t getNumContact(ContactModel& self) {
75 10 return self.num_contact_points();
76 }
77 4 static void setNumContact(ContactModel& self, const size_t num) {
78 4 self.num_contact_points(num);
79 4 }
80 24 static Matrix3X getContactPositions(ContactModel& self) {
81 24 return self.contact_points_positions();
82 }
83 4 static void setContactPositions(ContactModel& self, const Matrix3X& pos) {
84 4 self.contact_points_positions(pos);
85 4 }
86 };
87 } // namespace python
88 } // namespace multicontact_api
89
90 #endif // ifndef __multicontact_api_python_scenario_contact_model_planar_hpp__
91