区块链技术博客
www.b2bchain.cn

Qt 读取Las点云文件求职学习资料

本文介绍了Qt 读取Las点云文件求职学习资料,有助于帮助完成毕业设计以及求职,是一篇很好的资料。

对技术面试,学习经验等有一些体会,在此分享。

       有时候我们在接触LAS点云的时候,可能我们并不需要去对数据进行展示,或者进行过多的操作,那么当然市场上也有许许多多的点云读取库,如Liblas、PDal、pcl等众多第三方库的支持,本人比较懒也并不想去编译这些库,一是编译过程相当麻烦,而且技术受限总是报错之类的,所以直接研究Las文件格式发现这个文件是直接使用明文二进制格式存储,所以如果我只是想对Las点云文件进行读取的话,那么自己可以真的使用C++代码读取。

       接下来废话不多说,直接上代码。

1、点云结构体的创建,LasStruct.h

#pragma once #include <QString> #include <qlist.h> #include <basetsd.h> #include <QStringList> #include <QDataStream>  //自定义 点 结构体 struct LasPoint {     double x;     double y;     double z;     int intensity;     double GPStime;     int PointSourceID;     int r;     int g;     int b; };  /// <summary> /// 定义范围结构 /// </summary> struct RangeD {     double xmin;     double ymin;     double zmin;     double xmax;     double ymax;     double zmax; };  /// <summary> /// 变长记录 /// </summary> struct RecordSign {     unsigned short int recordSign;     char userId;     unsigned short int recordId;     unsigned short int recAftHeader;     char description;     char* extention = new char[recAftHeader]; };  /// <summary> /// 自定义点云结构体,包括头信息和变长记录,及点数据 /// </summary> struct LasInfo {     QString signature;     QString version;     UINT32 pointNum;     double xScale;     double yScale;     double zScale;     double xOffset;     double yOffset;     double zOffset;     RangeD rangeBound;     uint varNum;     int pointFormatId;     QList<RecordSign> recSigns;     QList<LasPoint> lasPoints; };

2、点云读取头文件 LasHelper.h

#pragma once #pragma execution_character_set("utf-8")//中文路径问题 #include "lashelper_global.h" #include "LasStruct.h"  //QT #include <QString> #include <qlist.h> #include <basetsd.h> #include <QStringList> #include <QDataStream>  class LASHELPER_EXPORT LasHelper {  public:     LasHelper(QString* lasUrl);     ~LasHelper();  private:     void readHeadInfo();     void readRecordSign();     void readPoints();  public:     LasInfo getHead();     LasInfo getPoints();  private:     QDataStream* lasStream;     LasInfo lasStruct;     RangeD readgeD;     QString lasFile; };

3、点云读取Cpp LasHelper.cpp

