GCC Code Coverage Report


Directory: ./
File: include/pinocchio/parsers/urdf/geometry.hxx
Date: 2025-02-12 21:03:38
Exec Total Coverage
Lines: 17 20 85.0%
Branches: 9 30 30.0%

Line Branch Exec Source
1 //
2 // Copyright (c) 2015-2023 CNRS INRIA
3 //
4
5 #ifndef __pinocchio_multibody_parsers_urdf_geometry_hxx__
6 #define __pinocchio_multibody_parsers_urdf_geometry_hxx__
7
8 #include "pinocchio/parsers/config.hpp"
9 #include "pinocchio/parsers/urdf.hpp"
10
11 #include <sstream>
12
13 namespace pinocchio
14 {
15 namespace urdf
16 {
17 namespace details
18 {
19 struct UrdfGeomVisitorBase
20 {
21 typedef FrameTpl<urdf_scalar_type, 0> Frame;
22
23 virtual Frame getBodyFrame(const std::string & name, FrameIndex & fid) const = 0;
24 };
25
26 template<typename _Scalar, int _Options, template<typename, int> class JointCollectionTpl>
27 struct UrdfGeomVisitor : UrdfGeomVisitorBase
28 {
29 typedef ModelTpl<_Scalar, _Options, JointCollectionTpl> Model;
30 const Model & model;
31
32 76 UrdfGeomVisitor(const Model & model)
33 76 : model(model)
34 {
35 76 }
36
37 1498 Frame getBodyFrame(const std::string & link_name, FrameIndex & fid) const
38 {
39
2/4
✓ Branch 1 taken 1498 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1498 times.
1498 if (!model.existFrame(link_name, BODY))
40 {
41 throw std::invalid_argument("No link " + link_name + " in model");
42 }
43
1/2
✓ Branch 1 taken 1498 times.
✗ Branch 2 not taken.
1498 fid = model.getFrameId(link_name, BODY);
44
1/4
✗ Branch 1 not taken.
✓ Branch 2 taken 1498 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
1498 PINOCCHIO_CHECK_INPUT_ARGUMENT(model.frames[fid].type == BODY);
45 1498 return model.frames[fid].template cast<urdf_scalar_type>();
46 }
47 };
48
49 /**
50 * @brief Recursive procedure for reading the URDF tree, looking for geometries
51 * This function fill the geometric model whith geometry objects retrieved from
52 * the URDF tree
53 *
54 * @param[in] tree The URDF kinematic tree
55 * @param[in] meshLoader The FCL mesh loader to avoid duplications of already loaded
56 * geometries
57 * @param[in] link The current URDF link
58 * @param model The model to which is the GeometryModel associated
59 * @param geomModel The GeometryModel where the Collision Objects must be added
60 * @param[in] package_dirs A vector containing the different directories where to search
61 * for packages
62 * @param[in] type The type of objects that must be loaded ( can be VISUAL or
63 * COLLISION)
64 *
65 */
66 PINOCCHIO_PARSERS_DLLAPI void parseTreeForGeom(
67 UrdfGeomVisitorBase & visitor,
68 const std::istream & xmlStream,
69 const GeometryType type,
70 GeometryModel & geomModel,
71 const std::vector<std::string> & package_dirs,
72 ::hpp::fcl::MeshLoaderPtr meshLoader);
73
74 } // namespace details
75
76 template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl>
77 26 GeometryModel & buildGeom(
78 const ModelTpl<Scalar, Options, JointCollectionTpl> & model,
79 const std::string & filename,
80 const GeometryType type,
81 GeometryModel & geomModel,
82 const std::vector<std::string> & package_dirs,
83 ::hpp::fcl::MeshLoaderPtr meshLoader)
84 {
85
1/2
✓ Branch 2 taken 26 times.
✗ Branch 3 not taken.
26 std::ifstream xmlStream(filename.c_str());
86
2/4
✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 26 times.
26 if (!xmlStream.is_open())
87 {
88 const std::string exception_message(filename + " does not seem to be a valid file.");
89 throw std::invalid_argument(exception_message);
90 }
91
1/2
✓ Branch 2 taken 26 times.
✗ Branch 3 not taken.
52 return buildGeom(model, xmlStream, type, geomModel, package_dirs, meshLoader);
92 26 }
93
94 template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl>
95 76 GeometryModel & buildGeom(
96 const ModelTpl<Scalar, Options, JointCollectionTpl> & model,
97 const std::istream & xmlStream,
98 const GeometryType type,
99 GeometryModel & geomModel,
100 const std::vector<std::string> & package_dirs,
101 ::hpp::fcl::MeshLoaderPtr meshLoader)
102 {
103 76 details::UrdfGeomVisitor<Scalar, Options, JointCollectionTpl> visitor(model);
104
1/2
✓ Branch 2 taken 76 times.
✗ Branch 3 not taken.
76 details::parseTreeForGeom(visitor, xmlStream, type, geomModel, package_dirs, meshLoader);
105 76 return geomModel;
106 }
107
108 } // namespace urdf
109 } // namespace pinocchio
110
111 #endif // ifndef __pinocchio_multibody_parsers_urdf_geometry_hxx__
112