GCC Code Coverage Report


Directory: ./
File: bindings/python/algorithm/expose-model.cpp
Date: 2024-08-27 18:20:05
Exec Total Coverage
Lines: 33 37 89.2%
Branches: 21 46 45.7%

Line Branch Exec Source
1 //
2 // Copyright (c) 2019-2024 INRIA
3 //
4
5 #include "pinocchio/bindings/python/algorithm/algorithms.hpp"
6 #include "pinocchio/bindings/python/utils/std-vector.hpp"
7 #include "pinocchio/algorithm/model.hpp"
8
9 namespace pinocchio
10 {
11 namespace python
12 {
13
14 namespace bp = boost::python;
15
16 template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl>
17 1 bp::tuple appendModel_proxy(
18 const ModelTpl<Scalar, Options, JointCollectionTpl> & modelA,
19 const ModelTpl<Scalar, Options, JointCollectionTpl> & modelB,
20 const GeometryModel & geomModelA,
21 const GeometryModel & geomModelB,
22 const FrameIndex frameInModelA,
23 const SE3Tpl<Scalar, Options> & aMb)
24 {
25 typedef ModelTpl<Scalar, Options, JointCollectionTpl> Model;
26
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 Model model;
27
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 GeometryModel geom_model;
28
29
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 appendModel(modelA, modelB, geomModelA, geomModelB, frameInModelA, aMb, model, geom_model);
30
31
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 return bp::make_tuple(model, geom_model);
32 1 }
33
34 template<
35 typename Scalar,
36 int Options,
37 template<typename, int>
38 class JointCollectionTpl,
39 typename ConfigVectorType>
40 1 bp::tuple buildReducedModel(
41 const ModelTpl<Scalar, Options, JointCollectionTpl> & model,
42 const GeometryModel & geom_model,
43 const std::vector<JointIndex> & list_of_joints_to_lock,
44 const Eigen::MatrixBase<ConfigVectorType> & reference_configuration)
45 {
46 typedef ModelTpl<Scalar, Options, JointCollectionTpl> Model;
47
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 Model reduced_model;
48
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 GeometryModel reduced_geom_model;
49
50
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 buildReducedModel(
51 model, geom_model, list_of_joints_to_lock, reference_configuration, reduced_model,
52 reduced_geom_model);
53
54
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 return bp::make_tuple(reduced_model, reduced_geom_model);
55 1 }
56
57 template<
58 typename Scalar,
59 int Options,
60 template<typename, int>
61 class JointCollectionTpl,
62 typename ConfigVectorType>
63 2 bp::tuple buildReducedModel(
64 const ModelTpl<Scalar, Options, JointCollectionTpl> & model,
65 const std::vector<GeometryModel, Eigen::aligned_allocator<GeometryModel>> &
66 list_of_geom_models,
67 const std::vector<JointIndex> & list_of_joints_to_lock,
68 const Eigen::MatrixBase<ConfigVectorType> & reference_configuration)
69 {
70 typedef ModelTpl<Scalar, Options, JointCollectionTpl> Model;
71
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 std::vector<GeometryModel, Eigen::aligned_allocator<GeometryModel>> reduced_geom_models;
72
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 Model reduced_model;
73
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 buildReducedModel(
74 model, list_of_geom_models, list_of_joints_to_lock, reference_configuration, reduced_model,
75 reduced_geom_models);
76
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 return bp::make_tuple(reduced_model, reduced_geom_models);
77 2 }
78
79 bp::tuple findCommonAncestor_proxy(
80 const context::Model & model, const JointIndex joint1_id, const JointIndex joint2_id)
81 {
82 size_t index_ancestor_in_support1, index_ancestor_in_support2;
83 JointIndex ancestor_id = findCommonAncestor(
84 model, joint1_id, joint2_id, index_ancestor_in_support1, index_ancestor_in_support2);
85 return bp::make_tuple(ancestor_id, index_ancestor_in_support1, index_ancestor_in_support2);
86 }
87
88 20 void exposeModelAlgo()
89 {
90 using namespace Eigen;
91
92 typedef std::vector<GeometryModel, Eigen::aligned_allocator<GeometryModel>>
93 GeometryModelVector;
94
3/6
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 20 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 20 times.
✗ Branch 10 not taken.
20 StdVectorPythonVisitor<GeometryModelVector>::expose("StdVec_GeometryModel");
95
96
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 bp::def(
97 "appendModel",
98 (Model(*)(const Model &, const Model &, const FrameIndex, const SE3 &))
99 & appendModel<double, 0, JointCollectionDefaultTpl>,
100 40 bp::args("modelA", "modelB", "frame_in_modelA", "aMb"),
101 "Append a child model into a parent model, after a specific frame given by its index.\n\n"
102 "Parameters:\n"
103 "\tmodelA: the parent model\n"
104 "\tmodelB: the child model\n"
105 "\tframeInModelA: index of the frame of modelA where to append modelB\n"
106 "\taMb: pose of modelB universe joint (index 0) in frameInModelA\n");
107
108
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 bp::def(
109 "appendModel", &appendModel_proxy<double, 0, JointCollectionDefaultTpl>,
110 40 bp::args("modelA", "modelB", "geomModelA", "geomModelB", "frame_in_modelA", "aMb"),
111 "Append a child (geometry) model into a parent (geometry) model, after a specific "
112 "frame given by its index.\n\n"
113 "Parameters:\n"
114 "\tmodelA: the parent model\n"
115 "\tmodelB: the child model\n"
116 "\tgeomModelA: the parent geometry model\n"
117 "\tgeomModelB: the child geometry model\n"
118 "\tframeInModelA: index of the frame of modelA where to append modelB\n"
119 "\taMb: pose of modelB universe joint (index 0) in frameInModelA\n");
120
121
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 bp::def(
122 "buildReducedModel",
123 (Model(*)(
124 const Model &, const std::vector<JointIndex> &, const Eigen::MatrixBase<VectorXd> &))
125 & pinocchio::buildReducedModel<double, 0, JointCollectionDefaultTpl, VectorXd>,
126 40 bp::args("model", "list_of_joints_to_lock", "reference_configuration"),
127 "Build a reduce model from a given input model and a list of joint to lock.\n\n"
128 "Parameters:\n"
129 "\tmodel: input kinematic modell to reduce\n"
130 "\tlist_of_joints_to_lock: list of joint indexes to lock\n"
131 "\treference_configuration: reference configuration to compute the placement of the "
132 "lock joints\n");
133
134
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 bp::def(
135 "buildReducedModel",
136 (bp::tuple(*)(
137 const Model &, const GeometryModel &, const std::vector<JointIndex> &,
138 const Eigen::MatrixBase<VectorXd> &))
139 & buildReducedModel<double, 0, JointCollectionDefaultTpl, VectorXd>,
140 40 bp::args("model", "geom_model", "list_of_joints_to_lock", "reference_configuration"),
141 "Build a reduced model and a reduced geometry model from a given input model,"
142 "an input geometry model and a list of joints to lock.\n\n"
143 "Parameters:\n"
144 "\tmodel: input kinematic model to reduce\n"
145 "\tgeom_model: input geometry model to reduce\n"
146 "\tlist_of_joints_to_lock: list of joint indexes to lock\n"
147 "\treference_configuration: reference configuration to compute the placement of the "
148 "locked joints\n");
149
150
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 bp::def(
151 "buildReducedModel",
152 (bp::tuple(*)(
153 const Model &,
154 const std::vector<GeometryModel, Eigen::aligned_allocator<GeometryModel>> &,
155 const std::vector<JointIndex> &, const Eigen::MatrixBase<VectorXd> &))
156 buildReducedModel<double, 0, JointCollectionDefaultTpl, VectorXd>,
157 40 bp::args(
158 "model", "list_of_geom_models", "list_of_joints_to_lock", "reference_configuration"),
159 "Build a reduced model and the related reduced geometry models from a given "
160 "input model,"
161 "a list of input geometry models and a list of joints to lock.\n\n"
162 "Parameters:\n"
163 "\tmodel: input kinematic model to reduce\n"
164 "\tlist_of_geom_models: input geometry models to reduce\n"
165 "\tlist_of_joints_to_lock: list of joint indexes to lock\n"
166 "\treference_configuration: reference configuration to compute the "
167 "placement of the locked joints\n");
168
169
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 bp::def(
170 40 "findCommonAncestor", findCommonAncestor_proxy, bp::args("model", "joint1_id", "joint2_id"),
171 "Computes the common ancestor between two joints belonging to the same kinematic tree.\n\n"
172 "Parameters:\n"
173 "\tmodel: input model\n"
174 "\tjoint1_id: index of the first joint\n"
175 "\tjoint2_id: index of the second joint\n"
176 "Returns a tuple containing the index of the common joint ancestor, the position of this "
177 "ancestor in model.supports[joint1_id] and model.supports[joint2_id].\n");
178 20 }
179
180 } // namespace python
181 } // namespace pinocchio
182