代码:pcd_write.cpp文件
#include <iostream>
#include <pcl/io/pcd_io.h> // PCD I/O 操作定义的头文件
#include <pcl/point_types.h> //包含几个点类型结构的定义
int
main ()
{
pcl::PointCloud<pcl::PointXYZ> cloud; //创建的模板化 PointCloud 结构。每个点的类型设置为pcl::PointXYZ,这是一个具有x、 y和z字段的结构。
// Fill in the cloud data 用随机点值填充 PointCloud 结构,并设置适当的参数(宽度、高度、is_dense)
cloud.width = 5;
cloud.height = 1;
cloud.is_dense = false;
cloud.resize (cloud.width * cloud.height);
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);//将 PointCloud 数据保存到磁盘到名为 test_pcd.pcd 的文件中
//用于显示生成的数据
std::cerr << "Saved " << cloud.size () << " data points to test_pcd.pcd."