GCC Code Coverage Report


Directory: ./
File: include/pinocchio/bindings/python/visualizers/visualizer-visitor.hpp
Date: 2025-04-30 16:14:33
Exec Total Coverage
Lines: 22 29 75.9%
Branches: 38 78 48.7%

Line Branch Exec Source
1 //
2 // Copyright (c) 2024-2025 INRIA
3 //
4 #ifndef __pinocchio_python_extra_extras_hpp__
5 #define __pinocchio_python_extra_extras_hpp__
6
7 #include "pinocchio/visualizers/base-visualizer.hpp"
8 #include "pinocchio/bindings/python/fwd.hpp"
9
10 #include <eigenpy/optional.hpp>
11
12 namespace pinocchio
13 {
14 namespace python
15 {
16 namespace bp = boost::python;
17
18 template<class Visualizer>
19 struct VisualizerPythonVisitor : bp::def_visitor<VisualizerPythonVisitor<Visualizer>>
20 {
21 typedef ::pinocchio::visualizers::BaseVisualizer Base;
22 typedef ::pinocchio::visualizers::ConstMatrixRef ConstMatrixRef;
23 static_assert(
24 std::is_base_of<Base, Visualizer>::value,
25 "Visualizer class must be derived from pinocchio::visualizers::BaseVisualizer.");
26
27 static void setCameraPose_proxy(Visualizer & vis, const Base::Matrix4 & pose)
28 {
29 vis.setCameraPose(pose);
30 }
31
32 static void setCameraPose_proxy2(Visualizer & vis, const SE3 & pose)
33 {
34 vis.setCameraPose(pose);
35 }
36
37 static void play_proxy2(Visualizer & vis, const ConstMatrixRef & qs, context::Scalar dt)
38 {
39 vis.play(qs, dt);
40 }
41
42 template<class... PyArgs>
43 2 void visit(bp::class_<PyArgs...> & cl) const
44 {
45 using ::pinocchio::visualizers::ConstVectorRef;
46 2 eigenpy::OptionalConverter<ConstVectorRef, boost::optional>::registration();
47
48 // convenience macro to use a lambda -- passing &Visualizer::<getter-fun> doesn't work
49 #define DEF_PROP_PROXY(name) \
50 add_property( \
51 #name, \
52 bp::make_function( \
53 +[](Visualizer & v) -> auto & { return v.name(); }, bp::return_internal_reference<>()))
54
55 4 cl.def("initViewer", &Visualizer::initViewer)
56 2 .def("loadViewerModel", &Visualizer::loadViewerModel)
57 2 .def("rebuildData", &Visualizer::rebuildData)
58
1/2
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
4 .def(
59 "display", +[](Visualizer & v, const ConstVectorRef & q) { v.display(q); },
60
3/6
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
4 (bp::arg("self"), bp::arg("q") = boost::none))
61
4/8
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
4 .def("play", play_proxy2, (bp::arg("self"), "qs", "dt"))
62
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
4 .def("setCameraTarget", &Visualizer::setCameraTarget, (bp::arg("self"), "target"))
63
3/6
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
4 .def("setCameraPosition", &Visualizer::setCameraPosition, (bp::arg("self"), "position"))
64
4/8
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
4 .def("setCameraPose", setCameraPose_proxy, (bp::arg("self"), "pose"))
65
3/6
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
4 .def("setCameraPose", setCameraPose_proxy2, (bp::arg("self"), "pose"))
66
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
4 .def("setCameraZoom", &Visualizer::setCameraZoom, (bp::arg("self"), "value"))
67
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
4 .def("clean", &Visualizer::clean, bp::arg("self"))
68
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 .def("hasExternalData", &Visualizer::hasExternalData)
69
3/6
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
5 .DEF_PROP_PROXY(model)
70
2/4
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
5 .DEF_PROP_PROXY(visualModel)
71
2/4
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
4 .DEF_PROP_PROXY(collisionModel)
72
2/4
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
4 .DEF_PROP_PROXY(data)
73
2/4
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
4 .DEF_PROP_PROXY(visualData)
74
2/4
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
2 .DEF_PROP_PROXY(collisionData);
75 #undef DEF_PROP_PROXY
76 2 }
77 };
78
79 } // namespace python
80 } // namespace pinocchio
81
82 #endif // #ifndef __pinocchio_python_extra_extras_hpp__
83