ui 0.10 增加多线程读入pcd文件处理,提示用户等待加载,qvtk部分代码重构,ui修改

This commit is contained in:
ZESl
2020-04-19 21:59:33 +08:00
parent 9bca2d1482
commit 6226f3f909
9 changed files with 356 additions and 156 deletions

30
Classes/MyThread.cpp Normal file
View File

@@ -0,0 +1,30 @@
#include "MyThread.h"
MyThread::MyThread()
{
}
void MyThread::run()
{
if(!pcd.empty())
{
PointCloud<PointXYZRGB>::Ptr cloudPtr(new PointCloud<PointXYZRGB>);
io::loadPCDFile(pcd, *cloudPtr);
cloud = *cloudPtr;
}
}
void MyThread::setPcd(QString str)
{
pcd = str.toStdString();
}
PointCloud<PointXYZRGB> MyThread::getCloud()
{
return cloud;
}
MyThread::~MyThread()
{
}

25
Classes/MyThread.h Normal file
View File

@@ -0,0 +1,25 @@
#pragma once
#include <qthread.h>
#include <pcl/point_types.h>
#include <pcl/io/vtk_lib_io.h>
using namespace std;
using namespace pcl;
class MyThread :
public QThread
{
public:
MyThread();
~MyThread();
void setPcd(QString str);
PointCloud<PointXYZRGB> getCloud();
private:
string pcd;
PointCloud<PointXYZRGB> cloud;
protected:
void run();
};

View File

@@ -3,10 +3,14 @@
Reconstruction::Reconstruction(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
ui.setupUi(this);
t = new MyThread;
connect(t, SIGNAL(finished()), this, SLOT(setCloud()));
setStyle();
}
#pragma region Style
void Reconstruction::setStyle()
{
this->setContentsMargins(0, 0, 0, 0);
@@ -23,14 +27,21 @@ void Reconstruction::setStyle()
file.close();
QPalette palette1;
palette1.setColor(QPalette::Background, qRgba(44, 46, 70, 100));
palette1.setColor(QPalette::Background, qRgba(62, 71, 128, 100)); //左侧
ui.widget->setPalette(palette1);
QPalette palette2;
palette2.setColor(QPalette::Background, qRgba(255, 255, 255, 100)); //白色
// palette2.setColor(QPalette::Background, qRgba(204, 213, 240, 100)); //背景
ui.stackedWidget->setPalette(palette2);
ui.stackedWidget->setCurrentIndex(0);
setPicStyle();
setButtonStyle();
}
void Reconstruction::setPicStyle()
{
ui.label_9->setPixmap(QPixmap(":/icon/image/reconstruction/loading.png"));
ui.label_11->setPixmap(QPixmap(":/icon/image/calibration/novideo.png"));
ui.label_21->setPixmap(QPixmap(":/icon/image/projection/novideo.jpg"));
}
@@ -62,7 +73,7 @@ void Reconstruction::setButtonStyle()
ui.pushButton_15->setIcon(QIcon(":/icon/image/reconstruction/save2.png"));
ui.pushButton_16->setIcon(QIcon(":/icon/image/reconstruction/color.png"));
}
#pragma endregion
#pragma region 界面菜单
void Reconstruction::on_pushButton_clicked()
@@ -78,11 +89,31 @@ void Reconstruction::on_pushButton_2_clicked()
void Reconstruction::on_pushButton_3_clicked()
{
ui.stackedWidget->setCurrentIndex(2);
ui.label_9->setVisible(FALSE);
updateQVTK(cloud);
if(loadingStatus)
{
ui.label_9->setVisible(true);
}else
{
ui.label_9->setVisible(false);
}
}
#pragma endregion
#pragma region 多线程
void Reconstruction::setCloud()
{
ui.label_9->setVisible(false);
loadingStatus = false;
cloud = t->getCloud();
updateQVTK(cloud);
}
void Reconstruction::updateQVTK(PointCloud<PointXYZRGB> cloud)
{
boost::shared_ptr<visualization::PCLVisualizer> viewer(new visualization::PCLVisualizer("3D Viewer"));
viewer->setBackgroundColor(0, 0, 0);
viewer->setBackgroundColor(0.458, 0.529, 0.844);
viewer->setPointCloudRenderingProperties(visualization::PCL_VISUALIZER_POINT_SIZE, 1, "cloud");
if(cloud.size()!=0)
if (cloud.size() != 0)
{
PointCloud<PointXYZRGB>::Ptr cloudPtr(new PointCloud<PointXYZRGB>);
cloudPtr = cloud.makeShared();
@@ -270,12 +301,17 @@ void Reconstruction::on_pushButton_12_clicked()
// 导入点云
void Reconstruction::on_pushButton_13_clicked()
{
if(loadingStatus)
{
QMessageBox mesg;
mesg.warning(this, "WARNING", "正在加载… ");
return;
}
QString fileName = QFileDialog::getOpenFileName(
this, tr("open multiple image file"),
"./", tr("PCD files(*.pcd);;All files (*.*)")); // todo 文件类型待确认
ui.label_9->setVisible(TRUE);
this, tr("open multiple image file"),
"./", tr("PCD files(*.pcd);;All files (*.*)")); // todo 文件类型待确认
if (fileName.isEmpty())
{
QMessageBox mesg;
@@ -283,17 +319,11 @@ void Reconstruction::on_pushButton_13_clicked()
return;
}
string pcd = fileName.toStdString();
PointCloud<PointXYZRGB>::Ptr cloudPtr(new PointCloud<PointXYZRGB>);
io::loadPCDFile(pcd, *cloudPtr);
cloud = *cloudPtr;
boost::shared_ptr<visualization::PCLVisualizer> viewer(new visualization::PCLVisualizer("3D Viewer"));
viewer->setBackgroundColor(0, 0, 0);
viewer->addPointCloud(cloudPtr, "cloud");
viewer->setPointCloudRenderingProperties(visualization::PCL_VISUALIZER_POINT_SIZE, 1, "cloud");
ui.qvtkWidget->SetRenderWindow(viewer->getRenderWindow());
ui.label_9->setVisible(FALSE);
ui.qvtkWidget->update();
ui.label_9->setVisible(true);
QCoreApplication::processEvents();
t->setPcd(fileName);
t->start();
loadingStatus = true;
// todo 存储文件或文件路径
}
@@ -315,7 +345,7 @@ void Reconstruction::on_pushButton_15_clicked()
if (!fileName.isNull())
{
// 截图所选的控件暂时用 label_17 替代
QPixmap pix = QPixmap::grabWidget(ui.label_17);
QPixmap pix = QPixmap::grabWidget(ui.qvtkWidget);
pix.save(fileName);
}
}