“`

include ‘LasHelper.h’

include

include

include

include

include

using namespace std;

LasHelper::LasHelper(QString* lasUrl)
{
this->lasFile = *lasUrl;
}

LasHelper::~LasHelper()
{
}

LasInfo LasHelper::getHead()
{
QFile lasFile(this->lasFile);
if (!(lasFile.open(QIODevice::ReadOnly)))
{
return lasStruct;
}
//读取文件流
lasStream = new QDataStream(&lasFile);
this->readHeadInfo();
return lasStruct;
}

LasInfo LasHelper::getPoints()
{
QFile lasFile(this->lasFile);
if (!(lasFile.open(QIODevice::ReadOnly)))
{
return lasStruct;
}
//读取文件流
lasStream = new QDataStream(&lasFile);
this->readHeadInfo();
readRecordSign();
readPoints();
return lasStruct;
}

///

/// 读取头文件信息 ///

void LasHelper::readHeadInfo() {
//File Signature (“LASF”)
char sn[4];
lasStream->readRawData((char)&sn, 4); QString signature; for each (char var in sn) { signature.append(var); } lasStruct.signature = signature; //File Source ID unsigned short int fsId; lasStream->readRawData((char)&fsId, sizeof(unsigned short int));
//Global Encoding
unsigned short int gencod;
lasStream->readRawData((char)&gencod, sizeof(unsigned short int)); //Project ID – GUID data 1 signed int guid1; lasStream->readRawData((char)&guid1, sizeof(signed int));
//Project ID – GUID data 2
unsigned short int guid2;
lasStream->readRawData((char)&guid2, sizeof(unsigned short int)); //Project ID – GUID data 3 unsigned short int guid3; lasStream->readRawData((char)&guid3, sizeof(unsigned short int));
//Project ID – GUID data 4
unsigned char guid4[8];
lasStream->readRawData((char*)&guid4, 8 * sizeof(unsigned char));
//Version Major
char versionMajor;
lasStream->readRawData((char)&versionMajor, sizeof(char)); //Version Minor char versionMinor; lasStream->readRawData((char)&versionMinor, sizeof(char));
QString version = QString(“%1.%2”).arg((int)versionMajor).arg((int)versionMinor);
lasStruct.version = version;
//System Identifier 系统标识符
char sysIde[32];
lasStream->readRawData((char*)&sysIde, 32 * sizeof(char));

       有时候我们在接触LAS点云的时候,可能我们并不需要去对数据进行展示,或者进行过多的操作,那么当然市场上也有许许多多的点云读取库,如Liblas、PDal、pcl等众多第三方库的支持,本人比较懒也并不想去编译这些库,一是编译过程相当麻烦,而且技术受限总是报错之类的,所以直接研究Las文件格式发现这个文件是直接使用明文二进制格式存储,所以如果我只是想对Las点云文件进行读取的话,那么自己可以真的使用C++代码读取。

       接下来废话不多说,直接上代码。

1、点云结构体的创建,LasStruct.h

#pragma once #include <QString> #include <qlist.h> #include <basetsd.h> #include <QStringList> #include <QDataStream>  //自定义 点 结构体 struct LasPoint {     double x;     double y;     double z;     int intensity;     double GPStime;     int PointSourceID;     int r;     int g;     int b; };  /// <summary> /// 定义范围结构 /// </summary> struct RangeD {     double xmin;     double ymin;     double zmin;     double xmax;     double ymax;     double zmax; };  /// <summary> /// 变长记录 /// </summary> struct RecordSign {     unsigned short int recordSign;     char userId;     unsigned short int recordId;     unsigned short int recAftHeader;     char description;     char* extention = new char[recAftHeader]; };  /// <summary> /// 自定义点云结构体,包括头信息和变长记录,及点数据 /// </summary> struct LasInfo {     QString signature;     QString version;     UINT32 pointNum;     double xScale;     double yScale;     double zScale;     double xOffset;     double yOffset;     double zOffset;     RangeD rangeBound;     uint varNum;     int pointFormatId;     QList<RecordSign> recSigns;     QList<LasPoint> lasPoints; };

2、点云读取头文件 LasHelper.h

#pragma once #pragma execution_character_set("utf-8")//中文路径问题 #include "lashelper_global.h" #include "LasStruct.h"  //QT #include <QString> #include <qlist.h> #include <basetsd.h> #include <QStringList> #include <QDataStream>  class LASHELPER_EXPORT LasHelper {  public:     LasHelper(QString* lasUrl);     ~LasHelper();  private:     void readHeadInfo();     void readRecordSign();     void readPoints();  public:     LasInfo getHead();     LasInfo getPoints();  private:     QDataStream* lasStream;     LasInfo lasStruct;     RangeD readgeD;     QString lasFile; };

3、点云读取Cpp LasHelper.cpp

“`

include ‘LasHelper.h’

include

include

include

include

include

using namespace std;

LasHelper::LasHelper(QString* lasUrl)
{
this->lasFile = *lasUrl;
}

LasHelper::~LasHelper()
{
}

LasInfo LasHelper::getHead()
{
QFile lasFile(this->lasFile);
if (!(lasFile.open(QIODevice::ReadOnly)))
{
return lasStruct;
}
//读取文件流
lasStream = new QDataStream(&lasFile);
this->readHeadInfo();
return lasStruct;
}

LasInfo LasHelper::getPoints()
{
QFile lasFile(this->lasFile);
if (!(lasFile.open(QIODevice::ReadOnly)))
{
return lasStruct;
}
//读取文件流
lasStream = new QDataStream(&lasFile);
this->readHeadInfo();
readRecordSign();
readPoints();
return lasStruct;
}

///

/// 读取头文件信息 ///

