capsule.cpp
Go to the documentation of this file.
1 
29 #include <stdexcept>
30 
31 #include <tinyxml2.h>
33 
35 #include <tesseract_urdf/capsule.h>
36 #include <tesseract_urdf/utils.h>
37 
38 namespace tesseract_urdf
39 {
40 tesseract_geometry::Capsule::Ptr parseCapsule(const tinyxml2::XMLElement* xml_element)
41 {
42  double r{ 0 }, l{ 0 };
43  if (xml_element->QueryDoubleAttribute("length", &(l)) != tinyxml2::XML_SUCCESS || !(l > 0))
44  std::throw_with_nested(std::runtime_error("Capsule: Missing or failed parsing attribute 'length'!"));
45 
46  if (xml_element->QueryDoubleAttribute("radius", &(r)) != tinyxml2::XML_SUCCESS || !(r > 0))
47  std::throw_with_nested(std::runtime_error("Capsule: Missing or failed parsing attribute 'radius'!"));
48 
49  return std::make_shared<tesseract_geometry::Capsule>(r, l);
50 }
51 
52 tinyxml2::XMLElement* writeCapsule(const std::shared_ptr<const tesseract_geometry::Capsule>& capsule,
53  tinyxml2::XMLDocument& doc)
54 {
55  if (capsule == nullptr)
56  std::throw_with_nested(std::runtime_error("Capsule is nullptr and cannot be written to XML file"));
57  tinyxml2::XMLElement* xml_element = doc.NewElement(CAPSULE_ELEMENT_NAME.data());
58  xml_element->SetAttribute("length", toString(capsule->getLength()).c_str());
59  xml_element->SetAttribute("radius", toString(capsule->getRadius()).c_str());
60  return xml_element;
61 }
62 
63 } // namespace tesseract_urdf
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
utils.h
r
S r
TESSERACT_COMMON_IGNORE_WARNINGS_POP
tesseract_urdf::toString
std::string toString(const double &float_value, int precision=3)
Definition: utils.cpp:12
tesseract_urdf::CAPSULE_ELEMENT_NAME
static constexpr std::string_view CAPSULE_ELEMENT_NAME
Definition: capsule.h:45
tesseract_urdf::parseCapsule
std::shared_ptr< tesseract_geometry::Capsule > parseCapsule(const tinyxml2::XMLElement *xml_element)
Parse a xml capsule element.
Definition: capsule.cpp:40
capsule.h
Parse capsule from xml string.
tesseract_geometry::Capsule::Ptr
std::shared_ptr< Capsule > Ptr
capsule.h
macros.h
tesseract_urdf
Definition: box.h:43
tesseract_urdf::writeCapsule
tinyxml2::XMLElement * writeCapsule(const std::shared_ptr< const tesseract_geometry::Capsule > &capsule, tinyxml2::XMLDocument &doc)
Definition: capsule.cpp:52


tesseract_urdf
Author(s): Levi Armstrong
autogenerated on Thu Apr 24 2025 03:10:44