|
@@ -4,6 +4,8 @@
|
|
|
#include <iostream>
|
|
|
|
|
|
#include <QFileDialog>
|
|
|
+#include <QMessageBox>
|
|
|
+#include <QFile>
|
|
|
|
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
@@ -52,9 +54,54 @@ void MainWindow::on_actionLoad_triggered()
|
|
|
{
|
|
|
//读取pcd文件并显示
|
|
|
pcl::PointCloud<pcl::PointXYZI>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZI>());//创建点云指针
|
|
|
- QString fileName = QFileDialog::getOpenFileName(this, "Open PointCloud", ".", "Open PCD files(*.pcd)");
|
|
|
+ QString fileName = QFileDialog::getOpenFileName(this, "Open PointCloud", ".", "Open files(*.*)");
|
|
|
if(fileName == "") return;
|
|
|
- pcl::io::loadPCDFile(fileName.toStdString(),*cloud);
|
|
|
+ if((fileName.right(4) != ".pcd") &&(fileName.right(4) != ".bin"))
|
|
|
+ {
|
|
|
+ QMessageBox::warning(this,tr("Warning"),tr("Not .pcd or .bin file."),QMessageBox::YesAll);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(fileName.right(4) == ".pcd")
|
|
|
+ {
|
|
|
+ pcl::io::loadPCDFile(fileName.toStdString(),*cloud);
|
|
|
+ }
|
|
|
+ if(fileName.right(4) == ".bin")
|
|
|
+ {
|
|
|
+ QFile xFile;
|
|
|
+ xFile.setFileName(fileName);
|
|
|
+ if(xFile.open(QIODevice::ReadOnly))
|
|
|
+ {
|
|
|
+
|
|
|
+ while(1)
|
|
|
+ {
|
|
|
+
|
|
|
+ float x,y,z,intensity;
|
|
|
+ int nread;
|
|
|
+ xFile.read((char *)&x,sizeof(float));
|
|
|
+ xFile.read((char *)&y,sizeof(float));
|
|
|
+ xFile.read((char *)&z,sizeof(float));
|
|
|
+ nread = xFile.read((char *)&intensity,sizeof(float));
|
|
|
+ if(nread < 4)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ pcl::PointXYZI point;
|
|
|
+ point.x = x;
|
|
|
+ point.y = y;
|
|
|
+ point.z = z;
|
|
|
+ point.intensity = intensity;
|
|
|
+ cloud->points.push_back(point);
|
|
|
+ ++cloud->width;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ QMessageBox::warning(this,tr("Warning"),tr("Can't Read File."),QMessageBox::YesAll);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ xFile.close();
|
|
|
+
|
|
|
+ }
|
|
|
pcl::visualization::PointCloudColorHandlerGenericField<pcl::PointXYZI> fildColor(cloud, "intensity"); // 按照y字段进行渲染
|
|
|
view->removePointCloud("cloud");
|
|
|
view->addPointCloud<pcl::PointXYZI>(cloud,fildColor,"cloud");
|