43 auto inertial = std::make_shared<tesseract_scene_graph::Inertial>();
44 const tinyxml2::XMLElement* origin = xml_element->FirstChildElement(
"origin");
45 if (origin !=
nullptr)
53 std::throw_with_nested(std::runtime_error(
"Inertial: Failed parsing element 'origin'!"));
57 const tinyxml2::XMLElement* mass = xml_element->FirstChildElement(
"mass");
59 std::throw_with_nested(std::runtime_error(
"Inertial: Missing element 'mass'!"));
61 if (mass->QueryDoubleAttribute(
"value", &(inertial->mass)) != tinyxml2::XML_SUCCESS)
62 std::throw_with_nested(std::runtime_error(
"Inertial: Missing or failed parsing 'mass' attribute 'value'!"));
64 const tinyxml2::XMLElement* inertia = xml_element->FirstChildElement(
"inertia");
65 if (inertia ==
nullptr)
66 std::throw_with_nested(std::runtime_error(
"Inertial: Missing element 'inertia'!"));
68 if (inertia->QueryDoubleAttribute(
"ixx", &(inertial->ixx)) != tinyxml2::XML_SUCCESS)
69 std::throw_with_nested(std::runtime_error(
"Inertial: Missing or failed parsing attribute 'ixx'!"));
71 if (inertia->QueryDoubleAttribute(
"ixy", &(inertial->ixy)) != tinyxml2::XML_SUCCESS)
72 std::throw_with_nested(std::runtime_error(
"Inertial: Missing or failed parsing attribute 'ixy'!"));
74 if (inertia->QueryDoubleAttribute(
"ixz", &(inertial->ixz)) != tinyxml2::XML_SUCCESS)
75 std::throw_with_nested(std::runtime_error(
"Inertial: Missing or failed parsing attribute 'ixz'!"));
77 if (inertia->QueryDoubleAttribute(
"iyy", &(inertial->iyy)) != tinyxml2::XML_SUCCESS)
78 std::throw_with_nested(std::runtime_error(
"Inertial: Missing or failed parsing attribute 'iyy'!"));
80 if (inertia->QueryDoubleAttribute(
"iyz", &(inertial->iyz)) != tinyxml2::XML_SUCCESS)
81 std::throw_with_nested(std::runtime_error(
"Inertial: Missing or failed parsing attribute 'iyz'!"));
83 if (inertia->QueryDoubleAttribute(
"izz", &(inertial->izz)) != tinyxml2::XML_SUCCESS)
84 std::throw_with_nested(std::runtime_error(
"Inertial: Missing or failed parsing attribute 'izz'!"));
89 tinyxml2::XMLElement*
writeInertial(
const std::shared_ptr<const tesseract_scene_graph::Inertial>& inertial,
90 tinyxml2::XMLDocument& doc)
92 if (inertial ==
nullptr)
93 std::throw_with_nested(std::runtime_error(
"Inertial is nullptr and cannot be converted to XML"));
96 if (!inertial->origin.matrix().isIdentity(std::numeric_limits<double>::epsilon()))
98 tinyxml2::XMLElement* xml_origin =
writeOrigin(inertial->origin, doc);
99 xml_element->InsertEndChild(xml_origin);
102 tinyxml2::XMLElement* xml_mass = doc.NewElement(
"mass");
103 xml_mass->SetAttribute(
"value",
toString(inertial->mass).c_str());
105 tinyxml2::XMLElement* xml_inertia = doc.NewElement(
"inertia");
106 xml_inertia->SetAttribute(
"ixx",
toString(inertial->ixx).c_str());
107 xml_inertia->SetAttribute(
"ixy",
toString(inertial->ixy).c_str());
108 xml_inertia->SetAttribute(
"ixz",
toString(inertial->ixz).c_str());
109 xml_inertia->SetAttribute(
"iyy",
toString(inertial->iyy).c_str());
110 xml_inertia->SetAttribute(
"iyz",
toString(inertial->iyz).c_str());
111 xml_inertia->SetAttribute(
"izz",
toString(inertial->izz).c_str());
113 xml_element->InsertEndChild(xml_mass);
114 xml_element->InsertEndChild(xml_inertia);