一、下载链接
二、源码编译
LASlib/LAStools:Win10 + VS2017 编译LASlib/LAStools
三、配置LASlib
1、将编译成功的laslib随便放一个盘里
2、打开属性页,VC++目录——包含目录——添加laslib的include路径
D:\PCL 1.11.1\Laslib\include
3、库目录中添加laslib的lib路径,
debug版本:
D:\PCL 1.11.1\Laslib\lib\debug
release版本:
D:\PCL 1.11.1\Laslib\lib\release
4、链接器——输入——附加依赖项
debug版本添加
LASlibD.lib
release版本添加
LASlib.lib
四、测试代码
#include <iostream>
#include <lasreader.hpp>
// PCL
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <boost/thread/thread.hpp>
#include <pcl/visualization/pcl_visualizer.h>
using namespace std;
int main(int argc, char* argv[])
{
LASreadOpener lasreadopener;
LASreader* lasreader = lasreadopener.open(false, "test.las");// 第一个参数为是否只读取las头文件里的信息
if (lasreader == 0)
{
fprintf(stderr, "ERROR: could not open lasreader\n");
}
printf("reading %I64d points from '%s'.\n", lasreader->npoints, lasreadopener.get_file_name());
double xOffset = lasreader->header.x_offset; // X方向的偏移量
double yOffset = lasreader->header.y_offset; // Y方向的偏移量
double zOffset = lasreader->header.z_offset; // Z方向的偏移量
cout << "X方向的偏移量为:" << xOffset << "Y方向的偏移量为:" << yOffset << "Z方向的偏移量为:" << zOffset << endl;
int pointAmount = lasreader->npoints;
// ----------------------------使用PCL获取xyz坐标--------------------------------
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>());
cloud->width = pointAmount;
cloud->height = 1;
cloud->resize(lasreader->npoints);
cloud->is_dense = false;
size_t i = 0;
while (lasreader->read_point() && i < pointAmount)
{
// 与CloudCompare中减去偏移量操作对应
cloud->points[i].x = lasreader->point.get_x() - xOffset; // 获取X坐标
cloud->points[i].y = lasreader->point.get_y() - yOffset; // 获取Y坐标
cloud->points[i].z = lasreader->point.get_z() - zOffset; // 获取Z坐标
++i;
}
lasreader->close();
delete lasreader;
lasreader = nullptr;
// --------------------------使用PCL进行简单的可视化------------------------------
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));
viewer->setBackgroundColor(0, 0, 0);
viewer->setWindowName("LasLib读点云PCL可视化");
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> single_color(cloud, 0, 255, 0);
viewer->addPointCloud<pcl::PointXYZ>(cloud, single_color, "sample cloud");
viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3, "sample cloud");
while (!viewer->wasStopped())
{
viewer->spinOnce(100);
boost::this_thread::sleep(boost::posix_time::microseconds(100000));
}
return 0;
}
五、测试结果
六、参考链接
[1] LASlib / LAStools
[2] LASlib库将PCL库点云类型数据转换为las格式保存
[3] .las数据转.pcd并显示
[4] 孙爱怡,王健.LAS格式的解析与转换[J].全球定位系统,2016,41(02):115-117+124.