|
7 | 7 |
|
8 | 8 | #include "pinocchio/parsers/mjcf.hpp" |
9 | 9 | #include "pinocchio/parsers/mjcf/mjcf-graph.hpp" |
| 10 | +#include "pinocchio/multibody/model.hpp" |
| 11 | +#include "pinocchio/algorithm/contact-info.hpp" |
10 | 12 |
|
11 | 13 | namespace pinocchio |
12 | 14 | { |
@@ -37,12 +39,46 @@ namespace pinocchio |
37 | 39 |
|
38 | 40 | graph.parseGraphFromXML(xmlStr); |
39 | 41 |
|
40 | | - // // Use the Mjcf graph to create the model |
| 42 | + // Use the Mjcf graph to create the model |
41 | 43 | graph.parseRootTree(); |
42 | 44 |
|
43 | 45 | return model; |
44 | 46 | } |
45 | 47 |
|
| 48 | + template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl> |
| 49 | + ModelTpl<Scalar, Options, JointCollectionTpl> & buildModel( |
| 50 | + const std::string & filename, |
| 51 | + ModelTpl<Scalar, Options, JointCollectionTpl> & model, |
| 52 | + PINOCCHIO_STD_VECTOR_WITH_EIGEN_ALLOCATOR(RigidConstraintModel) & contact_models, |
| 53 | + const bool verbose) |
| 54 | + { |
| 55 | + return buildModelFromXML(filename, model, contact_models, verbose); |
| 56 | + } |
| 57 | + |
| 58 | + template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl> |
| 59 | + ModelTpl<Scalar, Options, JointCollectionTpl> & buildModelFromXML( |
| 60 | + const std::string & xmlStr, |
| 61 | + ModelTpl<Scalar, Options, JointCollectionTpl> & model, |
| 62 | + PINOCCHIO_STD_VECTOR_WITH_EIGEN_ALLOCATOR(RigidConstraintModel) & contact_models, |
| 63 | + const bool verbose) |
| 64 | + { |
| 65 | + ::pinocchio::urdf::details::UrdfVisitor<Scalar, Options, JointCollectionTpl> visitor(model); |
| 66 | + |
| 67 | + typedef ::pinocchio::mjcf::details::MjcfGraph MjcfGraph; |
| 68 | + |
| 69 | + MjcfGraph graph(visitor, xmlStr); |
| 70 | + if (verbose) |
| 71 | + visitor.log = &std::cout; |
| 72 | + |
| 73 | + graph.parseGraphFromXML(xmlStr); |
| 74 | + |
| 75 | + // Use the Mjcf graph to create the model |
| 76 | + graph.parseRootTree(); |
| 77 | + graph.parseContactInformation(model, contact_models); |
| 78 | + |
| 79 | + return model; |
| 80 | + } |
| 81 | + |
46 | 82 | template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl> |
47 | 83 | ModelTpl<Scalar, Options, JointCollectionTpl> & buildModel( |
48 | 84 | const std::string & filename, |
@@ -71,8 +107,45 @@ namespace pinocchio |
71 | 107 |
|
72 | 108 | graph.parseGraphFromXML(xmlStr); |
73 | 109 |
|
74 | | - // // Use the Mjcf graph to create the model |
| 110 | + // Use the Mjcf graph to create the model |
| 111 | + graph.parseRootTree(); |
| 112 | + |
| 113 | + return model; |
| 114 | + } |
| 115 | + |
| 116 | + template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl> |
| 117 | + ModelTpl<Scalar, Options, JointCollectionTpl> & buildModel( |
| 118 | + const std::string & filename, |
| 119 | + const typename ModelTpl<Scalar, Options, JointCollectionTpl>::JointModel & rootJoint, |
| 120 | + ModelTpl<Scalar, Options, JointCollectionTpl> & model, |
| 121 | + PINOCCHIO_STD_VECTOR_WITH_EIGEN_ALLOCATOR(RigidConstraintModel) & contact_models, |
| 122 | + const bool verbose) |
| 123 | + { |
| 124 | + return buildModelFromXML(filename, rootJoint, model, contact_models, verbose); |
| 125 | + } |
| 126 | + |
| 127 | + template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl> |
| 128 | + ModelTpl<Scalar, Options, JointCollectionTpl> & buildModelFromXML( |
| 129 | + const std::string & xmlStr, |
| 130 | + const typename ModelTpl<Scalar, Options, JointCollectionTpl>::JointModel & rootJoint, |
| 131 | + ModelTpl<Scalar, Options, JointCollectionTpl> & model, |
| 132 | + PINOCCHIO_STD_VECTOR_WITH_EIGEN_ALLOCATOR(RigidConstraintModel) & contact_models, |
| 133 | + const bool verbose) |
| 134 | + { |
| 135 | + ::pinocchio::urdf::details::UrdfVisitorWithRootJoint<Scalar, Options, JointCollectionTpl> |
| 136 | + visitor(model, rootJoint); |
| 137 | + |
| 138 | + typedef ::pinocchio::mjcf::details::MjcfGraph MjcfGraph; |
| 139 | + |
| 140 | + MjcfGraph graph(visitor, xmlStr); |
| 141 | + if (verbose) |
| 142 | + visitor.log = &std::cout; |
| 143 | + |
| 144 | + graph.parseGraphFromXML(xmlStr); |
| 145 | + |
| 146 | + // Use the Mjcf graph to create the model |
75 | 147 | graph.parseRootTree(); |
| 148 | + graph.parseContactInformation(model, contact_models); |
76 | 149 |
|
77 | 150 | return model; |
78 | 151 | } |
|
0 commit comments