0
点赞
收藏
分享

微信扫一扫

pcl学习笔记--生成写pcd文件

精进的医生 2022-02-02 阅读 45

pcd_write.cpp

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

int main(int argc, char **argv)
{
//定义点云数据类型
pcl::PointCloud<pcl::PointXYZ> cloud;
//定义数据的长宽,尺寸等信息
// Fill in the cloud data
cloud.width = 5;
cloud.height = 1;
cloud.is_dense = false;
cloud.points.resize(cloud.width * cloud.height);

//c++11以后版本才有这个用法,所以要设置编译的版本号
for (auto &point : cloud)
{
//使用随机数给点云复制
point.x = 1024 * rand() / (RAND_MAX + 1.0f);
point.y = 1024 * rand() / (RAND_MAX + 1.0f);
point.z = 1024 * rand() / (RAND_MAX + 1.0f);
}
//保存文件
pcl::io::savePCDFileASCII("test_pcd.pcd", cloud);
std::cout << "Saved " << cloud.size() << " data points to test_pcd.pcd." << std::endl;

for (const auto &point : cloud)
std::cout << " " << point.x << " " << point.y << " " << point.z << std::endl;

return (0);
}

CmakeList.txt

 

cmake_minimum_required(VERSION 2.8 FATAL_ERROR) #对于cmake版本的最低版本的要求

project(pcd_write) #创建工程名

set(CMAKE_CXX_FLAGS "-g -Wall -std=c++11") #设置c++版本为2011版本

find_package(PCL 1.2 REQUIRED) #查看pcl库

include_directories(${PCL_INCLUDE_DIRS}) #添加pcl的相关路径
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

add_executable(pcd_write pcd_write.cpp) #这句话告诉CMake从单个源文件write_pcd建立一个可执行文件
#虽然包含了PCL的头文件,因此编译器知道我们现在访问所用的方法,我们也需要让链接器知道所链接的库,PCL找到库文件由
#PCL_COMMON_LIBRARIES变量指示,通过target_link_libraries这个宏来出发链接操作
target_link_libraries (pcd_write ${PCL_LIBRARIES}) #

参考资料

pcl-learning/CMakeLists.txt at master · HuangCongQing/pcl-learning · GitHub

举报

相关推荐

0 条评论