31 #include <boost/algorithm/string/classification.hpp>
32 #include <boost/algorithm/string/split.hpp>
33 #include <Eigen/Geometry>
46 std::vector<tesseract_geometry::SDFMesh::Ptr>
parseSDFMesh(
const tinyxml2::XMLElement* xml_element,
50 std::vector<tesseract_geometry::SDFMesh::Ptr> meshes;
54 std::throw_with_nested(std::runtime_error(
"SDFMesh: Missing or failed parsing attribute 'filename'!"));
56 std::string scale_string;
57 Eigen::Vector3d scale(1, 1, 1);
60 std::vector<std::string> tokens;
61 boost::split(tokens, scale_string, boost::is_any_of(
" "), boost::token_compress_on);
63 std::throw_with_nested(std::runtime_error(
"SDFMesh: Failed parsing attribute 'scale'!"));
65 double sx{ 0 }, sy{ 0 }, sz{ 0 };
72 std::throw_with_nested(std::runtime_error(
"SDFMesh: Scale x is not greater than zero!"));
75 std::throw_with_nested(std::runtime_error(
"SDFMesh: Scale y is not greater than zero!"));
78 std::throw_with_nested(std::runtime_error(
"SDFMesh: Scale z is not greater than zero!"));
80 scale = Eigen::Vector3d(sx, sy, sz);
84 meshes = tesseract_geometry::createMeshFromResource<tesseract_geometry::SDFMesh>(
85 locator.
locateResource(filename), scale,
true,
true,
true,
true,
true);
87 meshes = tesseract_geometry::createMeshFromResource<tesseract_geometry::SDFMesh>(
91 std::throw_with_nested(std::runtime_error(
"SDFMesh: Error importing meshes from filename: '" + filename +
"'!"));
96 tinyxml2::XMLElement*
writeSDFMesh(
const std::shared_ptr<const tesseract_geometry::SDFMesh>& sdf_mesh,
97 tinyxml2::XMLDocument& doc,
98 const std::string& package_path,
99 const std::string& filename)
101 if (sdf_mesh ==
nullptr)
102 std::throw_with_nested(std::runtime_error(
"SDF Mesh is nullptr and cannot be converted to XML"));
104 Eigen::IOFormat eigen_format(Eigen::StreamPrecision, Eigen::DontAlignCols,
" ",
" ");
112 std::throw_with_nested(std::runtime_error(
"Failed to write convex mesh to file: " + package_path + filename));
114 xml_element->SetAttribute(
"filename",
makeURDFFilePath(package_path, filename).c_str());
116 if (!sdf_mesh->getScale().isOnes())
118 std::stringstream scale_string;
119 scale_string << sdf_mesh->getScale().format(eigen_format);
120 xml_element->SetAttribute(
"scale", scale_string.str().c_str());