octree_utils.h
Go to the documentation of this file.
1 
26 #ifndef TESSERACT_GEOMETRY_OCTREE_UTILS_H
27 #define TESSERACT_GEOMETRY_OCTREE_UTILS_H
28 
31 #include <octomap/OcTree.h>
32 #include <memory>
34 
36 
37 namespace tesseract_geometry
38 {
40 struct PointCloud
41 {
42  struct Point
43  {
44  Point() = default;
45  Point(double x_, double y_, double z_) : x(x_), y(y_), z(z_) {}
46 
47  double x;
48  double y;
49  double z;
50  };
51 
52  std::vector<Point> points;
53 
54  void addPoint(double x, double y, double z) { points.emplace_back(x, y, z); }
55 };
56 
57 template <typename PointT>
58 std::unique_ptr<octomap::OcTree>
59 createOctree(const PointT& point_cloud, const double resolution, const bool prune, const bool binary = true)
60 {
61  auto ot = std::make_unique<octomap::OcTree>(resolution);
62 
63  for (auto& point : point_cloud.points)
64  ot->updateNode(point.x, point.y, point.z, true, true);
65 
66  // Per the documentation for overload updateNode above with lazy_eval enabled this must be called after all points
67  // are added
68  ot->updateInnerOccupancy();
69  if (binary)
70  ot->toMaxLikelihood();
71 
72  if (prune)
74 
75  return ot;
76 }
77 } // namespace tesseract_geometry
78 #endif // TESSERACT_GEOMETRY_OCTREE_UTILS_H
tesseract_geometry::PointCloud::Point::y
double y
Definition: octree_utils.h:48
tesseract_geometry::PointCloud::Point::z
double z
Definition: octree_utils.h:49
tesseract_geometry::createOctree
std::unique_ptr< octomap::OcTree > createOctree(const PointT &point_cloud, const double resolution, const bool prune, const bool binary=true)
Definition: octree_utils.h:59
tesseract_geometry::PointCloud::addPoint
void addPoint(double x, double y, double z)
Definition: octree_utils.h:54
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
tesseract_geometry::PointCloud::Point
Definition: octree_utils.h:42
tesseract_geometry::PointCloud::Point::Point
Point()=default
tesseract_geometry::PointCloud
A basic point cloud structure to leverage instead of PCL.
Definition: octree_utils.h:40
TESSERACT_COMMON_IGNORE_WARNINGS_POP
#define TESSERACT_COMMON_IGNORE_WARNINGS_POP
tesseract_geometry
Definition: fwd.h:31
tesseract_geometry::Octree::prune
static void prune(octomap::OcTree &octree)
A custom octree prune which will prune if all children are above the occupancy threshold.
Definition: octree.cpp:144
tesseract_geometry::PointCloud::points
std::vector< Point > points
Definition: octree_utils.h:52
macros.h
octree.h
Tesseract Octree Geometry.
tesseract_geometry::PointCloud::Point::Point
Point(double x_, double y_, double z_)
Definition: octree_utils.h:45
tesseract_geometry::PointCloud::Point::x
double x
Definition: octree_utils.h:47


tesseract_geometry
Author(s): Levi Armstrong
autogenerated on Sun May 18 2025 03:01:46