[#03] PCD νμΌ μ°κΈ°
PCD νμΌ νμμΌλ‘ μ μ₯ν΄λ³΄μ
μ 체 μ½λ
#include <iostream>
// ν€λ νμΌ μ μΈ
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
using namespace std;
int main(int argc, char** argv)
{
// PCL object μ μΈ
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>());
// Unorganized formμΌλ‘ λ°μ΄ν° μ±μ°κΈ°
cloud->width = 30;
cloud->height = 1;
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);
}
// 2κ°μ§ λ°©λ² μ‘΄μ¬
// 1. savePCDFile ν¨μ μ΄μ©
// Third argument -> False for ASCII
if (pcl::io::savePCDFile("../test.pcd", *cloud, false) == -1)
{
PCL_ERROR("Failed to save!");
return -1;
}
// 2. PCDWriter μ΄μ©
pcl::PCDWriter writer;
writer.write("../test.pcd", *cloud, false);
return 0;
}
Leave a comment