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


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