PCL_Write
PCL ASCII文本文件写入及点云文件格式。
Code
#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);
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::cerr << "Saved " << cloud.size() << " data points to test_pcd.pcd." << std::endl;
for (const auto &point : cloud)
std::cerr << " " << point.x << " " << point.y << " " << point.z << std::endl;
return (0);
}
Compile & Run
cmake -B build -S . -G "Visual Studio 15 2017 Win64"
cmake --build build --config Debug || cmake --build build --config Release
.\build\Debug\pcd_write.exe
Viewer Result
pcl_viewer_release.exe .\test_pcd.pcd -ps 10