Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle MultiSphere #128

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add multisphere
mpowelson committed May 20, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 57706f7e43f19ed530a2454fc47e8008e6817ff2
51 changes: 51 additions & 0 deletions urdf_parser/src/link.cpp
Original file line number Diff line number Diff line change
@@ -216,6 +216,35 @@ bool parseMesh(Mesh &m, TiXmlElement *c)
return true;
}

bool parseMultiSphere(MultiSphere &m, TiXmlElement *c)
{
m.clear();

m.type = Geometry::MULTISPHERE;
if (!c->Attribute("filename")) {
CONSOLE_BRIDGE_logError("Multi-sphere must contain a filename attribute");
return false;
}

m.filename = c->Attribute("filename");

if (c->Attribute("scale")) {
try {
m.scale.init(c->Attribute("scale"));
}
catch (ParseError &e) {
m.scale.clear();
CONSOLE_BRIDGE_logError("Multi-sphere scale was specified, but could not be parsed: %s", e.what());
return false;
}
}
else
{
m.scale.x = m.scale.y = m.scale.z = 1;
}
return true;
}

GeometrySharedPtr parseGeometry(TiXmlElement *g)
{
GeometrySharedPtr geom;
@@ -257,6 +286,13 @@ GeometrySharedPtr parseGeometry(TiXmlElement *g)
if (parseMesh(*m, shape))
return geom;
}
else if (type_name == "multisphere")
{
MultiSphere *m = new MultiSphere();
geom.reset(m);
if (parseMultiSphere(*m, shape))
return geom;
}
else
{
CONSOLE_BRIDGE_logError("Unknown geometry type '%s'", type_name.c_str());
@@ -544,6 +580,17 @@ bool exportMesh(Mesh &m, TiXmlElement *xml)
return true;
}

bool exportMultiSphere(MultiSphere &m, TiXmlElement *xml)
{
// e.g. add <multisphere filename="my_file" scale="1 1 1"/>
TiXmlElement *multisphere_xml = new TiXmlElement("multisphere");
if (!m.filename.empty())
multisphere_xml->SetAttribute("filename", m.filename);
multisphere_xml->SetAttribute("scale", urdf_export_helpers::values2str(m.scale));
xml->LinkEndChild(multisphere_xml);
return true;
}

bool exportGeometry(GeometrySharedPtr &geom, TiXmlElement *xml)
{
TiXmlElement *geometry_xml = new TiXmlElement("geometry");
@@ -563,6 +610,10 @@ bool exportGeometry(GeometrySharedPtr &geom, TiXmlElement *xml)
{
exportMesh((*(urdf::dynamic_pointer_cast<Mesh>(geom).get())), geometry_xml);
}
else if (urdf::dynamic_pointer_cast<MultiSphere>(geom))
{
exportMultiSphere((*(urdf::dynamic_pointer_cast<MultiSphere>(geom).get())), geometry_xml);
}
else
{
CONSOLE_BRIDGE_logError("geometry not specified, I'll make one up for you!");