用liblas进行.las和.pcd互换

看了下liblas的文档,但是没有一次调通,特意记录如下:

 //读入.las,写点云
 void writePointCloudFromLas(const char* strInputLasName, const char* strOutPutPointCloudName)
 {
  //打开las文件
  std::ifstream ifs;
  ifs.open(strInputLasName, std::ios::in | std::ios::binary);

  liblas::ReaderFactory readerFactory;
  liblas::Reader reader = readerFactory.CreateWithStream(ifs);

  //写点云
  pcl::PointCloud<pcl::PointXYZ> cloudOutput;
  cloudOutput.clear();

  while (reader.ReadNextPoint())
  {
   double x = reader.GetPoint().GetX();
   double y = reader.GetPoint().GetY();
   double z = reader.GetPoint().GetZ();

   pcl::PointXYZ thePt(x, y, z);
   cloudOutput.push_back(thePt);

  }

  cloudOutput.width = cloudOutput.size();
  cloudOutput.height = 1;
  cloudOutput.is_dense = false;
  cloudOutput.resize(cloudOutput.width * cloudOutput.height);

  pcl::io::savePCDFileASCII("E:\\DEM-2016_2.pcd", cloudOutput);

  cloudOutput.clear();
 }
 //读入点云,写.las
 void writeLasFromPointCloud(const char* strInputPointCloudName, const char* strOutLasName)
 {

  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
  pcl::PCDReader pcdreader;
  pcdreader.read(strInputPointCloudName, *cloud);

  std::cout << "总数:" << cloud->points.size() << std::endl;
  //写liblas,

  std::ios::openmode m = std::ios::out | std::ios::in | std::ios::binary | std::ios::ate;

  std::ofstream ofs;
  if (!liblas::Create(ofs, strOutLasName))
  {
   std::cout << "无法创建.las" << std::endl;
   return;
  }
  ofs.close();

  std::ofstream * ofs2 = new std::ofstream(strOutLasName, m);
  if (!ofs2->is_open())
  {
   std::cout << "打不开.las" << std::endl;
   return;
  }
  else
  {
   std::cout << "能打开.las" << std::endl;

  }

  liblas::Header header;
  liblas::Writer writer(*ofs2, header);
  liblas::Point point(&header);
 
  for (size_t i = 0; i < cloud->points.size(); i++)
  {
   double x = cloud->points[i].x;
   double y = cloud->points[i].y;
   double z = cloud->points[i].z;

   point.SetX(x);
   point.SetY(y);
   point.SetZ(z);
   writer.WritePoint(point);
   std::cout << x << "," << y << "," << z << std::endl;
  }
  
 }




评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值