void LasHelper::readHeadInfo() {
//File Signature (“LASF”)
char sn[4];
lasStream->readRawData((char)&sn, 4); QString signature; for each (char var in sn) { signature.append(var); } lasStruct.signature = signature; //File Source ID unsigned short int fsId; lasStream->readRawData((char)&fsId, sizeof(unsigned short int));
//Global Encoding
unsigned short int gencod;
lasStream->readRawData((char)&gencod, sizeof(unsigned short int)); //Project ID – GUID data 1 signed int guid1; lasStream->readRawData((char)&guid1, sizeof(signed int));
//Project ID – GUID data 2
unsigned short int guid2;
lasStream->readRawData((char)&guid2, sizeof(unsigned short int)); //Project ID – GUID data 3 unsigned short int guid3; lasStream->readRawData((char)&guid3, sizeof(unsigned short int));
//Project ID – GUID data 4
unsigned char guid4[8];
lasStream->readRawData((char*)&guid4, 8 * sizeof(unsigned char));
//Version Major
char versionMajor;
lasStream->readRawData((char)&versionMajor, sizeof(char)); //Version Minor char versionMinor; lasStream->readRawData((char)&versionMinor, sizeof(char));
QString version = QString(“%1.%2”).arg((int)versionMajor).arg((int)versionMinor);
lasStruct.version = version;
//System Identifier 系统标识符
char sysIde[32];
lasStream->readRawData((char*)&sysIde, 32 * sizeof(char));

       有时候我们在接触LAS点云的时候,可能我们并不需要去对数据进行展示,或者进行过多的操作,那么当然市场上也有许许多多的点云读取库,如Liblas、PDal、pcl等众多第三方库的支持,本人比较懒也并不想去编译这些库,一是编译过程相当麻烦,而且技术受限总是报错之类的,所以直接研究Las文件格式发现这个文件是直接使用明文二进制格式存储,所以如果我只是想对Las点云文件进行读取的话,那么自己可以真的使用C++代码读取。

       接下来废话不多说,直接上代码。

1、点云结构体的创建,LasStruct.h

#pragma once #include <QString> #include <qlist.h> #include <basetsd.h> #include <QStringList> #include <QDataStream>  //自定义 点 结构体 struct LasPoint {     double x;     double y;     double z;     int intensity;     double GPStime;     int PointSourceID;     int r;     int g;     int b; };  /// <summary> /// 定义范围结构 /// </summary> struct RangeD {     double xmin;     double ymin;     double zmin;     double xmax;     double ymax;     double zmax; };  /// <summary> /// 变长记录 /// </summary> struct RecordSign {     unsigned short int recordSign;     char userId;     unsigned short int recordId;     unsigned short int recAftHeader;     char description;     char* extention = new char[recAftHeader]; };  /// <summary> /// 自定义点云结构体,包括头信息和变长记录,及点数据 /// </summary> struct LasInfo {     QString signature;     QString version;     UINT32 pointNum;     double xScale;     double yScale;     double zScale;     double xOffset;     double yOffset;     double zOffset;     RangeD rangeBound;     uint varNum;     int pointFormatId;     QList<RecordSign> recSigns;     QList<LasPoint> lasPoints; };

2、点云读取头文件 LasHelper.h

#pragma once #pragma execution_character_set("utf-8")//中文路径问题 #include "lashelper_global.h" #include "LasStruct.h"  //QT #include <QString> #include <qlist.h> #include <basetsd.h> #include <QStringList> #include <QDataStream>  class LASHELPER_EXPORT LasHelper {  public:     LasHelper(QString* lasUrl);     ~LasHelper();  private:     void readHeadInfo();     void readRecordSign();     void readPoints();  public:     LasInfo getHead();     LasInfo getPoints();  private:     QDataStream* lasStream;     LasInfo lasStruct;     RangeD readgeD;     QString lasFile; };

3、点云读取Cpp LasHelper.cpp

“`

include ‘LasHelper.h’

include

include

include

include

include

using namespace std;

LasHelper::LasHelper(QString* lasUrl)
{
this->lasFile = *lasUrl;
}

LasHelper::~LasHelper()
{
}

LasInfo LasHelper::getHead()
{
QFile lasFile(this->lasFile);
if (!(lasFile.open(QIODevice::ReadOnly)))
{
return lasStruct;
}
//读取文件流
lasStream = new QDataStream(&lasFile);
this->readHeadInfo();
return lasStruct;
}

LasInfo LasHelper::getPoints()
{
QFile lasFile(this->lasFile);
if (!(lasFile.open(QIODevice::ReadOnly)))
{
return lasStruct;
}
//读取文件流
lasStream = new QDataStream(&lasFile);
this->readHeadInfo();
readRecordSign();
readPoints();
return lasStruct;
}

///

/// 读取头文件信息 ///

void LasHelper::readHeadInfo() {
//File Signature (“LASF”)
char sn[4];
lasStream->readRawData((char)&sn, 4); QString signature; for each (char var in sn) { signature.append(var); } lasStruct.signature = signature; //File Source ID unsigned short int fsId; lasStream->readRawData((char)&fsId, sizeof(unsigned short int));
//Global Encoding
unsigned short int gencod;
lasStream->readRawData((char)&gencod, sizeof(unsigned short int)); //Project ID – GUID data 1 signed int guid1; lasStream->readRawData((char)&guid1, sizeof(signed int));
//Project ID – GUID data 2
unsigned short int guid2;
lasStream->readRawData((char)&guid2, sizeof(unsigned short int)); //Project ID – GUID data 3 unsigned short int guid3; lasStream->readRawData((char)&guid3, sizeof(unsigned short int));
//Project ID – GUID data 4
unsigned char guid4[8];
lasStream->readRawData((char*)&guid4, 8 * sizeof(unsigned char));
//Version Major
char versionMajor;
lasStream->readRawData((char)&versionMajor, sizeof(char)); //Version Minor char versionMinor; lasStream->readRawData((char)&versionMinor, sizeof(char));
QString version = QString(“%1.%2”).arg((int)versionMajor).arg((int)versionMinor);
lasStruct.version = version;
//System Identifier 系统标识符
char sysIde[32];
lasStream->readRawData((char*)&sysIde, 32 * sizeof(char));

部分转自互联网,侵权删除联系

赞(0) 打赏
部分文章转自网络,侵权联系删除b2bchain区块链学习技术社区 » Qt 读取Las点云文件求职学习资料
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

b2b链

联系我们联系我们