contact-sequence.hpp 2.25 KB
Newer Older
Justin Carpentier's avatar
Justin Carpentier committed
1
2
// Copyright (c) 2015-2018, CNRS
// Authors: Justin Carpentier <jcarpent@laas.fr>
Guilhem Saurel's avatar
Guilhem Saurel committed
3
4
5

#ifndef __multicontact_api_python_scenario_contact_sequence_hpp__
#define __multicontact_api_python_scenario_contact_sequence_hpp__
Justin Carpentier's avatar
Justin Carpentier committed
6

7
#include <pinocchio/fwd.hpp>
Justin Carpentier's avatar
Justin Carpentier committed
8
9
10
#include <eigenpy/eigenpy.hpp>
#include <pinocchio/bindings/python/utils/std-aligned-vector.hpp>

Guilhem Saurel's avatar
Guilhem Saurel committed
11
12
#include "multicontact-api/scenario/contact-sequence.hpp"
#include "multicontact-api/bindings/python/serialization/archive.hpp"
Justin Carpentier's avatar
Justin Carpentier committed
13

Guilhem Saurel's avatar
Guilhem Saurel committed
14
15
namespace multicontact_api {
namespace python {
Guilhem Saurel's avatar
Guilhem Saurel committed
16

Guilhem Saurel's avatar
Guilhem Saurel committed
17
namespace bp = boost::python;
Guilhem Saurel's avatar
Guilhem Saurel committed
18

Guilhem Saurel's avatar
Guilhem Saurel committed
19
template <typename CS>
20
struct ContactSequencePythonVisitor : public bp::def_visitor<ContactSequencePythonVisitor<CS> > {
Guilhem Saurel's avatar
Guilhem Saurel committed
21
  typedef typename CS::ContactPhaseVector ContactPhaseVector;
Guilhem Saurel's avatar
Guilhem Saurel committed
22

23

Guilhem Saurel's avatar
Guilhem Saurel committed
24

Guilhem Saurel's avatar
Guilhem Saurel committed
25
26
27
  template <class PyClass>
  void visit(PyClass& cl) const {
    cl.def(bp::init<size_t>(bp::arg("size"), "Default constructor from a given size."))
28
        .def(bp::init<>(bp::arg(""),"Default constructor."))
Guilhem Saurel's avatar
Guilhem Saurel committed
29
        .def(bp::init<CS>(bp::args("other"), "Copy contructor."))
30
31
32
33
34
35
36
37
        .def("size", &CS::size, "Return the size of the contact sequence.")
        .def("resize", &CS::resize,bp::arg("size"), "Resize the vector of ContactPhases.")
        .def("append",&CS::append,bp::arg("ContactPhase"),
        "Add the given ContactPhase at the end of the sequence. \n"
        "Return the new id of this ContactPhase inside the sequence.")
        .add_property("contactPhases",
        bp::make_getter(&CS::m_contact_phases,bp::return_internal_reference<>()),
        "Vector of Contact Phases contained in the sequence")
Justin Carpentier's avatar
Justin Carpentier committed
38
39
        .def(bp::self == bp::self)
        .def(bp::self != bp::self)
40
41
        .def("copy", &copy, "Returns a copy of *this.");
        ;
Guilhem Saurel's avatar
Guilhem Saurel committed
42
  }
Guilhem Saurel's avatar
Guilhem Saurel committed
43

Guilhem Saurel's avatar
Guilhem Saurel committed
44
45
46
  static void expose(const std::string& class_name) {
    std::string doc = "Contact Sequence of dynamic size";
    bp::class_<CS>(class_name.c_str(), doc.c_str(), bp::no_init)
Justin Carpentier's avatar
Justin Carpentier committed
47
        .def(ContactSequencePythonVisitor<CS>())
Guilhem Saurel's avatar
Guilhem Saurel committed
48
        .def(SerializableVisitor<CS>());
Guilhem Saurel's avatar
Guilhem Saurel committed
49

50
51
    bp::class_<ContactPhaseVector>("ContactPhaseVector")
        .def(bp::vector_indexing_suite<ContactPhaseVector>() );
Justin Carpentier's avatar
Justin Carpentier committed
52
  }
53
54
55
56
57
58

  protected:

    static CS copy(const CS& self) { return CS(self); }


Guilhem Saurel's avatar
Guilhem Saurel committed
59
60
61
};
}  // namespace python
}  // namespace multicontact_api
Justin Carpentier's avatar
Justin Carpentier committed
62

Guilhem Saurel's avatar
Guilhem Saurel committed
63
#endif  // ifndef __multicontact_api_python_scenario_contact_sequence_hpp__