#include <liblas/liblas.hpp>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <cmath>
#include <pcl/point_cloud.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/visualization/pcl_visualizer.h> // 实现Unshort转为Unchar类型
//int Unshort2Unchar(uint16_t &green, uint8_t &g)
//{
// unsigned short * word;
// word = &green;
// int size = WideCharToMultiByte(CP_ACP, 0, LPCWSTR(word), -1, NULL, 0, NULL, FALSE);
// char *AsciiBuff=new char[size];
// WideCharToMultiByte(CP_ACP, 0, LPCWSTR(word), -1, AsciiBuff, size, NULL, FALSE);
// g = *AsciiBuff;
//
// delete[] AsciiBuff;
// AsciiBuff = NULL;
// return 0;
//} void writePointCloudFromLas(const char* strInputLasName, const char* strOutPutPointCloudName)
{
//打开las文件
std::ifstream ifs;
ifs.open(strInputLasName, std::ios::in | std::ios::binary);
if (!ifs.is_open())
{
std::cout << "无法打开.las" << std::endl;
return;
}
liblas::ReaderFactory readerFactory;
liblas::Reader reader = readerFactory.CreateWithStream(ifs);
//写点云
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloudOutput(new pcl::PointCloud<pcl::PointXYZRGBA>());
cloudOutput->clear();
while (reader.ReadNextPoint())
{
double x = reader.GetPoint().GetX();
double y = reader.GetPoint().GetY();
double z = reader.GetPoint().GetZ();
uint16_t red = reader.GetPoint().GetColor()[];
uint16_t green = reader.GetPoint().GetColor()[];
uint16_t blue = reader.GetPoint().GetColor()[]; /*****颜色说明
* uint16_t 范围为0-256*256 ;
* pcl 中 R G B利用的unsigned char 0-256;
* 因此这里将uint16_t 除以256 得到 三位数的0-256的值
* 从而进行rgba 值32位 的位运算。
*
******/ pcl::PointXYZRGBA thePt; //int rgba = 255<<24 | ((int)r) << 16 | ((int)g) << 8 | ((int)b);
thePt.x = x; thePt.y = y; thePt.z = z;
thePt.rgba = (uint32_t) << | (uint32_t)(red / ) << | (uint32_t)(green / ) << | (uint32_t)(blue / );
//uint32_t rgb = *reinterpret_cast<int*>(&thePt.rgb); //reinterpret_cast 强制转换
cloudOutput->push_back(thePt);
} //boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));
//viewer->setBackgroundColor(0, 0, 0); //设置背景
//viewer->addPointCloud(cloudOutput,"cloudssd");
//while (!viewer->wasStopped()){
// viewer->spinOnce();
//}
pcl::io::savePCDFileASCII(strOutPutPointCloudName, *cloudOutput);
cloudOutput->clear();
} //读入点云,写.las void writeLasFromPointCloud3(const char* strInputPointCloudName, const char* strOutLasName)
{
std::ofstream ofs(strOutLasName, ios::out | ios::binary);
if (!ofs.is_open())
{
std::cout << "err to open file las....." << std::endl;
return;
}
liblas::Header header;
header.SetVersionMajor();
header.SetVersionMinor();
header.SetDataFormatId(liblas::PointFormatName::ePointFormat3);
header.SetScale(0.001, 0.001, 0.001); pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGBA>);
pcl::io::loadPCDFile(strInputPointCloudName, *cloud);
std::cout << "总数:" << cloud->points.size() << std::endl;
//写liblas,
liblas::Writer writer(ofs, header);
liblas::Point point(&header); for (size_t i = ; i < cloud->points.size(); i++)
{
double x = cloud->points[i].x;
double y = cloud->points[i].y;
double z = cloud->points[i].z;
point.SetCoordinates(x, y, z); uint32_t red = (uint32_t)cloud->points[i].r;
uint32_t green = (uint32_t)cloud->points[i].g;
uint32_t blue = (uint32_t)cloud->points[i].b;
liblas::Color pointColor(red, green, blue);
point.SetColor(pointColor);
writer.WritePoint(point);
//std::cout << x << "," << y << "," << z << std::endl;
}
double minPt[] = { , , };
double maxPt[] = { , , };
header.SetPointRecordsCount(cloud->points.size());
header.SetPointRecordsByReturnCount(, cloud->points.size());
header.SetMax(maxPt[], maxPt[], maxPt[]);
header.SetMin(minPt[], minPt[], minPt[]);
writer.SetHeader(header);
} int main()
{
//char strInputLasName[] = "qq.las";//"Scan_az001.las";
//char strOutPutPointCloudName[]="qqqq.pcd";
//writePointCloudFromLas(strInputLasName, strOutPutPointCloudName); //std::string strInputPointCloudName = "eewge";
//std::string strOutLasName = "eewge";
//writeLasFromPointCloud(strInputPointCloudName.c_str(), strOutLasName.c_str());
char strInputPointCloudName[] = "qq.pcd";
char strOutLasName[] = "qq.las";
writeLasFromPointCloud3(strInputPointCloudName, strOutLasName); return ;
}

