cylinder.cpp
Go to the documentation of this file.
1 
29 #include <stdexcept>
30 
31 #include <tinyxml2.h>
33 
36 #include <tesseract_urdf/utils.h>
37 
38 namespace tesseract_urdf
39 {
40 tesseract_geometry::Cylinder::Ptr parseCylinder(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("Cylinder: 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("Cylinder: Missing or failed parsing attribute 'radius'!"));
48 
49  return std::make_shared<tesseract_geometry::Cylinder>(r, l);
50 }
51 
52 tinyxml2::XMLElement* writeCylinder(const std::shared_ptr<const tesseract_geometry::Cylinder>& cylinder,
53  tinyxml2::XMLDocument& doc)
54 {
55  if (cylinder == nullptr)
56  std::throw_with_nested(std::runtime_error("Cylinder is nullptr and cannot be converted to XML"));
57  tinyxml2::XMLElement* xml_element = doc.NewElement(CYLINDER_ELEMENT_NAME.data());
58  xml_element->SetAttribute("length", toString(cylinder->getLength()).c_str());
59  xml_element->SetAttribute("radius", toString(cylinder->getRadius()).c_str());
60  return xml_element;
61 }
62 
63 } // namespace tesseract_urdf
tesseract_geometry::Cylinder::Ptr
std::shared_ptr< Cylinder > Ptr
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
cylinder.h
utils.h
tesseract_urdf::writeCylinder
tinyxml2::XMLElement * writeCylinder(const std::shared_ptr< const tesseract_geometry::Cylinder > &cylinder, tinyxml2::XMLDocument &doc)
Definition: cylinder.cpp:52
tesseract_urdf::CYLINDER_ELEMENT_NAME
static constexpr std::string_view CYLINDER_ELEMENT_NAME
Definition: cylinder.h:45
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::parseCylinder
std::shared_ptr< tesseract_geometry::Cylinder > parseCylinder(const tinyxml2::XMLElement *xml_element)
Parse a xml cylinder element.
Definition: cylinder.cpp:40
macros.h
tesseract_urdf
Definition: box.h:43
cylinder.h
Parse cylinder from xml string.


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