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());
}
相关推荐
C++ 老炮儿的技术栈34 分钟前
从 Qt Designer 属性编辑器的层级可以看到继承链
c语言·数据库·c++·qt·sqlite·visual studio
new_zhou1 小时前
C++ 项目 AI 协作指南(Windows / MSVC 环境)
c++·人工智能·windows
水饺编程2 小时前
AT&T 汇编语言学习笔记开篇语
c语言·汇编·c++
Iruoyaoxh3 小时前
类和对象~
开发语言·c++
程序喵大人3 小时前
【C++进阶】STL算法与函数对象 - 04 find、count和any_of把查询写成意图
开发语言·c++·算法
豆沙沙包?3 小时前
c++中引用(P7-P11)
java·c++·算法
wuminyu3 小时前
虚拟线程底层ForkJoinPool的工作窃取算法机制
java·linux·c语言·jvm·c++
吹什么轩3 小时前
c++复习:c++11:lambda表达式
开发语言·c++
不会代码的小猴3 小时前
标准模板库(STL)
开发语言·c++·笔记·算法
旖旎夜光4 小时前
LeetCode 202:快乐数(双指针问题) —— 题解
数据结构·c++·算法·leetcode·双指针