| Directory: | ./ |
|---|---|
| File: | bindings/python/algorithm/expose-model.cpp |
| Date: | 2025-04-30 16:14:33 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 35 | 43 | 81.4% |
| Branches: | 22 | 50 | 44.0% |
| 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> class JointCollectionTpl, | ||
| 38 | typename ConfigVectorType> | ||
| 39 | 1 | bp::tuple buildReducedModel( | |
| 40 | const ModelTpl<Scalar, Options, JointCollectionTpl> & model, | ||
| 41 | const GeometryModel & geom_model, | ||
| 42 | const std::vector<JointIndex> & list_of_joints_to_lock, | ||
| 43 | const Eigen::MatrixBase<ConfigVectorType> & reference_configuration) | ||
| 44 | { | ||
| 45 | typedef ModelTpl<Scalar, Options, JointCollectionTpl> Model; | ||
| 46 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | Model reduced_model; |
| 47 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | GeometryModel reduced_geom_model; |
| 48 | |||
| 49 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | buildReducedModel( |
| 50 | model, geom_model, list_of_joints_to_lock, reference_configuration, reduced_model, | ||
| 51 | reduced_geom_model); | ||
| 52 | |||
| 53 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return bp::make_tuple(reduced_model, reduced_geom_model); |
| 54 | 1 | } | |
| 55 | |||
| 56 | template< | ||
| 57 | typename Scalar, | ||
| 58 | int Options, | ||
| 59 | template<typename, int> class JointCollectionTpl, | ||
| 60 | typename ConfigVectorType> | ||
| 61 | 2 | bp::tuple buildReducedModel( | |
| 62 | const ModelTpl<Scalar, Options, JointCollectionTpl> & model, | ||
| 63 | const std::vector<GeometryModel, Eigen::aligned_allocator<GeometryModel>> & | ||
| 64 | list_of_geom_models, | ||
| 65 | const std::vector<JointIndex> & list_of_joints_to_lock, | ||
| 66 | const Eigen::MatrixBase<ConfigVectorType> & reference_configuration) | ||
| 67 | { | ||
| 68 | typedef ModelTpl<Scalar, Options, JointCollectionTpl> Model; | ||
| 69 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | std::vector<GeometryModel, Eigen::aligned_allocator<GeometryModel>> reduced_geom_models; |
| 70 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | Model reduced_model; |
| 71 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | buildReducedModel( |
| 72 | model, list_of_geom_models, list_of_joints_to_lock, reference_configuration, reduced_model, | ||
| 73 | reduced_geom_models); | ||
| 74 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
4 | return bp::make_tuple(reduced_model, reduced_geom_models); |
| 75 | 2 | } | |
| 76 | |||
| 77 | ✗ | bp::tuple findCommonAncestor_proxy( | |
| 78 | const context::Model & model, const JointIndex joint1_id, const JointIndex joint2_id) | ||
| 79 | { | ||
| 80 | size_t index_ancestor_in_support1, index_ancestor_in_support2; | ||
| 81 | ✗ | JointIndex ancestor_id = findCommonAncestor( | |
| 82 | ✗ | model, joint1_id, joint2_id, index_ancestor_in_support1, index_ancestor_in_support2); | |
| 83 | ✗ | return bp::make_tuple(ancestor_id, index_ancestor_in_support1, index_ancestor_in_support2); | |
| 84 | } | ||
| 85 | |||
| 86 | template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl> | ||
| 87 | ✗ | ModelTpl<Scalar, Options, JointCollectionTpl> transformJointIntoMimic_proxy( | |
| 88 | const ModelTpl<Scalar, Options, JointCollectionTpl> & input_model, | ||
| 89 | const JointIndex & index_mimicked, | ||
| 90 | const JointIndex & index_mimicking, | ||
| 91 | const Scalar & scaling, | ||
| 92 | const Scalar & offset) | ||
| 93 | { | ||
| 94 | typedef ModelTpl<Scalar, Options, JointCollectionTpl> Model; | ||
| 95 | |||
| 96 | ✗ | Model model; | |
| 97 | ✗ | pinocchio::transformJointIntoMimic( | |
| 98 | input_model, index_mimicked, index_mimicking, scaling, offset, model); | ||
| 99 | ✗ | return model; | |
| 100 | } | ||
| 101 | |||
| 102 | 72 | void exposeModelAlgo() | |
| 103 | { | ||
| 104 | using namespace Eigen; | ||
| 105 | |||
| 106 | typedef std::vector<GeometryModel, Eigen::aligned_allocator<GeometryModel>> | ||
| 107 | GeometryModelVector; | ||
| 108 |
3/6✓ Branch 2 taken 72 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 72 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 72 times.
✗ Branch 10 not taken.
|
72 | StdVectorPythonVisitor<GeometryModelVector>::expose("StdVec_GeometryModel"); |
| 109 | |||
| 110 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | bp::def( |
| 111 | "appendModel", | ||
| 112 | (Model(*)( | ||
| 113 | const Model &, const Model &, const FrameIndex, | ||
| 114 | const SE3 &))&appendModel<double, 0, JointCollectionDefaultTpl>, | ||
| 115 | 144 | bp::args("modelA", "modelB", "frame_in_modelA", "aMb"), | |
| 116 | "Append a child model into a parent model, after a specific frame given by its index.\n\n" | ||
| 117 | "Parameters:\n" | ||
| 118 | "\tmodelA: the parent model\n" | ||
| 119 | "\tmodelB: the child model\n" | ||
| 120 | "\tframeInModelA: index of the frame of modelA where to append modelB\n" | ||
| 121 | "\taMb: pose of modelB universe joint (index 0) in frameInModelA\n"); | ||
| 122 | |||
| 123 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | bp::def( |
| 124 | "appendModel", &appendModel_proxy<double, 0, JointCollectionDefaultTpl>, | ||
| 125 | 144 | bp::args("modelA", "modelB", "geomModelA", "geomModelB", "frame_in_modelA", "aMb"), | |
| 126 | "Append a child (geometry) model into a parent (geometry) model, after a specific " | ||
| 127 | "frame given by its index.\n\n" | ||
| 128 | "Parameters:\n" | ||
| 129 | "\tmodelA: the parent model\n" | ||
| 130 | "\tmodelB: the child model\n" | ||
| 131 | "\tgeomModelA: the parent geometry model\n" | ||
| 132 | "\tgeomModelB: the child geometry model\n" | ||
| 133 | "\tframeInModelA: index of the frame of modelA where to append modelB\n" | ||
| 134 | "\taMb: pose of modelB universe joint (index 0) in frameInModelA\n"); | ||
| 135 | |||
| 136 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | bp::def( |
| 137 | "buildReducedModel", | ||
| 138 | (Model(*)( | ||
| 139 | const Model &, const std::vector<JointIndex> &, | ||
| 140 | const Eigen::MatrixBase<VectorXd> &))&pinocchio:: | ||
| 141 | buildReducedModel<double, 0, JointCollectionDefaultTpl, VectorXd>, | ||
| 142 | 144 | bp::args("model", "list_of_joints_to_lock", "reference_configuration"), | |
| 143 | "Build a reduce model from a given input model and a list of joint to lock.\n\n" | ||
| 144 | "Parameters:\n" | ||
| 145 | "\tmodel: input kinematic modell 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 | "lock joints\n"); | ||
| 149 | |||
| 150 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | bp::def( |
| 151 | "buildReducedModel", | ||
| 152 | (bp::tuple(*)( | ||
| 153 | const Model &, const GeometryModel &, const std::vector<JointIndex> &, | ||
| 154 | const Eigen::MatrixBase< | ||
| 155 | VectorXd> &))&buildReducedModel<double, 0, JointCollectionDefaultTpl, VectorXd>, | ||
| 156 | 144 | bp::args("model", "geom_model", "list_of_joints_to_lock", "reference_configuration"), | |
| 157 | "Build a reduced model and a reduced geometry model from a given input model," | ||
| 158 | "an input geometry model and a list of joints to lock.\n\n" | ||
| 159 | "Parameters:\n" | ||
| 160 | "\tmodel: input kinematic model to reduce\n" | ||
| 161 | "\tgeom_model: input geometry model to reduce\n" | ||
| 162 | "\tlist_of_joints_to_lock: list of joint indexes to lock\n" | ||
| 163 | "\treference_configuration: reference configuration to compute the placement of the " | ||
| 164 | "locked joints\n"); | ||
| 165 | |||
| 166 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | bp::def( |
| 167 | "buildReducedModel", | ||
| 168 | (bp::tuple(*)( | ||
| 169 | const Model &, | ||
| 170 | const std::vector<GeometryModel, Eigen::aligned_allocator<GeometryModel>> &, | ||
| 171 | const std::vector<JointIndex> &, const Eigen::MatrixBase<VectorXd> &)) | ||
| 172 | buildReducedModel<double, 0, JointCollectionDefaultTpl, VectorXd>, | ||
| 173 | 144 | bp::args( | |
| 174 | "model", "list_of_geom_models", "list_of_joints_to_lock", "reference_configuration"), | ||
| 175 | "Build a reduced model and the related reduced geometry models from a given " | ||
| 176 | "input model," | ||
| 177 | "a list of input geometry models and a list of joints to lock.\n\n" | ||
| 178 | "Parameters:\n" | ||
| 179 | "\tmodel: input kinematic model to reduce\n" | ||
| 180 | "\tlist_of_geom_models: input geometry models to reduce\n" | ||
| 181 | "\tlist_of_joints_to_lock: list of joint indexes to lock\n" | ||
| 182 | "\treference_configuration: reference configuration to compute the " | ||
| 183 | "placement of the locked joints\n"); | ||
| 184 | |||
| 185 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | bp::def( |
| 186 | 144 | "findCommonAncestor", findCommonAncestor_proxy, bp::args("model", "joint1_id", "joint2_id"), | |
| 187 | "Computes the common ancestor between two joints belonging to the same kinematic tree.\n\n" | ||
| 188 | "Parameters:\n" | ||
| 189 | "\tmodel: input model\n" | ||
| 190 | "\tjoint1_id: index of the first joint\n" | ||
| 191 | "\tjoint2_id: index of the second joint\n" | ||
| 192 | "Returns a tuple containing the index of the common joint ancestor, the position of this " | ||
| 193 | "ancestor in model.supports[joint1_id] and model.supports[joint2_id].\n"); | ||
| 194 | |||
| 195 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | bp::def( |
| 196 | "transformJointIntoMimic", | ||
| 197 | transformJointIntoMimic_proxy<double, 0, JointCollectionDefaultTpl>, | ||
| 198 | 144 | bp::args("input_model", "index_mimicked", "index_mimicking", "scaling", "offset"), | |
| 199 | "Transform of a joint of the model into a mimic joint. Keep the type of the joint as it " | ||
| 200 | "was previously. \n\n" | ||
| 201 | "Parameters:\n" | ||
| 202 | "\tinput_model: model the input model to take joints from.\n" | ||
| 203 | "\tindex_mimicked: index of the joint to mimic\n" | ||
| 204 | "\tindex_mimicking: index of the joint that will mimic\n" | ||
| 205 | "\tscaling: Scaling of joint velocity and configuration\n" | ||
| 206 | "\toffset: Offset of joint configuration\n"); | ||
| 207 | 72 | } | |
| 208 | |||
| 209 | } // namespace python | ||
| 210 | } // namespace pinocchio | ||
| 211 |