#include<iostream>
#include<pcl/io/pcd_io.h>
#include<pcl/point_types.h>
int main()
{
 pcl::PointCloud<pcl::PointXYZ> cloud;
 cloud.width = 5;
 cloud.height = 1;
 cloud.is_dense = false;
 cloud.points.resize(cloud.width*cloud.height);
 for (size_t i = 0; i < cloud.points.size(); ++i)
 {
  cloud.points[i].x = 1000 * rand() / (RAND_MAX + 1.0);
  cloud.points[i].y = 1000 * rand() / (RAND_MAX + 1.0);
  cloud.points[i].z = 1000 * rand() / (RAND_MAX + 1.0);
 }
 pcl::io::savePCDFileASCII("my_test_pcd_input", cloud);
 std::cerr << "Saved " << cloud.points.size() << std::endl;
 for (size_t i = 0; i < cloud.points.size(); ++i)
 {
  std::cout << cloud.points[i].x << " " << cloud.points[i].y << " " << cloud.points[i].z << std::endl;
 }
 system("pause");
 return 0;
}

这里值得一说的就是这个随机生成数据的地方

  cloud.points[i].x = 1000 * rand() / (RAND_MAX + 1.0);
  cloud.points[i].y = 1000 * rand() / (RAND_MAX + 1.0);
  cloud.points[i].z = 1000 * rand() / (RAND_MAX + 1.0);
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