| Directory: | ./ |
|---|---|
| File: | include/pinocchio/algorithm/model.hpp |
| Date: | 2025-02-12 21:03:38 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 8 | 8 | 100.0% |
| Branches: | 3 | 6 | 50.0% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2019 CNRS INRIA | ||
| 3 | // | ||
| 4 | |||
| 5 | #ifndef __pinocchio_algorithm_model_hpp__ | ||
| 6 | #define __pinocchio_algorithm_model_hpp__ | ||
| 7 | |||
| 8 | #include "pinocchio/multibody/model.hpp" | ||
| 9 | #include "pinocchio/multibody/geometry.hpp" | ||
| 10 | |||
| 11 | namespace pinocchio | ||
| 12 | { | ||
| 13 | /** | ||
| 14 | * \brief Append a child model into a parent model, after a specific frame given by its index. | ||
| 15 | * | ||
| 16 | * \param[in] modelA the parent model. | ||
| 17 | * \param[in] modelB the child model. | ||
| 18 | * \param[in] frameInModelA index of the frame of modelA where to append modelB. | ||
| 19 | * \param[in] aMb pose of modelB universe joint (index 0) in frameInModelA. | ||
| 20 | * \param[out] model the resulting model. | ||
| 21 | * | ||
| 22 | * The order of the joints in the output models are | ||
| 23 | * - joints of modelA up to the parent of FrameInModelA, | ||
| 24 | * - all the descendents of parent of FrameInModelA, | ||
| 25 | * - the remaining joints of modelA. | ||
| 26 | */ | ||
| 27 | template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl> | ||
| 28 | void appendModel( | ||
| 29 | const ModelTpl<Scalar, Options, JointCollectionTpl> & modelA, | ||
| 30 | const ModelTpl<Scalar, Options, JointCollectionTpl> & modelB, | ||
| 31 | const FrameIndex frameInModelA, | ||
| 32 | const SE3Tpl<Scalar, Options> & aMb, | ||
| 33 | ModelTpl<Scalar, Options, JointCollectionTpl> & model); | ||
| 34 | |||
| 35 | /** | ||
| 36 | * \brief Append a child model into a parent model, after a specific frame given by its index. | ||
| 37 | * | ||
| 38 | * \param[in] modelA the parent model. | ||
| 39 | * \param[in] modelB the child model. | ||
| 40 | * \param[in] frameInModelA index of the frame of modelA where to append modelB. | ||
| 41 | * \param[in] aMb pose of modelB universe joint (index 0) in frameInModelA. | ||
| 42 | * | ||
| 43 | * \return A new model containing the fusion of modelA and modelB. | ||
| 44 | * | ||
| 45 | * The order of the joints in the output models are | ||
| 46 | * - joints of modelA up to the parent of FrameInModelA, | ||
| 47 | * - all the descendents of parent of FrameInModelA, | ||
| 48 | * - the remaining joints of modelA. | ||
| 49 | */ | ||
| 50 | template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl> | ||
| 51 | 2 | ModelTpl<Scalar, Options, JointCollectionTpl> appendModel( | |
| 52 | const ModelTpl<Scalar, Options, JointCollectionTpl> & modelA, | ||
| 53 | const ModelTpl<Scalar, Options, JointCollectionTpl> & modelB, | ||
| 54 | const FrameIndex frameInModelA, | ||
| 55 | const SE3Tpl<Scalar, Options> & aMb) | ||
| 56 | { | ||
| 57 | typedef ModelTpl<Scalar, Options, JointCollectionTpl> Model; | ||
| 58 | 2 | Model model; | |
| 59 | |||
| 60 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | appendModel(modelA, modelB, frameInModelA, aMb, model); |
| 61 | |||
| 62 | 2 | return model; | |
| 63 | } | ||
| 64 | |||
| 65 | /** | ||
| 66 | * \brief Append a child model into a parent model, after a specific frame given by its index. | ||
| 67 | * | ||
| 68 | * \param[in] modelA the parent model. | ||
| 69 | * \param[in] modelB the child model. | ||
| 70 | * \param[in] geomModelA the parent geometry model. | ||
| 71 | * \param[in] geomModelB the child geometry model. | ||
| 72 | * \param[in] frameInModelA index of the frame of modelA where to append modelB. | ||
| 73 | * \param[in] aMb pose of modelB universe joint (index 0) in frameInModelA. | ||
| 74 | * \param[out] model the resulting model. | ||
| 75 | * \param[out] geomModel the resulting geometry model. | ||
| 76 | */ | ||
| 77 | template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl> | ||
| 78 | void appendModel( | ||
| 79 | const ModelTpl<Scalar, Options, JointCollectionTpl> & modelA, | ||
| 80 | const ModelTpl<Scalar, Options, JointCollectionTpl> & modelB, | ||
| 81 | const GeometryModel & geomModelA, | ||
| 82 | const GeometryModel & geomModelB, | ||
| 83 | const FrameIndex frameInModelA, | ||
| 84 | const SE3Tpl<Scalar, Options> & aMb, | ||
| 85 | ModelTpl<Scalar, Options, JointCollectionTpl> & model, | ||
| 86 | GeometryModel & geomModel); | ||
| 87 | |||
| 88 | /** | ||
| 89 | * | ||
| 90 | * \brief Build a reduced model from a given input model and a list of joint to lock. | ||
| 91 | * | ||
| 92 | * \param[in] model the input model to reduce. | ||
| 93 | * \param[in] list_of_joints_to_lock list of joints to lock in the input model. | ||
| 94 | * \param[in] reference_configuration reference configuration. | ||
| 95 | * \param[out] reduced_model the reduced model. | ||
| 96 | * | ||
| 97 | * \remarks All the joints that have been set to be fixed in the new reduced_model now appear in | ||
| 98 | * the kinematic tree as a Frame as FIXED_JOINT. | ||
| 99 | * | ||
| 100 | * \todo At the moment, the joint and geometry order is kept while the frames | ||
| 101 | * are re-ordered in a hard to predict way. Their order could be kept. | ||
| 102 | * | ||
| 103 | */ | ||
| 104 | template< | ||
| 105 | typename Scalar, | ||
| 106 | int Options, | ||
| 107 | template<typename, int> class JointCollectionTpl, | ||
| 108 | typename ConfigVectorType> | ||
| 109 | void buildReducedModel( | ||
| 110 | const ModelTpl<Scalar, Options, JointCollectionTpl> & model, | ||
| 111 | std::vector<JointIndex> list_of_joints_to_lock, | ||
| 112 | const Eigen::MatrixBase<ConfigVectorType> & reference_configuration, | ||
| 113 | ModelTpl<Scalar, Options, JointCollectionTpl> & reduced_model); | ||
| 114 | |||
| 115 | /** | ||
| 116 | * | ||
| 117 | * \brief Build a reduced model from a given input model and a list of joint to lock. | ||
| 118 | * | ||
| 119 | * \param[in] model the input model to reduce. | ||
| 120 | * \param[in] list_of_joints_to_lock list of joints to lock in the input model. | ||
| 121 | * \param[in] reference_configuration reference configuration. | ||
| 122 | * | ||
| 123 | * \returns A reduce model of the input model. | ||
| 124 | * | ||
| 125 | * \remarks All the joints that have been set to be fixed in the new reduced_model now appear in | ||
| 126 | * the kinematic tree as a Frame as FIXED_JOINT. | ||
| 127 | * | ||
| 128 | */ | ||
| 129 | template< | ||
| 130 | typename Scalar, | ||
| 131 | int Options, | ||
| 132 | template<typename, int> class JointCollectionTpl, | ||
| 133 | typename ConfigVectorType> | ||
| 134 | 8 | ModelTpl<Scalar, Options, JointCollectionTpl> buildReducedModel( | |
| 135 | const ModelTpl<Scalar, Options, JointCollectionTpl> & model, | ||
| 136 | const std::vector<JointIndex> & list_of_joints_to_lock, | ||
| 137 | const Eigen::MatrixBase<ConfigVectorType> & reference_configuration) | ||
| 138 | { | ||
| 139 | typedef ModelTpl<Scalar, Options, JointCollectionTpl> Model; | ||
| 140 | 8 | Model reduced_model; | |
| 141 | |||
| 142 |
2/4✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
|
8 | buildReducedModel(model, list_of_joints_to_lock, reference_configuration, reduced_model); |
| 143 | |||
| 144 | 8 | return reduced_model; | |
| 145 | } | ||
| 146 | |||
| 147 | /** | ||
| 148 | * | ||
| 149 | * \brief Build a reduced model and a rededuced geometry model from a given input model, a given | ||
| 150 | * input geometry model and a list of joint to lock. | ||
| 151 | * | ||
| 152 | * \param[in] model the input model to reduce. | ||
| 153 | * \param[in] geom_model the input geometry model to reduce. | ||
| 154 | * \param[in] list_of_joints_to_lock list of joints to lock in the input model. | ||
| 155 | * \param[in] reference_configuration reference configuration. | ||
| 156 | * \param[out] reduced_model the reduced model. | ||
| 157 | * \param[out] reduced_geom_model the reduced geometry model. | ||
| 158 | * | ||
| 159 | * \remarks All the joints that have been set to be fixed in the new reduced_model now appear in | ||
| 160 | * the kinematic tree as a Frame as FIXED_JOINT. | ||
| 161 | * | ||
| 162 | */ | ||
| 163 | template< | ||
| 164 | typename Scalar, | ||
| 165 | int Options, | ||
| 166 | template<typename, int> class JointCollectionTpl, | ||
| 167 | typename ConfigVectorType> | ||
| 168 | void buildReducedModel( | ||
| 169 | const ModelTpl<Scalar, Options, JointCollectionTpl> & model, | ||
| 170 | const GeometryModel & geom_model, | ||
| 171 | const std::vector<JointIndex> & list_of_joints_to_lock, | ||
| 172 | const Eigen::MatrixBase<ConfigVectorType> & reference_configuration, | ||
| 173 | ModelTpl<Scalar, Options, JointCollectionTpl> & reduced_model, | ||
| 174 | GeometryModel & reduced_geom_model); | ||
| 175 | |||
| 176 | /** | ||
| 177 | * | ||
| 178 | * \brief Build a reduced model and a rededuced geometry model from a given input model, a given | ||
| 179 | * input geometry model and a list of joint to lock. | ||
| 180 | * | ||
| 181 | * \param[in] model the input model to reduce. | ||
| 182 | * \param[in] list_of_geom_models the input geometry model to reduce (example: visual_model, | ||
| 183 | * collision_model). \param[in] list_of_joints_to_lock list of joints to lock in the input model. | ||
| 184 | * \param[in] reference_configuration reference configuration. | ||
| 185 | * \param[out] reduced_model the reduced model. | ||
| 186 | * \param[out] list_of_reduced_geom_model the list of reduced geometry models. | ||
| 187 | * | ||
| 188 | * \remarks All the joints that have been set to be fixed in the new reduced_model now appear in | ||
| 189 | * the kinematic tree as a Frame as FIXED_JOINT. | ||
| 190 | * | ||
| 191 | */ | ||
| 192 | template< | ||
| 193 | typename Scalar, | ||
| 194 | int Options, | ||
| 195 | template<typename, int> class JointCollectionTpl, | ||
| 196 | typename GeometryModelAllocator, | ||
| 197 | typename ConfigVectorType> | ||
| 198 | void buildReducedModel( | ||
| 199 | const ModelTpl<Scalar, Options, JointCollectionTpl> & model, | ||
| 200 | const std::vector<GeometryModel, GeometryModelAllocator> & list_of_geom_models, | ||
| 201 | const std::vector<JointIndex> & list_of_joints_to_lock, | ||
| 202 | const Eigen::MatrixBase<ConfigVectorType> & reference_configuration, | ||
| 203 | ModelTpl<Scalar, Options, JointCollectionTpl> & reduced_model, | ||
| 204 | std::vector<GeometryModel, GeometryModelAllocator> & list_of_reduced_geom_models); | ||
| 205 | |||
| 206 | /** | ||
| 207 | * | ||
| 208 | * \brief Computes the common ancestor between two joints belonging to the same kinematic tree. | ||
| 209 | * | ||
| 210 | * \param[in] model the input model. | ||
| 211 | * \param[in] joint1_id index of the first joint. | ||
| 212 | * \param[in] joint2_id index of the second joint. | ||
| 213 | * \param[out] index_ancestor_in_support1 index of the ancestor within model.support[joint1_id]. | ||
| 214 | * \param[out] index_ancestor_in_support2 index of the ancestor within model.support[joint2_id]. | ||
| 215 | * | ||
| 216 | */ | ||
| 217 | template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl> | ||
| 218 | JointIndex findCommonAncestor( | ||
| 219 | const ModelTpl<Scalar, Options, JointCollectionTpl> & model, | ||
| 220 | JointIndex joint1_id, | ||
| 221 | JointIndex joint2_id, | ||
| 222 | size_t & index_ancestor_in_support1, | ||
| 223 | size_t & index_ancestor_in_support2); | ||
| 224 | |||
| 225 | } // namespace pinocchio | ||
| 226 | |||
| 227 | #include "pinocchio/algorithm/model.hxx" | ||
| 228 | |||
| 229 | #if PINOCCHIO_ENABLE_TEMPLATE_INSTANTIATION | ||
| 230 | #include "pinocchio/algorithm/model.txx" | ||
| 231 | #endif // PINOCCHIO_ENABLE_TEMPLATE_INSTANTIATION | ||
| 232 | |||
| 233 | #endif // ifndef __pinocchio_algorithm_model_hpp__ | ||
| 234 |