在配置好liblas库之后实现了las与pcd格式的转换。在代码中顺便测试了一下转换的速度。
主要代码如下:
#include <liblas\liblas.hpp>
#include <fstream>
#include <iostream>
#include <string>
#include<vector>
#include<pcl\io\pcd_io.h>
#include<pcl\point_types.h>
#include<time.h>
int main()
{
clock_t sT, tT,eT;
//打开文件
ifstream fp;
fp.open("1.las",ios::in|ios::binary);
sT = clock();
//读取
liblas::ReaderFactory readerFactory;
liblas::Reader reader = readerFactory.CreateWithStream(fp);
tT = clock();
cout << "读取" << reader.GetHeader().GetPointRecordsCount() <<"个点花费"<<(double)(tT-sT)/CLOCKS_PER_SEC<<"s"<<endl;
//点云类型
pcl::PointCloud<pcl::PointXYZ> cloudOutput;
cloudOutput.clear();
//转换xyz
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("1.pcd",cloudOutput);
cloudOutput.clear();
eT = clock();
cout << "存入" << reader.GetHeader().GetPointRecordsCount() << "个点花费" << (double)(eT - tT) / CLOCKS_PER_SEC << "s" << endl;
return 0;
}
测试结果:
速度很慢。。,但是终究实现了。