UFOMap代码Debug

问题描述:

根因不是单纯的点云误分类,而是 UFOMap (https://github.com/UnknownFreeOccupied/ufomap) 内部的 occupancy 聚合、自动剪枝逻辑,以及查询路径的 depth 下钻错误共同导致的。

查询路径 Octree::getNode(code) 和写入路径 Octree::getNodePath(code) 在 depth0 查询时不一致。写入路径已经更新到真实 depth0 leaf,但查询路径可能少下钻一层,读到父级节点的 occupancy。

代码修改

路径 3rdparty/ufomap/ufomap/include/ufo/map/octree.h:975-986

Git DIff

diff 复制代码
 std::pair<LEAF_NODE const*, DepthType> getNode(Code const& code) const
 {
     LEAF_NODE const* node = &getRoot();
-    for (DepthType depth = getTreeDepthLevels() - 1; depth > code.getDepth(); --depth) {
+    for (DepthType depth = getTreeDepthLevels(); depth > code.getDepth(); --depth) {
         INNER_NODE const& inner_node = static_cast<INNER_NODE const&>(*node);
         if (!hasChildren(inner_node)) {
-            return std::make_pair(node, depth + 1);
+            return std::make_pair(node, depth);
         }
-        node = &getChild(inner_node, depth, code.getChildIdx(depth));
+        DepthType child_depth = depth - 1;
+        node = &getChild(inner_node, child_depth, code.getChildIdx(child_depth));
     }
     return std::make_pair(node, code.getDepth());
 }

修复后的完整代码:

cpp 复制代码
std::pair<LEAF_NODE const*, DepthType> getNode(Code const& code) const
{
    LEAF_NODE const* node = &getRoot();
    for (DepthType depth = getTreeDepthLevels(); depth > code.getDepth(); --depth) {
        INNER_NODE const& inner_node = static_cast<INNER_NODE const&>(*node);
        if (!hasChildren(inner_node)) {
            return std::make_pair(node, depth);
        }
        DepthType child_depth = depth - 1;
        node = &getChild(inner_node, child_depth, code.getChildIdx(child_depth));
    }
    return std::make_pair(node, code.getDepth());
}
相关推荐
用户8055336980319 小时前
不止三件套:QObject 属性系统全关键字与运行时反射!
c++·qt
BadBadBad__AK1 天前
线段树维护区间 k 次方和
c++·数学·算法·stl
卷无止境2 天前
Eigen 库如何借助 OpenMP 加速计算
c++·后端
卷无止境2 天前
OpenMPI、MPICH 与 OpenMP:关系、核心概念与架构全解
c++·后端
郝学胜_神的一滴3 天前
CMake 30:循环语法全解|foreach_while双循环精讲、迭代技巧与实战避坑指南
c++·cmake
卷无止境5 天前
C++ 的Eigen 库全解析
c++
卷无止境5 天前
现代 C++特性大盘点:一门脱胎换骨的老语言
c++·后端
郝学胜_神的一滴5 天前
CMake 27:缓存变量的特性、语法、类型与实操全解
c++·cmake
博客18007 天前
酷宝的使用方法,超好用的免费界面库,C++、MFC可用
c++·mfc·界面库·库来帮·酷宝
郝学胜_神的一滴7 天前
CMake 026:属性体系精讲、四大作用域全解 & 实战代码落地
c++·cmake