首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >[C++]octomap安装后测试

[C++]octomap安装后测试

作者头像
云未归来
发布2025-07-19 15:18:59
发布2025-07-19 15:18:59
560
举报

测试环境:

vs2019

octomap==1.9.6

release x64

代码:

#include <octomap/octomap.h> #include <octomap/OcTree.h>

using namespace std; using namespace octomap; void print_query_info(point3d query, OcTreeNode* node) {     if (node != NULL) {         cout << "occupancy probability at " << query << ":\t " << node->getOccupancy() << endl;     }     else         cout << "occupancy probability at " << query << ":\t is unknown" << endl; } int main(int argc, char** argv) {

    cout << endl;     cout << "generating example map" << endl;     OcTree tree(0.1);  // create empty tree with resolution 0.1     // insert some measurements of occupied cells     for (int x = -20; x < 20; x++) {         for (int y = -20; y < 20; y++) {             for (int z = -20; z < 20; z++) {                 point3d endpoint((float)x * 0.05f, (float)y * 0.05f, (float)z * 0.05f);                 tree.updateNode(endpoint, true); // integrate 'occupied' measurement             }         }     }     // insert some measurements of free cells     for (int x = -30; x < 30; x++) {         for (int y = -30; y < 30; y++) {             for (int z = -30; z < 30; z++) {                 point3d endpoint((float)x * 0.02f - 1.0f, (float)y * 0.02f - 1.0f, (float)z * 0.02f - 1.0f);                 tree.updateNode(endpoint, false);  // integrate 'free' measurement             }         }     }     cout << endl;     cout << "performing some queries:" << endl;     point3d query(0., 0., 0.);     OcTreeNode* result = tree.search(query);     print_query_info(query, result);     query = point3d(-1., -1., -1.);     result = tree.search(query);     print_query_info(query, result);     query = point3d(1., 1., 1.);     result = tree.search(query);     print_query_info(query, result);     cout << endl;     tree.writeBinary("simple_tree.bt");     cout << "wrote example file simple_tree.bt" << endl << endl;     cout << "now you can use octovis to visualize: octovis simple_tree.bt" << endl;     cout << "Hint: hit 'F'-key in viewer to see the freespace" << endl << endl; }

结果:

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-05-25,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档