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());
}
相关推荐
「QT(C++)开发工程师」2 小时前
C++ auto 用法详解
开发语言·c++
OPEN-F2 小时前
C++STL教程:容器适配器与实用工具
开发语言·c++
OPEN-F2 小时前
C++模板教程:变参模板、折叠表达式与SFINAE
java·开发语言·c++
有点。2 小时前
C++二叉搜索树进阶
开发语言·c++
HugoStudio_SWAN2 小时前
【擦除重绘】C++ 控制台动画:弹跳 Logo DVD 屏保效果
开发语言·c++·学习·程序人生
kyle~4 小时前
C++_STL---迭代器失效
开发语言·c++
wuminyu5 小时前
深入剖析 Panama Off-heap 的性能损耗与开销
java·linux·c语言·jvm·c++
rhythm-ring6 小时前
宏定义续行符 \ 的使用与踩坑
c语言·c++
江安下小雨6 小时前
muduo网络库(十六):新增连接池模块
网络·c++
「QT(C++)开发工程师」7 小时前
C++11 std::unique_ptr — 独占所有权的智能指针
c语言·开发语言·c++·qt