GCC Code Coverage Report


Directory: ./
File: include/pinocchio/parsers/urdf/geometry.hxx
Date: 2024-08-27 18:20:05
Exec Total Coverage
Lines: 12 19 63.2%
Branches: 5 30 16.7%

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