#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 ;
}

最新文章

  1. espcms特殊标签
  2. Java--super关键字用法
  3. 使用连发互联空间+SQLyog 设置我们的数据库链接
  4. cloud theory is a failure? 分类: Cloud Computing 2013-12-26 06:52 269人阅读 评论(0) 收藏
  5. SqlServer 查看事务锁及执行语句
  6. SO_REUSEADDR 和 SO_REUSEPORT
  7. 列出当前ARM开发板系统加载的模块
  8. MVC Unit Testing学习笔记
  9. django中上传图片的写法
  10. FWT快速沃尔什变换学习笔记
  11. centos7安装NFS
  12. Hdoj 1007 Quoit Design 题解
  13. 字节输出流 FileOutputStream
  14. arcgis js api前端完成面积测算
  15. .NET小笔记-NPOI读取excel内容到DataTable
  16. java细节问题
  17. openstack系列文章(二)
  18. 高效使用jquery之一:请使用&#39;On&#39;函数
  19. 算法笔记_111:第五届蓝桥杯软件类省赛真题(Java本科A组)试题解答
  20. CentOS定位、查找文件的命令

热门文章

  1. Brain Powerd计划
  2. shell script 的简单介绍
  3. nodeJS学习(8)--- WS/...开发 NodeJS 项目-节3 &lt;使用 mongodb 完整实例过程&gt;
  4. 解决ie8下页面刚出现时候的晃动问题
  5. angular-关于分页
  6. Ubuntu中配置Tomcat与Eclipse整合
  7. Linux和Windows兼容
  8. hdu 3074(线段树)
  9. android studio 按钮运行按钮后,不弹出选择运行模拟器的对话框
  10. (5)ASP.NET HttpResponse 类