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


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