44#include <octomap/octomap.h> 55 shared_ptr<const octomap::OcTree>
tree;
68 new octomap::
OcTree(resolution))) {
78 explicit OcTree(
const shared_ptr<const octomap::OcTree>& tree_)
100 shared_ptr<const octomap::OcTree>
getTree()
const {
return tree; }
106 typedef Eigen::Matrix<float, 3, 1> Vec3sloat;
107 Vec3sloat max_extent, min_extent;
109 octomap::OcTree::iterator it =
110 tree->begin((
unsigned char)
tree->getTreeDepth());
111 octomap::OcTree::iterator end =
tree->end();
113 if (it == end)
return;
116 const octomap::point3d& coord =
118 max_extent = min_extent = Eigen::Map<const Vec3sloat>(&coord.x());
119 for (++it; it != end; ++it) {
120 const octomap::point3d& coord = it.getCoordinate();
121 const Vec3sloat pos = Eigen::Map<const Vec3sloat>(&coord.x());
122 max_extent = max_extent.array().max(pos.array());
123 min_extent = min_extent.array().min(pos.array());
129 max_extent.array() += float(resolution / 2.);
130 min_extent.array() -= float(resolution / 2.);
143 return AABB(
Vec3s(-delta, -delta, -delta),
Vec3s(delta, delta, delta));
150 unsigned long size()
const {
return tree->size(); }
179 std::vector<Vec6s> boxes;
180 boxes.reserve(
tree->size() / 2);
181 for (octomap::OcTree::iterator
182 it =
tree->begin((
unsigned char)
tree->getTreeDepth()),
195 box << x, y, z,
size, c, t;
196 boxes.push_back(box);
204 typedef Eigen::Matrix<float, 3, 1> Vec3sloat;
205 const size_t total_size = (
tree->size() *
sizeof(
CoalScalar) * 3) / 2;
206 std::vector<uint8_t> bytes;
207 bytes.reserve(total_size);
209 for (octomap::OcTree::iterator
210 it =
tree->begin((
unsigned char)
tree->getTreeDepth()),
213 const Vec3s box_pos =
214 Eigen::Map<Vec3sloat>(&it.getCoordinate().x()).cast<
CoalScalar>();
216 std::copy(box_pos.data(), box_pos.data() +
sizeof(
CoalScalar) * 3,
217 std::back_inserter(bytes));
241 return tree->getNodeChild(node, childIdx);
246 unsigned int childIdx)
const {
247 return tree->getNodeChild(node, childIdx);
252 return tree->nodeChildExists(node, childIdx);
257 return tree->nodeHasChildren(node);
268 const OcTree* other_ptr =
dynamic_cast<const OcTree*
>(&_other);
269 if (other_ptr ==
nullptr)
return false;
270 const OcTree& other = *other_ptr;
272 return (tree.get() == other.
tree.get() || toBoxes() == other.
toBoxes()) &&
279 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
283static inline void computeChildBV(
const AABB& root_bv,
unsigned int i,
286 child_bv.min_[0] = (root_bv.min_[0] + root_bv.max_[0]) * 0.5;
287 child_bv.max_[0] = root_bv.max_[0];
289 child_bv.min_[0] = root_bv.min_[0];
290 child_bv.max_[0] = (root_bv.min_[0] + root_bv.max_[0]) * 0.5;
294 child_bv.min_[1] = (root_bv.min_[1] + root_bv.max_[1]) * 0.5;
295 child_bv.max_[1] = root_bv.max_[1];
297 child_bv.min_[1] = root_bv.min_[1];
298 child_bv.max_[1] = (root_bv.min_[1] + root_bv.max_[1]) * 0.5;
302 child_bv.min_[2] = (root_bv.min_[2] + root_bv.max_[2]) * 0.5;
303 child_bv.max_[2] = root_bv.max_[2];
305 child_bv.min_[2] = root_bv.min_[2];
306 child_bv.max_[2] = (root_bv.min_[2] + root_bv.max_[2]) * 0.5;
319makeOctree(
const Eigen::Matrix<CoalScalar, Eigen::Dynamic, 3>& point_cloud,
A class describing the AABB collision structure, which is a box in 3D space determined by two diagona...
Definition AABB.h:55
The geometry for the object for collision or distance computation.
Definition collision_object.h:94
Octree is one type of collision geometry which can encode uncertainty information in the sensor data.
Definition octree.h:53
CoalScalar getFreeThres() const
the threshold used to decide whether one node is free, this is NOT the octree free_threshold
Definition octree.h:229
OBJECT_TYPE getObjectType() const
return object type, it is an octree
Definition octree.h:261
std::vector< Vec6s > toBoxes() const
transform the octree into a bunch of boxes; uncertainty information is kept in the boxes....
Definition octree.h:178
bool nodeChildExists(const OcTreeNode *node, unsigned int childIdx) const
return true if the child at childIdx exists
Definition octree.h:251
AABB getRootBV() const
get the bounding volume for the root
Definition octree.h:139
OcTree(const OcTree &other)
 
Definition octree.h:89
void computeLocalAABB()
compute the AABB for the octree in its local coordinate system
Definition octree.h:105
void setFreeThres(CoalScalar d)
Definition octree.h:237
void exportAsObjFile(const std::string &filename) const
void setOccupancyThres(CoalScalar d)
Definition octree.h:235
OcTreeNode * getNodeChild(OcTreeNode *node, unsigned int childIdx)
Definition octree.h:240
CoalScalar getDefaultOccupancy() const
Definition octree.h:231
shared_ptr< const octomap::OcTree > getTree() const
Returns the tree associated to the underlying octomap OcTree.
Definition octree.h:100
shared_ptr< const octomap::OcTree > tree
Definition octree.h:55
OcTree * clone() const
Clone *this into a new Octree.
Definition octree.h:97
CoalScalar default_occupancy
Definition octree.h:57
OcTreeNode * getRoot() const
get the root node of the octree
Definition octree.h:156
OcTree(CoalScalar resolution)
construct octree with a given resolution
Definition octree.h:66
unsigned int getTreeDepth() const
Returns the depth of the octree.
Definition octree.h:147
void setCellDefaultOccupancy(CoalScalar d)
Definition octree.h:233
CoalScalar getOccupancyThres() const
the threshold used to decide whether one node is occupied, this is NOT the octree occupied_thresold
Definition octree.h:225
const OcTreeNode * getNodeChild(const OcTreeNode *node, unsigned int childIdx) const
Definition octree.h:245
bool nodeHasChildren(const OcTreeNode *node) const
return true if node has at least one child
Definition octree.h:256
bool isNodeUncertain(const OcTreeNode *node) const
whether one node is uncertain
Definition octree.h:171
OcTree(const shared_ptr< const octomap::OcTree > &tree_)
construct octree from octomap
Definition octree.h:78
unsigned long size() const
Returns the size of the octree.
Definition octree.h:150
CoalScalar getResolution() const
Returns the resolution of the octree.
Definition octree.h:153
CoalScalar free_threshold
Definition octree.h:60
octomap::OcTreeNode OcTreeNode
Definition octree.h:63
bool isNodeFree(const OcTreeNode *node) const
whether one node is completely free
Definition octree.h:165
CoalScalar occupancy_threshold
Definition octree.h:59
NODE_TYPE getNodeType() const
return node type, it is an octree
Definition octree.h:264
std::vector< uint8_t > tobytes() const
Returns a byte description of *this.
Definition octree.h:203
bool isNodeOccupied(const OcTreeNode *node) const
whether one node is completely occupied
Definition octree.h:159
AABB aabb_local
AABB in local coordinate, used for tight AABB when only translation transform.
Definition collision_object.h:158
@ GEOM_OCTREE
Definition collision_object.h:83
@ OT_OCTREE
Definition collision_object.h:56
Vec3s aabb_center
AABB center in local coordinate.
Definition collision_object.h:151
CollisionGeometry()
Definition collision_object.h:96
CoalScalar aabb_radius
AABB radius.
Definition collision_object.h:154
Main namespace.
Definition broadphase_bruteforce.h:44
Eigen::Matrix< CoalScalar, 6, 1 > Vec6s
Definition data_types.h:79
bool isEqual(const Eigen::MatrixBase< Derived > &lhs, const Eigen::MatrixBase< OtherDerived > &rhs, const CoalScalar tol=std::numeric_limits< CoalScalar >::epsilon() *100)
Definition tools.h:204
OcTreePtr_t makeOctree(const Eigen::Matrix< CoalScalar, Eigen::Dynamic, 3 > &point_cloud, const CoalScalar resolution)
Build an OcTree from a point cloud and a given resolution.
NODE_TYPE
traversal node type: bounding volume (AABB, OBB, RSS, kIOS, OBBRSS, KDOP16, KDOP18,...
Definition collision_object.h:64
shared_ptr< OcTree > OcTreePtr_t
Definition fwd.hh:145
OBJECT_TYPE
object type: BVH (mesh, points), basic geometry, octree
Definition collision_object.h:52
Eigen::Matrix< CoalScalar, 3, 1 > Vec3s
Definition data_types.h:77
double CoalScalar
Definition data_types.h:76