View File

@@ -15,6 +15,7 @@
#include <pcl/io/vtk_lib_io.h>
#include <vtkRenderWindow.h>
#include <QProgressDialog>
#include "MyThread.h"
using namespace pcl;
using namespace std;
@@ -27,14 +28,19 @@ public:
private:
Ui::ReconstructionClass ui;
QString calPath; // 相机标定:标定图像的存储路径
QString picPath = "Result/result.png"; // 图案投影:拍摄照片的存储路径
QString calPath; // 系统标定:标定图像的存储路径
QString picPath = "Result/result.png"; // 三维重建:拍摄照片的存储路径
PointCloud<PointXYZRGB> cloud;
bool confirmPic = false; // 图案投影:确定是否用所拍照片进行重建
QColor color = Qt::black; // 三维重建:颜色
bool confirmPic = false; // 三维重建:确定是否用所拍照片进行重建
QColor color = Qt::black; // 点云渲染:颜色
// 多线程
MyThread* t;
bool loadingStatus = false; // 点云渲染
void setStyle();
void setPicStyle();
void setButtonStyle();
void updateQVTK(PointCloud<PointXYZRGB> cloud);
private slots:
void on_pushButton_clicked();
@@ -55,4 +61,5 @@ private slots:
void on_pushButton_16_clicked();
void on_pushButton_17_clicked();
void setPicAction(QString action);
void setCloud();
};

View File

@@ -19,6 +19,7 @@
<file>image/projection/novideo.jpg</file>
<file>image/loading/label.png</file>
<file>image/loading/press.png</file>
<file>image/reconstruction/loading.png</file>
</qresource>
<qresource prefix="/qss">
<file>qss/flat.qss</file>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

View File

