| Directory: | ./ |
|---|---|
| File: | include/pinocchio/bindings/python/multibody/frame.hpp |
| Date: | 2025-02-12 21:03:38 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 57 | 61 | 93.4% |
| Branches: | 99 | 196 | 50.5% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2016-2022 CNRS INRIA | ||
| 3 | // | ||
| 4 | |||
| 5 | #ifndef __pinocchio_python_multibody_frame_hpp__ | ||
| 6 | #define __pinocchio_python_multibody_frame_hpp__ | ||
| 7 | |||
| 8 | #include "pinocchio/multibody/fwd.hpp" | ||
| 9 | #include "pinocchio/multibody/frame.hpp" | ||
| 10 | |||
| 11 | #include "pinocchio/bindings/python/utils/deprecation.hpp" | ||
| 12 | #include "pinocchio/bindings/python/utils/cast.hpp" | ||
| 13 | #include "pinocchio/bindings/python/utils/copyable.hpp" | ||
| 14 | #include "pinocchio/bindings/python/utils/printable.hpp" | ||
| 15 | #include "pinocchio/bindings/python/utils/registration.hpp" | ||
| 16 | |||
| 17 | namespace pinocchio | ||
| 18 | { | ||
| 19 | namespace python | ||
| 20 | { | ||
| 21 | namespace bp = boost::python; | ||
| 22 | |||
| 23 | template<typename Frame> | ||
| 24 | struct FramePythonVisitor : public boost::python::def_visitor<FramePythonVisitor<Frame>> | ||
| 25 | { | ||
| 26 | typedef typename Frame::SE3 SE3; | ||
| 27 | typedef typename Frame::Inertia Inertia; | ||
| 28 | |||
| 29 | template<class PyClass> | ||
| 30 | 69 | void visit(PyClass & cl) const | |
| 31 | { | ||
| 32 |
2/4✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 69 times.
✗ Branch 6 not taken.
|
69 | cl.def(bp::init<>(bp::arg("self"), "Default constructor")) |
| 33 |
3/6✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 69 times.
✗ Branch 8 not taken.
|
138 | .def(bp::init<const Frame &>(bp::args("self", "other"), "Copy constructor")) |
| 34 |
6/12✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 69 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 69 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 69 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 69 times.
✗ Branch 17 not taken.
|
276 | .def(bp::init< |
| 35 | const std::string &, const JointIndex, const SE3 &, FrameType, | ||
| 36 | bp::optional<const Inertia &>>( | ||
| 37 |
4/8✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 69 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 69 times.
✗ Branch 11 not taken.
|
276 | (bp::arg("name"), bp::arg("parent_joint"), bp::arg("placement"), bp::arg("type"), |
| 38 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
138 | bp::arg("inertia")), |
| 39 | "Initialize from a given name, type, parent frame index and placement wrt parent joint " | ||
| 40 | "and an spatial inertia object.")) | ||
| 41 |
8/16✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 69 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 69 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 69 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 69 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 69 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 69 times.
✗ Branch 23 not taken.
|
345 | .def(bp::init< |
| 42 | const std::string &, const JointIndex, const FrameIndex, const SE3 &, FrameType, | ||
| 43 | bp::optional<const Inertia &>>( | ||
| 44 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | (bp::arg("name"), bp::arg("parent_joint"), bp::args("parent_frame"), |
| 45 |
3/6✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 69 times.
✗ Branch 8 not taken.
|
276 | bp::arg("placement"), bp::arg("type"), bp::arg("inertia")), |
| 46 | "Initialize from a given name, type, parent joint index, parent frame index and " | ||
| 47 | "placement wrt parent joint and an spatial inertia object.")) | ||
| 48 |
5/10✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 69 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 69 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 69 times.
✗ Branch 14 not taken.
|
138 | .def(bp::init<const Frame &>((bp::arg("self"), bp::arg("clone")), "Copy constructor")) |
| 49 | |||
| 50 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def_readwrite("name", &Frame::name, "name of the frame") |
| 51 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def_readwrite("parentJoint", &Frame::parentJoint, "Index of the parent joint") |
| 52 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def_readwrite("parentFrame", &Frame::parentFrame, "Index of the parent frame") |
| 53 |
3/6✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 69 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 69 times.
✗ Branch 10 not taken.
|
138 | .add_property( |
| 54 | "parent", | ||
| 55 | bp::make_function( | ||
| 56 | ✗ | +[](const Frame & self) { return self.parentJoint; }, | |
| 57 |
2/4✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 69 times.
✗ Branch 6 not taken.
|
138 | deprecated_member<>("Deprecated member. Use Frame.parentJoint instead.")), |
| 58 | bp::make_function( | ||
| 59 | ✗ | +[](Frame & self, const JointIndex index) { self.parentJoint = index; }, | |
| 60 |
2/4✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 69 times.
✗ Branch 6 not taken.
|
138 | deprecated_member<>("Deprecated member. Use Frame.parentJoint instead.")), |
| 61 | "See parentJoint property.") | ||
| 62 |
3/6✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 69 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 69 times.
✗ Branch 10 not taken.
|
138 | .add_property( |
| 63 | "previousFrame", | ||
| 64 | bp::make_function( | ||
| 65 | ✗ | +[](const Frame & self) { return self.parentFrame; }, | |
| 66 |
2/4✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 69 times.
✗ Branch 6 not taken.
|
138 | deprecated_member<>("Deprecated member. Use Frame.parentFrame instead.")), |
| 67 | bp::make_function( | ||
| 68 | ✗ | +[](Frame & self, const FrameIndex index) { self.parentFrame = index; }, | |
| 69 |
2/4✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 69 times.
✗ Branch 6 not taken.
|
138 | deprecated_member<>("Deprecated member. Use Frame.parentFrame instead.")), |
| 70 | "See parentFrame property.") | ||
| 71 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def_readwrite( |
| 72 | "placement", &Frame::placement, "placement in the parent joint local frame") | ||
| 73 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def_readwrite("type", &Frame::type, "type of the frame") |
| 74 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def_readwrite("inertia", &Frame::inertia, "Inertia information attached to the frame.") |
| 75 | |||
| 76 | #ifndef PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS | ||
| 77 |
1/2✓ Branch 2 taken 65 times.
✗ Branch 3 not taken.
|
65 | .def(bp::self == bp::self) |
| 78 |
1/2✓ Branch 2 taken 65 times.
✗ Branch 3 not taken.
|
65 | .def(bp::self != bp::self) |
| 79 | #endif | ||
| 80 | ; | ||
| 81 | 69 | } | |
| 82 | |||
| 83 | 69 | static void expose() | |
| 84 | { | ||
| 85 |
2/2✓ Branch 1 taken 65 times.
✓ Branch 2 taken 4 times.
|
69 | if (!register_symbolic_link_to_registered_type<FrameType>()) |
| 86 | { | ||
| 87 | 130 | bp::enum_<FrameType>("FrameType") | |
| 88 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .value("OP_FRAME", OP_FRAME) |
| 89 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .value("JOINT", JOINT) |
| 90 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .value("FIXED_JOINT", FIXED_JOINT) |
| 91 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .value("BODY", BODY) |
| 92 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .value("SENSOR", SENSOR) |
| 93 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .export_values(); |
| 94 | } | ||
| 95 | |||
| 96 | 69 | bp::class_<Frame>( | |
| 97 | "Frame", | ||
| 98 | "A Plucker coordinate frame related to a parent joint inside a kinematic tree.\n", | ||
| 99 | bp::no_init) | ||
| 100 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def(FramePythonVisitor()) |
| 101 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def(CastVisitor<Frame>()) |
| 102 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def(ExposeConstructorByCastVisitor<Frame, ::pinocchio::Frame>()) |
| 103 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def(CopyableVisitor<Frame>()) |
| 104 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def(PrintableVisitor<Frame>()) |
| 105 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def_pickle(Pickle()); |
| 106 | 69 | } | |
| 107 | |||
| 108 | private: | ||
| 109 | struct Pickle : bp::pickle_suite | ||
| 110 | { | ||
| 111 | 1 | static bp::tuple getinitargs(const Frame &) | |
| 112 | { | ||
| 113 | 1 | return bp::make_tuple(); | |
| 114 | } | ||
| 115 | |||
| 116 | 1 | static bp::tuple getstate(const Frame & f) | |
| 117 | { | ||
| 118 | return bp::make_tuple( | ||
| 119 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | f.name, f.parentJoint, f.parentFrame, f.placement, (int)f.type, f.inertia); |
| 120 | } | ||
| 121 | |||
| 122 | 1 | static void setstate(Frame & f, bp::tuple tup) | |
| 123 | { | ||
| 124 |
5/10✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
|
1 | f.name = bp::extract<std::string>(tup[0]); |
| 125 |
4/8✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
|
1 | f.parentJoint = bp::extract<JointIndex>(tup[1]); |
| 126 |
4/8✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
|
1 | f.parentFrame = bp::extract<JointIndex>(tup[2]); |
| 127 |
5/10✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
|
1 | f.placement = bp::extract<SE3 &>(tup[3]); |
| 128 |
4/8✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
|
1 | f.type = (FrameType)(int)bp::extract<int>(tup[4]); |
| 129 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | if (bp::len(tup) > 5) |
| 130 |
5/10✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
|
1 | f.inertia = bp::extract<Inertia &>(tup[5]); |
| 131 | 1 | } | |
| 132 | |||
| 133 | 69 | static bool getstate_manages_dict() | |
| 134 | { | ||
| 135 | 69 | return true; | |
| 136 | } | ||
| 137 | }; | ||
| 138 | }; | ||
| 139 | |||
| 140 | } // namespace python | ||
| 141 | } // namespace pinocchio | ||
| 142 | |||
| 143 | #endif // ifndef __pinocchio_python_multibody_frame_hpp__ | ||
| 144 |