点云pcd文件转为八叉树bt文件的代码及编译流程

目录

目的

代码

pcd2bt.cpp

CMakeLists.txt文件内容

代码修改

编译

执行命令

 终端显示内容

使用程序


目的

点云文件转为八叉树文件

代码

在一个文件夹中新建两个文件,pcd2bt.cpp和CMakeLists.txt,分别写入:

pcd2bt.cpp

#include <iostream>
#include <assert.h>
 
//pcl
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>

//octomap
#include <octomap/octomap.h>
using namespace std;
 
int main( int argc, char** argv )
{
    if (argc != 3)
    {
        cout<<"error"<<endl;
        return -1;
    }
 
    string input_file = argv[1];
    string output_file = argv[2];
    pcl::PointCloud<pcl::PointXYZI> cloud;
    pcl::io::loadPCDFile<pcl::PointXYZI> ( input_file, cloud );
 
    cout<<"point cloud loaded, piont size = "<<cloud.points.size()<<endl;
 
    //声明octomap变量
    cout<<"copy data into octomap..."<<endl;
    // 创建八叉树对象,参数为分辨率,这里设成了0.05
    octomap::OcTree tree( 0.05 );
 
    for (auto p:cloud.points)
    {
        // 将点云里的点插入到octomap中
        tree.updateNode( octomap::point3d(p.x, p.y, p.z), true );
    }
 
    // 更新octomap
    tree.updateInnerOccupancy();
    // 存储octomap
    tree.writeBinary(output_file);
    cout<<"done."<<endl;
 
    return 0;
}

CMakeLists.txt文件内容

cmake_minimum_required(VERSION 2.8)
project(my_project_pcd2bt)
 
set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_CXX_FLAGS "-std=c++11")
# 设置编译类型为Release
 
# 添加PCL库的依赖
find_package(PCL REQUIRED )
 
# 添加octomap库的依赖
find_package(octomap REQUIRED)
 
# 添加头文件路径
include_directories(${PCL_INCLUDE_DIRS})
include_directories(${OCTOMAP_INCLUDE_DIRS})
 
# 添加链接库路径
link_directories(${PCL_LIBRARY_DIRS})
link_directories(${OCTOMAP_LIBRARY_DIRS})
 
# 编译可执行文件
add_executable(pcd2bt pcd2bt.cpp)
 
# 链接依赖库
target_link_libraries(pcd2bt ${PCL_LIBRARIES})
target_link_libraries(pcd2bt ${OCTOMAP_LIBRARIES})

代码修改

pcd2bt.cpp文件中,根据需要修改<pcl::PointXYZI>、分辨率等。

编译

执行命令

在这个文件夹中,打开终端。依次执行:

mkdir build
cd build
cmake ..
make

 终端显示内容

cmake ..通过,终端最后显示

-- Configuring done
-- Generating done
-- Build files have been written to: /usr/myhome/xxx/pcd2bt/build

make通过,终端最后显示 

Scanning dependencies of target pcd2bt
[ 50%] Building CXX object CMakeFiles/pcd2bt.dir/pcd2bt.cpp.o
[100%] Linking CXX executable pcd2bt
[100%] Built target pcd2bt

使用程序

在build文件夹下,打开终端。依次执行:

./pcd2bt /usr/myhome/xxx.pcd xxx.bt

xxx.pcd修改为所需转换的pcd文件的路径。

xxx.bt修改为所需保存的bt文件的路径。

参考

https://www.cnblogs.com/gaoxiang12/p/5041142.html

  • 12
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值