@@ -2,14 +2,14 @@
/*QPushButton*/
QPushButton {
color: #000000;
background-color: white;
background-color: #e5ebfb;
border: 0px solid rgba(255, 255, 255, 0);
font-size: 16px;
border-radius: 5px;
}
QPushButton:hover {
background-color: #cceeff;
background-color: #ccd5f0;
}
QPushButton:pressed {
@@ -18,8 +18,8 @@ QPushButton:pressed {
fx: 0.5,
fy: 0.5,
radius: 1.5,
stop: 0.2 #4fc1e9,
stop: 0.8 #3bafda);
stop: 0.2 #abb6d7,
stop: 0.8 #abb6d7);
}
/*MediumGray*/

View File

@@ -56,10 +56,10 @@
<widget class="QStackedWidget" name="stackedWidget">
<property name="geometry">
<rect>
<x>249</x>
<y>6</y>
<width>981</width>
<height>641</height>
<x>239</x>
<y>-4</y>
<width>1001</width>
<height>651</height>
</rect>
</property>
<property name="autoFillBackground">
@@ -75,8 +75,8 @@
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>300</x>
<y>10</y>
<x>310</x>
<y>20</y>
<width>81</width>
<height>16</height>
</rect>
@@ -96,9 +96,9 @@
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
<x>670</x>
<x>690</x>
<y>430</y>
<width>301</width>
<width>291</width>
<height>201</height>
</rect>
</property>
@@ -303,8 +303,8 @@
<widget class="QGroupBox" name="groupBox_2">
<property name="geometry">
<rect>
<x>670</x>
<y>20</y>
<x>690</x>
<y>30</y>
<width>291</width>
<height>151</height>
</rect>
@@ -411,8 +411,8 @@
<widget class="QGroupBox" name="groupBox_5">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<x>30</x>
<y>40</y>
<width>640</width>
<height>512</height>
</rect>
@@ -461,15 +461,21 @@
<widget class="QPushButton" name="pushButton_5">
<property name="geometry">
<rect>
<x>70</x>
<x>50</x>
<y>580</y>
<width>100</width>
<height>28</height>
<width>120</width>
<height>51</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>100</width>
<width>110</width>
<height>16777215</height>
</size>
</property>
@@ -488,13 +494,19 @@
<rect>
<x>210</x>
<y>580</y>
<width>100</width>
<height>28</height>
<width>120</width>
<height>51</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>100</width>
<width>110</width>
<height>16777215</height>
</size>
</property>
@@ -511,15 +523,21 @@
<widget class="QPushButton" name="pushButton_7">
<property name="geometry">
<rect>
<x>350</x>
<x>370</x>
<y>580</y>
<width>100</width>
<height>28</height>
<width>120</width>
<height>51</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>100</width>
<width>110</width>
<height>16777215</height>
</size>
</property>
@@ -536,15 +554,21 @@
<widget class="QPushButton" name="pushButton_8">
<property name="geometry">
<rect>
<x>490</x>
<x>530</x>
<y>580</y>
<width>100</width>
<height>28</height>
<width>120</width>
<height>51</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>100</width>
<width>120</width>
<height>16777215</height>
</size>
</property>
@@ -561,9 +585,9 @@
<widget class="QGroupBox" name="groupBox_3">
<property name="geometry">
<rect>
<x>670</x>
<y>190</y>
<width>301</width>
<x>690</x>
<y>200</y>
<width>291</width>
<height>211</height>
</rect>
</property>
@@ -584,7 +608,7 @@
<rect>
<x>10</x>
<y>20</y>
<width>281</width>
<width>271</width>
<height>181</height>
</rect>
</property>
@@ -600,8 +624,8 @@
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>370</x>
<y>20</y>
<x>310</x>
<y>30</y>
<width>81</width>
<height>16</height>
</rect>
@@ -621,8 +645,8 @@
<widget class="QGroupBox" name="groupBox_6">
<property name="geometry">
<rect>
<x>90</x>
<y>50</y>
<x>30</x>
<y>60</y>
<width>640</width>
<height>512</height>
</rect>
@@ -665,51 +689,21 @@
<zorder>graphicsView_2</zorder>
<zorder>label_21</zorder>
</widget>
<widget class="QPushButton" name="pushButton_9">
<property name="geometry">
<rect>
<x>810</x>
<y>190</y>
<width>93</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<family>黑体</family>
</font>
</property>
<property name="text">
<string>相机拍照</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_10">
<property name="geometry">
<rect>
<x>810</x>
<y>290</y>
<width>93</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<family>黑体</family>
</font>
</property>
<property name="text">
<string>保存照片</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_4">
<property name="geometry">
<rect>
<x>620</x>
<y>580</y>
<width>111</width>
<height>31</height>
<x>550</x>
<y>590</y>
<width>120</width>
<height>41</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<property name="font">
<font>
<family>黑体</family>
@@ -722,26 +716,32 @@
<widget class="QLineEdit" name="lineEdit">
<property name="geometry">
<rect>
<x>240</x>
<y>580</y>
<width>331</width>
<height>31</height>
<x>150</x>
<y>590</y>
<width>381</width>
<height>41</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_18">
<property name="geometry">
<rect>
<x>90</x>
<y>580</y>
<x>30</x>
<y>590</y>
<width>111</width>
<height>30</height>
<height>40</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>40</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>30</height>
<height>40</height>
</size>
</property>
<property name="font">
@@ -757,32 +757,152 @@
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QPushButton" name="pushButton_17">
<widget class="QGroupBox" name="groupBox_7">
<property name="geometry">
<rect>
<x>810</x>
<y>390</y>
<width>93</width>
<height>31</height>
<x>700</x>
<y>50</y>
<width>281</width>
<height>311</height>
</rect>
</property>
<property name="font">
<font>
<family>黑体</family>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>开始重建</string>
<property name="title">
<string>重建日志</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<widget class="QTextBrowser" name="textBrowser_8">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>261</width>
<height>281</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>9</pointsize>
</font>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox_8">
<property name="geometry">
<rect>
<x>710</x>
<y>380</y>
<width>261</width>
<height>251</height>
</rect>
</property>
<property name="font">
<font>
<family>黑体</family>
<pointsize>10</pointsize>
</font>
</property>
<property name="title">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<widget class="QPushButton" name="pushButton_9">
<property name="geometry">
<rect>
<x>70</x>
<y>20</y>
<width>120</width>
<height>51</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<property name="font">
<font>
<family>黑体</family>
</font>
</property>
<property name="text">
<string>相机拍照</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_10">
<property name="geometry">
<rect>
<x>70</x>
<y>100</y>
<width>120</width>
<height>51</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<property name="font">
<font>
<family>黑体</family>
</font>
</property>
<property name="text">
<string>保存照片</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_17">
<property name="geometry">
<rect>
<x>70</x>
<y>180</y>
<width>120</width>
<height>51</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<property name="font">
<font>
<family>黑体</family>
</font>
</property>
<property name="text">
<string>开始重建</string>
</property>
</widget>
</widget>
<zorder>groupBox_8</zorder>
<zorder>label_3</zorder>
<zorder>groupBox_6</zorder>
<zorder>pushButton_4</zorder>
<zorder>lineEdit</zorder>
<zorder>label_18</zorder>
<zorder>groupBox_7</zorder>
</widget>
<widget class="QWidget" name="page_3">
<widget class="QGroupBox" name="groupBox_4">
<property name="geometry">
<rect>
<x>780</x>
<x>800</x>
<y>70</y>
<width>191</width>
<width>181</width>
<height>191</height>
</rect>
</property>
@@ -895,10 +1015,10 @@
<widget class="QPushButton" name="pushButton_13">
<property name="geometry">
<rect>
<x>800</x>
<x>820</x>
<y>330</y>
<width>131</width>
<height>28</height>
<width>141</width>
<height>41</height>
</rect>
</property>
<property name="font">
@@ -913,10 +1033,10 @@
<widget class="QPushButton" name="pushButton_14">
<property name="geometry">
<rect>
<x>800</x>
<y>400</y>
<width>131</width>
<height>28</height>
<x>820</x>
<y>410</y>
<width>141</width>
<height>41</height>
</rect>
</property>
<property name="font">
@@ -931,10 +1051,10 @@
<widget class="QPushButton" name="pushButton_15">
<property name="geometry">
<rect>
<x>800</x>
<y>470</y>
<width>131</width>
<height>28</height>
<x>820</x>
<y>490</y>
<width>141</width>
<height>41</height>
</rect>
</property>
<property name="font">
@@ -946,24 +1066,11 @@
<string>保存截图</string>
</property>
</widget>
<widget class="QLabel" name="label_17">
<property name="geometry">
<rect>
<x>280</x>
<y>260</y>
<width>72</width>
<height>15</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QVTKWidget" name="qvtkWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<x>30</x>
<y>20</y>
<width>741</width>
<height>621</height>
</rect>
@@ -972,23 +1079,23 @@
<widget class="QLabel" name="label_9">
<property name="geometry">
<rect>
<x>310</x>
<y>310</y>
<width>131</width>
<height>51</height>
<x>30</x>
<y>20</y>
<width>741</width>
<height>611</height>
</rect>
</property>
<property name="font">
<font>
<family>黑体</family>
<pointsize>11</pointsize>
<pointsize>18</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);</string>
<string notr="true"/>
</property>
<property name="text">
<string>Loading...</string>
<string/>
</property>
</widget>
</widget>