point_cloud.cpp
Go to the documentation of this file.
1 
29 #include <stdexcept>
30 
31 #include <console_bridge/console.h>
32 #include <pcl/io/pcd_io.h>
33 #include <tesseract_common/utils.h>
34 #include <tinyxml2.h>
35 #include <octomap/OcTree.h>
37 
42 
43 namespace tesseract_urdf
44 {
45 tesseract_geometry::Octree::Ptr parsePointCloud(const tinyxml2::XMLElement* xml_element,
46  const tesseract_common::ResourceLocator& locator,
48  bool prune)
49 {
50  std::string filename;
51  if (tesseract_common::QueryStringAttribute(xml_element, "filename", filename) != tinyxml2::XML_SUCCESS)
52  std::throw_with_nested(std::runtime_error("PointCloud: Missing or failed parsing attribute 'filename'!"));
53 
54  double resolution{ 0 };
55  if (xml_element->QueryDoubleAttribute("resolution", &resolution) != tinyxml2::XML_SUCCESS)
56  std::throw_with_nested(std::runtime_error("PointCloud: Missing or failed parsing point_cloud attribute "
57  "'resolution'!"));
58 
59  auto cloud = std::make_shared<pcl::PointCloud<pcl::PointXYZ>>();
60 
61  tesseract_common::Resource::Ptr located_resource = locator.locateResource(filename);
62  if (!located_resource || !located_resource->isFile() || !std::filesystem::exists(located_resource->getFilePath()))
63  {
64  // TODO: Handle point clouds that are not files
65  CONSOLE_BRIDGE_logError("Point clouds can only be loaded from file");
66  std::throw_with_nested(std::runtime_error("PointCloud: Unable to locate resource '" + filename + "'!"));
67  }
68 
69  if (pcl::io::loadPCDFile<pcl::PointXYZ>(located_resource->getFilePath(), *cloud) == -1)
70  std::throw_with_nested(std::runtime_error("PointCloud: Failed to import point cloud from '" + filename + "'!"));
71 
72  if (cloud->points.empty())
73  std::throw_with_nested(std::runtime_error("PointCloud: Imported point cloud from '" + filename + "' is empty!"));
74 
75  auto octree = tesseract_geometry::createOctree(*cloud, resolution, prune);
76  auto geom = std::make_shared<tesseract_geometry::Octree>(std::move(octree), shape_type, prune);
77  if (geom == nullptr)
78  std::throw_with_nested(std::runtime_error("PointCloud: Failed to create Tesseract Octree Geometry from point "
79  "cloud!"));
80 
81  return geom;
82 }
83 
84 } // namespace tesseract_urdf
utils.h
resource_locator.h
point_cloud.h
Parse PCL point cloud to octree from xml string.
tesseract_common::ResourceLocator::locateResource
virtual std::shared_ptr< Resource > locateResource(const std::string &url) const=0
tesseract_geometry::createOctree
std::unique_ptr< octomap::OcTree > createOctree(const PointT &point_cloud, const double resolution, const bool prune, const bool binary=true)
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
OcTree.h
tesseract_common::ResourceLocator
tesseract_urdf::parsePointCloud
std::shared_ptr< tesseract_geometry::Octree > parsePointCloud(const tinyxml2::XMLElement *xml_element, const tesseract_common::ResourceLocator &locator, tesseract_geometry::OctreeSubType shape_type, bool prune)
Parse xml element point_cloud.
Definition: point_cloud.cpp:45
tesseract_common::QueryStringAttribute
int QueryStringAttribute(const tinyxml2::XMLElement *xml_element, const char *name, std::string &value)
TESSERACT_COMMON_IGNORE_WARNINGS_POP
tesseract_geometry::Octree::Ptr
std::shared_ptr< Octree > Ptr
octree_utils.h
octree.h
tesseract_common::Resource::Ptr
std::shared_ptr< Resource > Ptr
macros.h
tesseract_urdf
Definition: box.h:43
tesseract_geometry::OctreeSubType
OctreeSubType


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