Octomap在windows环境配置(任意版本VS)

2019-07-27  本文已影响0人  codehory

简述

Octomap是一种采用八叉树数据结构存储三维环境的概率占据地图。地图单元为体素(立方体)。对于Octomap,作者这里也不过多介绍了。相信你点开这里,对Octomap也有了大致的了解。

由于一些特殊需求,我们有时需要在windows环境下进行配置使用Octomap。关于这块,网上的教程鲜有,故写此篇供大家参考。

此教程适用window下任意版本VS。
作者这里使用的是:VS2017 win10 octomap1.9.0

编译Octomap

打开Cmake,添加Octomap目录:1.根目录 2.build目录


点击Configure,根据自己的VS版本选择,


根据自己的平台选择,点Finish

点击Generate


进入octomap-1.9.0/build/文件夹,用VS打开ALL_BUILD.vcxproj,选择releaseordebug,win32orx64(这里要与上面选择的平台一致),右键解决方案栏里的ALL_BUILD重新生成,最终显示全部生成成功。

这样,在octomap-1.9.0文件夹中生成了lib文件夹

VS开发环境配置

1.新建一个空项目
2.菜单栏点击视图->其他窗口->属性管理器,按照你上面的选择,选择releaseordebug,win32orx64,这里以release|x64为例,右键新建添加新项目属性表,取名octomapconfig,添加,



3.双击新建的属性表
VC++ 目录->包含目录->添加头文件:(根据自己octomap的路径添加)
E:\Program Files\octomap-1.9.0\octomap\include
E:\Program Files\octomap-1.9.0\octovis\include
E:\Program Files\octomap-1.9.0\dynamicEDT3D\include

VC++ 目录->库目录->添加库文件:(根据自己octomap的路径添加)
E:\Program Files\octomap-1.9.0\lib

链接器->输入->附加依赖项添加lib文件:
dynamicedt3d.lib
octomap.lib
octomath.lib

点击确定,配置完成。

程序测试

#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;

}

如果生成成功,运行没有问题,表明配置成功!

相关问题

如果测试程序生成出现这样的报错,


解决办法:
项目->属性->C/C++->语言->符合模式->否

结语

至此,相信你也和我一样,已经配置成功了。
如有任何问题或是书写纰漏,请给我留言,我会帮你们耐心解决。
感谢观看,希望对你们有所帮助!

上一篇 下一篇

猜你喜欢

热点阅读