基于pcl 和 liblas 库 las与pcd格式(rgb点)相互转换(win10 VS2013 X64环境 )的更多相关文章

  1. 25 面向对象设计实例——基于PCL点云库的通用工具开发

    0 引言 问题背景:pcl中提供了大量工具,用于对点云和三角面片文件进行处理和显示.在研究中,存在很多简易的需求,比如点云坐标转换,点云的打开显示以及同步显示,点云的最小包络求解,点云的格式转换等等. ...

  2. PCL点云库中的坐标系(CoordinateSystem)

    博客转载自:https://blog.csdn.net/qq_33624918/article/details/80488590 引言 世上本没有坐标系,用的人多了,便定义了坐标系统用来定位.地理坐标 ...

  3. Windows 8 64位系统 在VS2010 32位软件上 搭建 PCL点云库 开发环境

    Windows 8 64位系统 在VS2010 32位软件上 搭建 PCL点云库 开发环境 下载PCL For windows 软件包 到这个网站下载PCL-All-In-One Installer: ...

  4. [PCL]1 PCL点云库安装

    1.安装文件下载:官网,我还是比较喜欢别人编译好的安装包啊,哈哈. http://www.pointclouds.org/downloads/windows.html 2.傻瓜式安装(下面的依赖项都集 ...

  5. PCL点云库:ICP算法

    ICP(Iterative Closest Point迭代最近点)算法是一种点集对点集配准方法.在VTK.PCL.MRPT.MeshLab等C++库或软件中都有实现,可以参见维基百科中的ICP Alg ...

  6. 基于Qt的第三方库和控件

    ====================== 基于Qt的第三方库和控件 ======================     libQxt --------   http://dev.libqxt.o ...

  7. 利用cocoapods创建基于git的私有库

    上一篇文章记录了我利用cocoapods创建基于SVN的私有库的全部过程,今天我再记录一下基于git创建的过程. 整体先说明一下创建一个私有的podspec包括如下那么几个步骤: 创建并设置一个私有的 ...

  8. Axios 是一个基于 promise 的 HTTP 库

    Axios 是一个基于 promise 的 HTTP 库 vue项目中关于axios的简单使用 axios介绍 Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.j ...

  9. 利用cocoapods创建基于git的私有库Spec Repo

    上一篇文章记录了我利用cocoapods创建基于SVN的私有库的全部过程,今天我再记录一下基于git创建的过程. 整体先说明一下创建一个私有的podspec包括如下那么几个步骤: 创建并设置一个私有的 ...

随机推荐

  1. Python之时间:time模块

    import time   对于时间,使用最频繁的模块 1.获取当前时间 (1)时间戳 time.time() 时间戳:从1970年1月1日0点开始到现在按秒计算的偏移量 (2)时间元组 time.l ...

  2. cocoaPod的Podfile文件的创建和内容格式

    Podfile创建: 1.终端中,cd到项目总目录(cd +路径名) cd/........./......../...../项目名 2.终端中继续建立Podfile(配置文件) touch Podf ...

  3. 关于eclipse总是出现adb refused request的问题(转)

    1.检查下是不是开启了手机助手之类2.打开进程管理器,结束所有的adb.exe 3.关闭所有的杀毒软件之类的东东4.检查USB连接线,USB口,把USB线连在电脑主机后面的USB口5.重启eclips ...

  4. Program "D:\AndroidDevelopment\android-ndk-r9\ndk-build.cmd" not found in PATH

    1.问题描述 2.解决方法:修改ndk-build.cmd的配置路径, 修改成本地ndk-build.cmd所在路径,如下

  5. 关于ping以及TTL的分析【转】

    转自:http://blog.csdn.net/u013451221/article/details/46608881 首先介绍一下ping这个工具 ping [目标] 的意思就是向目标发送几个数据包 ...

  6. asp.net内置对象 Response对象使用介绍

    Response对象是HttpRespone类的一个实例.该类主要是封装来自ASP.NET操作的HTTP相应信息.Response对象将数据作为请求的结果从服务器发送到客户浏览器中,并提供有关响应的消 ...

  7. Codeforces 371E Subway Innovation (前缀和预处理应用)

    题目链接 Subway Innovation 首先不难想到所求的k个点一定是连续的,那么假设先选最前面的k个点,然后在O(1)内判断第2个点到第k+1个点这k个点哪个更优. 判断的时候用detla[i ...

  8. Codeforces 734 F Anton and School

    Discription Anton goes to school, his favorite lessons are arraystudying. He usually solves all the ...

  9. Maven错误:“No goals have been specified for this build...”问题解决

    如图出现如下错误: 解决方法如下: 1.(未测试)在pom.xml添加如下配置: <build> <defaultGoal>compile</defaultGoal> ...

  10. IM即时通讯群组头像拼接.net core 解决方案

    一.需求概述 多人聊天(群组,讨论组,聊天室,以下统称: “群组” )生成一个拼接头像,需要把最先加入群组的几个人(最多4个人,以下简称:头部用户,A.B.C.D)的头像拼凑成在一起. 群组创建后,A ...