MCPcopy Create free account
hub / github.com/PlotJuggler/PlotJuggler / parseGeometry

Function parseGeometry

pj_scene3D/widgets/src/urdf_parser.cpp:71–119  ·  view source on GitHub ↗

Read into a GeomShape. Mesh refs are dispatched to the resolver. Returns false if no recognized child geometry is present.

Source from the content-addressed store, hash-verified

69// Read <geometry> into a GeomShape. Mesh refs are dispatched to the resolver.
70// Returns false if no recognized child geometry is present.
71bool parseGeometry(
72 const QDomElement& parent, UrdfPackageResolver* resolver, const std::string& urdf_dir, bool source_is_url,
73 GeomShape& out) {
74 const QDomElement geo = parent.firstChildElement(QStringLiteral("geometry"));
75 if (geo.isNull()) {
76 return false;
77 }
78
79 if (const QDomElement box = geo.firstChildElement(QStringLiteral("box")); !box.isNull()) {
80 GeomBox b;
81 std::array<double, 3> s{1, 1, 1};
82 if (parseDoubles(box.attribute(QStringLiteral("size")), s)) {
83 b.size = {s[0], s[1], s[2]};
84 }
85 out = b;
86 return true;
87 }
88 if (const QDomElement cyl = geo.firstChildElement(QStringLiteral("cylinder")); !cyl.isNull()) {
89 GeomCylinder c;
90 c.radius = attrDouble(cyl, QStringLiteral("radius"), 1.0);
91 c.length = attrDouble(cyl, QStringLiteral("length"), 1.0);
92 out = c;
93 return true;
94 }
95 if (const QDomElement sph = geo.firstChildElement(QStringLiteral("sphere")); !sph.isNull()) {
96 GeomSphere s;
97 s.radius = attrDouble(sph, QStringLiteral("radius"), 1.0);
98 out = s;
99 return true;
100 }
101 if (const QDomElement mesh = geo.firstChildElement(QStringLiteral("mesh")); !mesh.isNull()) {
102 GeomMesh m;
103 m.filename = mesh.attribute(QStringLiteral("filename")).toStdString();
104 std::array<double, 3> sc{1, 1, 1};
105 if (parseDoubles(mesh.attribute(QStringLiteral("scale")), sc)) {
106 m.scale = {sc[0], sc[1], sc[2]};
107 }
108 if (resolver != nullptr && !m.filename.empty()) {
109 const ResolvedMesh r = resolver->resolveUri(m.filename, urdf_dir, source_is_url);
110 m.resolved = r.resolved;
111 m.resolved_path = r.path;
112 m.issue = r.issue;
113 m.unresolved_package = r.package;
114 }
115 out = m;
116 return true;
117 }
118 return false;
119}
120
121// Read a <color rgba="r g b a"/> element into a vec4. Returns nullopt when the
122// element is null or "rgba" fails to parse; default {0.7,0.7,0.7,1.0} lives

Callers 1

parseGeomElementFunction · 0.85

Calls 5

parseDoublesFunction · 0.85
attrDoubleFunction · 0.85
resolveUriMethod · 0.80
isNullMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected