38 #ifndef FCL_OCTREE_INL_H 39 #define FCL_OCTREE_INL_H 41 #include "fcl/geometry/octree/octree.h" 43 #include "fcl/config.h" 56 void computeChildBV(
const AABB<double>& root_bv,
unsigned int i, AABB<double>& child_bv);
60 OcTree<S>::OcTree(S resolution)
61 : tree(std::shared_ptr<const octomap::OcTree>(new octomap::OcTree(resolution)))
63 default_occupancy = tree->getOccupancyThres();
66 occupancy_threshold = tree->getOccupancyThres();
72 OcTree<S>::OcTree(
const std::shared_ptr<const octomap::OcTree>& tree_)
75 default_occupancy = tree->getOccupancyThres();
78 occupancy_threshold = tree->getOccupancyThres();
84 void OcTree<S>::computeLocalAABB()
86 this->aabb_local = getRootBV();
87 this->aabb_center = this->aabb_local.center();
88 this->aabb_radius = (this->aabb_local.min_ - this->aabb_center).norm();
93 AABB<S> OcTree<S>::getRootBV()
const 95 S delta = (1 << tree->getTreeDepth()) * tree->getResolution() / 2;
98 return AABB<S>(Vector3<S>(-delta, -delta, -delta), Vector3<S>(delta, delta, delta));
102 template <
typename S>
103 typename OcTree<S>::OcTreeNode* OcTree<S>::getRoot()
const 105 return tree->getRoot();
109 template <
typename S>
110 bool OcTree<S>::isNodeOccupied(
const OcTree<S>::OcTreeNode* node)
const 113 return node->getOccupancy() >= occupancy_threshold;
117 template <
typename S>
118 bool OcTree<S>::isNodeFree(
const OcTree<S>::OcTreeNode* node)
const 121 return node->getOccupancy() <= free_threshold;
125 template <
typename S>
126 bool OcTree<S>::isNodeUncertain(
const OcTree<S>::OcTreeNode* node)
const 128 return (!isNodeOccupied(node)) && (!isNodeFree(node));
132 template <
typename S>
133 S OcTree<S>::getOccupancyThres()
const 135 return occupancy_threshold;
139 template <
typename S>
140 S OcTree<S>::getFreeThres()
const 142 return free_threshold;
146 template <
typename S>
147 S OcTree<S>::getDefaultOccupancy()
const 149 return default_occupancy;
153 template <
typename S>
154 void OcTree<S>::setCellDefaultOccupancy(S d)
156 default_occupancy = d;
160 template <
typename S>
161 void OcTree<S>::setOccupancyThres(S d)
163 occupancy_threshold = d;
167 template <
typename S>
168 void OcTree<S>::setFreeThres(S d)
174 template <
typename S>
175 typename OcTree<S>::OcTreeNode* OcTree<S>::getNodeChild(
176 typename OcTree<S>::OcTreeNode* node,
unsigned int childIdx)
178 #if OCTOMAP_VERSION_AT_LEAST(1,8,0) 179 return tree->getNodeChild(node, childIdx);
181 return node->getChild(childIdx);
186 template <
typename S>
187 const typename OcTree<S>::OcTreeNode* OcTree<S>::getNodeChild(
188 const typename OcTree<S>::OcTreeNode* node,
unsigned int childIdx)
const 190 #if OCTOMAP_VERSION_AT_LEAST(1,8,0) 191 return tree->getNodeChild(node, childIdx);
193 return node->getChild(childIdx);
198 template <
typename S>
199 bool OcTree<S>::nodeChildExists(
200 const OcTree<S>::OcTreeNode* node,
unsigned int childIdx)
const 202 #if OCTOMAP_VERSION_AT_LEAST(1,8,0) 203 return tree->nodeChildExists(node, childIdx);
205 return node->childExists(childIdx);
210 template <
typename S>
211 bool OcTree<S>::nodeHasChildren(
const OcTree<S>::OcTreeNode* node)
const 213 #if OCTOMAP_VERSION_AT_LEAST(1,8,0) 214 return tree->nodeHasChildren(node);
216 return node->hasChildren();
221 template <
typename S>
228 template <
typename S>
235 template <
typename S>
236 std::vector<std::array<S, 6>> OcTree<S>::toBoxes()
const 238 std::vector<std::array<S, 6>> boxes;
239 boxes.reserve(tree->size() / 2);
240 for(
auto it = tree->begin(tree->getTreeDepth()), end = tree->end();
245 if(isNodeOccupied(&*it))
247 S size = it.getSize();
251 S c = (*it).getOccupancy();
252 S t = tree->getOccupancyThres();
254 std::array<S, 6> box = {{x, y, z, size, c, t}};
255 boxes.push_back(box);
262 template <
typename S>
263 void computeChildBV(
const AABB<S>& root_bv,
unsigned int i, AABB<S>& child_bv)
267 child_bv.min_[0] = (root_bv.min_[0] + root_bv.max_[0]) * 0.5;
268 child_bv.max_[0] = root_bv.max_[0];
272 child_bv.min_[0] = root_bv.min_[0];
273 child_bv.max_[0] = (root_bv.min_[0] + root_bv.max_[0]) * 0.5;
278 child_bv.min_[1] = (root_bv.min_[1] + root_bv.max_[1]) * 0.5;
279 child_bv.max_[1] = root_bv.max_[1];
283 child_bv.min_[1] = root_bv.min_[1];
284 child_bv.max_[1] = (root_bv.min_[1] + root_bv.max_[1]) * 0.5;
289 child_bv.min_[2] = (root_bv.min_[2] + root_bv.max_[2]) * 0.5;
290 child_bv.max_[2] = root_bv.max_[2];
294 child_bv.min_[2] = root_bv.min_[2];
295 child_bv.max_[2] = (root_bv.min_[2] + root_bv.max_[2]) * 0.5;
NODE_TYPE
traversal node type: bounding volume (AABB, OBB, RSS, kIOS, OBBRSS, KDOP16, KDOP18, kDOP24), basic shape (box, sphere, ellipsoid, capsule, cone, cylinder, convex, plane, halfspace, triangle), and octree
Definition: collision_geometry.h:54
Main namespace.
Definition: broadphase_bruteforce-inl.h:45
OBJECT_TYPE
object type: BVH (mesh, points), basic geometry, octree
Definition: collision_geometry.h:51