26#ifndef TESSERACT_GEOMETRY_OCTREE_H
27#define TESSERACT_GEOMETRY_OCTREE_H
31#include <boost/serialization/access.hpp>
32#include <boost/serialization/export.hpp>
33#include <Eigen/Geometry>
35#include <octomap/octomap.h>
45 using Ptr = std::shared_ptr<Octree>;
46 using ConstPtr = std::shared_ptr<const Octree>;
60 template <
typename Po
intT>
62 const double resolution,
65 const bool binary =
true)
68 auto ot = std::make_shared<octomap::OcTree>(resolution);
70 for (
auto& point : point_cloud.points)
71 ot->updateNode(point.x, point.y, point.z,
true,
true);
75 ot->updateInnerOccupancy();
78 ot->toMaxLikelihood();
120 double occupancy_threshold =
octree_->getOccupancyThres();
123 if (
it->getOccupancy() >= occupancy_threshold)
130 std::shared_ptr<const octomap::OcTree>
octree_;
138 if (!
octree.nodeChildExists(node, 0))
141 double occupancy_threshold =
octree.getOccupancyThres();
143 const octomap::OcTreeNode* firstChild =
octree.getNodeChild(node, 0);
144 if (
octree.nodeHasChildren(firstChild) || firstChild->getOccupancy() < occupancy_threshold)
147 for (
unsigned int i = 1; i < 8; i++)
151 if (!
octree.nodeChildExists(node, i))
154 if (
octree.nodeHasChildren(
octree.getNodeChild(node, i)))
157 if (
octree.getNodeChild(node, i)->getOccupancy() < occupancy_threshold)
170 node->copyData(*(
octree.getNodeChild(node, 0)));
173 for (
unsigned int i = 0; i < 8; i++)
175 octree.deleteNodeChild(node, i);
183 octomap::OcTreeNode* node,
185 unsigned int max_depth,
186 unsigned int& num_pruned)
190 if (depth < max_depth)
192 for (
unsigned int i = 0; i < 8; i++)
194 if (
octree.nodeChildExists(node, i))
212 template <
class Archive>
213 void save(Archive& ar,
const unsigned int version)
const;
215 template <
class Archive>
216 void load(Archive& ar,
const unsigned int version);
218 template <
class Archive>
219 void serialize(Archive& ar,
const unsigned int version);
232 if (
octree.getRoot() ==
nullptr)
235 for (
unsigned int depth =
octree.getTreeDepth() - 1; depth > 0; --depth)
237 unsigned int num_pruned = 0;
Definition: geometry.h:60
std::shared_ptr< Geometry > Ptr
Definition: geometry.h:62
bool getPruned() const
Definition: octree.h:98
double resolution_
Definition: octree.h:132
std::shared_ptr< const Octree > ConstPtr
Definition: octree.h:46
bool operator!=(const Octree &rhs) const
Definition: octree.cpp:74
void update()
Octrees are typically generated from 3D sensor data so this method should be used to efficiently upda...
Definition: octree.h:108
std::shared_ptr< Octree > Ptr
Definition: octree.h:45
static bool isNodeCollapsible(octomap::OcTree &octree, octomap::OcTreeNode *node)
Definition: octree.h:136
Geometry::Ptr clone() const override final
Create a copy of this shape.
Definition: octree.h:100
bool operator==(const Octree &rhs) const
Definition: octree.cpp:40
SubType
Definition: octree.h:49
@ BOX
Definition: octree.h:50
@ SPHERE_OUTSIDE
Definition: octree.h:52
@ SPHERE_INSIDE
Definition: octree.h:51
static void prune(octomap::OcTree &octree)
A custom octree prune which will prune if all children are above the occupancy threshold.
Definition: octree.h:230
void load(Archive &ar, const unsigned int version)
Definition: octree.cpp:101
static void pruneRecurs(octomap::OcTree &octree, octomap::OcTreeNode *node, unsigned int depth, unsigned int max_depth, unsigned int &num_pruned)
Definition: octree.h:182
SubType sub_type_
Definition: octree.h:131
Octree(std::shared_ptr< const octomap::OcTree > octree, const SubType sub_type)
Definition: octree.h:55
~Octree() override=default
bool binary_octree_
Definition: octree.h:134
friend class boost::serialization::access
Definition: octree.h:211
std::shared_ptr< const octomap::OcTree > octree_
Definition: octree.h:130
void serialize(Archive &ar, const unsigned int version)
Definition: octree.cpp:133
Octree(const PointT &point_cloud, const double resolution, const SubType sub_type, const bool prune, const bool binary=true)
Definition: octree.h:61
const std::shared_ptr< const octomap::OcTree > & getOctree() const
Definition: octree.h:94
void save(Archive &ar, const unsigned int version) const
Definition: octree.cpp:77
bool pruned_
Definition: octree.h:133
long calcNumSubShapes() const
Calculate the number of sub shapes that would get generated for this octree.
Definition: octree.h:117
static bool pruneNode(octomap::OcTree &octree, octomap::OcTreeNode *node)
Definition: octree.h:164
SubType getSubType() const
Definition: octree.h:96
auto it
Definition: collision_core_unit.cpp:208
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
Definition: macros.h:71
Definition: create_convex_hull.cpp:36
Definition: geometry.h:39
GeometryType
Definition: geometry.h:41
@ OCTREE
Definition: geometry.h:52
auto octree
Definition: tesseract_geometry_unit.cpp:27