1 |
#include "SMScanner.h"
|
1 |
#include "SMScanner.h"
|
2 |
|
2 |
|
3 |
#include "ui_SMScanner.h"
|
3 |
#include "ui_SMScanner.h"
|
4 |
|
4 |
|
5 |
#include <QMetaObject>
|
5 |
#include <QMetaObject>
|
6 |
#include <QFileDialog>
|
6 |
#include <QFileDialog>
|
7 |
#include <QMessageBox>
|
7 |
#include <QMessageBox>
|
8 |
#include <QProgressDialog>
|
8 |
#include <QProgressDialog>
|
- |
|
9 |
#include <QDesktopServices>
|
9 |
|
10 |
|
10 |
#include <pcl/io/pcd_io.h>
|
11 |
#include <pcl/io/pcd_io.h>
|
11 |
#include <pcl/io/ascii_io.h>
|
12 |
#include <pcl/io/ascii_io.h>
|
12 |
#include <pcl/io/ply_io.h>
|
13 |
#include <pcl/io/ply_io.h>
|
13 |
#include <pcl/io/png_io.h>
|
14 |
#include <pcl/io/png_io.h>
|
14 |
#include <pcl/io/vtk_io.h>
|
15 |
#include <pcl/io/vtk_io.h>
|
15 |
#include <vtkPolyDataWriter.h>
|
16 |
#include <vtkPolyDataWriter.h>
|
16 |
#include <pcl/conversions.h>
|
17 |
#include <pcl/conversions.h>
|
17 |
|
18 |
|
18 |
#include "cvtools.h"
|
19 |
#include "cvtools.h"
|
19 |
|
20 |
|
20 |
SMScanner::SMScanner(QWidget *parent) :QMainWindow(parent), ui(new Ui::SMScanner),
|
21 |
SMScanner::SMScanner(QWidget *parent) :QMainWindow(parent), ui(new Ui::SMScanner),
|
21 |
calibrationReviewMode(false), captureReviewMode(false), lastCaptureId(-1){
|
22 |
calibrationReviewMode(false), captureReviewMode(false), lastCaptureId(-1){
|
22 |
|
23 |
|
23 |
// Register metatypes
|
24 |
// Register metatypes
|
24 |
qRegisterMetaType<cv::Mat>("cv::Mat");
|
25 |
qRegisterMetaType<cv::Mat>("cv::Mat");
|
25 |
qRegisterMetaType< std::vector<cv::Mat> >("std::vector<cv::Mat>");
|
26 |
qRegisterMetaType< std::vector<cv::Mat> >("std::vector<cv::Mat>");
|
26 |
qRegisterMetaType< std::vector<float> >("std::vector<float>");
|
27 |
qRegisterMetaType< std::vector<float> >("std::vector<float>");
|
27 |
qRegisterMetaType<SMCalibrationSet>("SMCalibrationSet");
|
28 |
qRegisterMetaType<SMCalibrationSet>("SMCalibrationSet");
|
28 |
qRegisterMetaType< std::vector<SMCalibrationSet> >("std::vector<SMCalibrationSet>");
|
29 |
qRegisterMetaType< std::vector<SMCalibrationSet> >("std::vector<SMCalibrationSet>");
|
29 |
qRegisterMetaType<SMFrameSequence>("SMFrameSequence");
|
30 |
qRegisterMetaType<SMFrameSequence>("SMFrameSequence");
|
30 |
qRegisterMetaType< std::vector<SMFrameSequence> >("std::vector<SMFrameSequence>");
|
31 |
qRegisterMetaType< std::vector<SMFrameSequence> >("std::vector<SMFrameSequence>");
|
31 |
qRegisterMetaType<pcl::PointCloud<pcl::PointXYZRGB>::Ptr>("pcl::PointCloud<pcl::PointXYZRGB>::Ptr");
|
32 |
qRegisterMetaType<pcl::PointCloud<pcl::PointXYZRGB>::Ptr>("pcl::PointCloud<pcl::PointXYZRGB>::Ptr");
|
32 |
qRegisterMetaType<SMPointCloud>("SMPointCloud");
|
33 |
qRegisterMetaType<SMPointCloud>("SMPointCloud");
|
33 |
qRegisterMetaType< std::vector<SMPointCloud> >("std::vector<SMPointCloud>");
|
34 |
qRegisterMetaType< std::vector<SMPointCloud> >("std::vector<SMPointCloud>");
|
34 |
|
35 |
|
35 |
// Setup ui (requires stream operators registered)
|
36 |
// Setup ui (requires stream operators registered)
|
36 |
ui->setupUi(this);
|
37 |
ui->setupUi(this);
|
37 |
|
38 |
|
38 |
// Restore geometry
|
39 |
// Restore geometry
|
39 |
this->restoreGeometry(settings.value("geometry/mainwindow").toByteArray());
|
40 |
this->restoreGeometry(settings.value("geometry/mainwindow").toByteArray());
|
40 |
this->restoreState(settings.value("state/mainwindow").toByteArray());
|
41 |
this->restoreState(settings.value("state/mainwindow").toByteArray());
|
41 |
|
42 |
|
42 |
// Set up capture thread
|
43 |
// Set up capture thread
|
43 |
captureWorker = new SMCaptureWorker;
|
44 |
captureWorker = new SMCaptureWorker;
|
44 |
captureWorkerThread = new QThread(this);
|
45 |
captureWorkerThread = new QThread(this);
|
45 |
captureWorkerThread->setObjectName("captureWorkerThread");
|
46 |
captureWorkerThread->setObjectName("captureWorkerThread");
|
46 |
captureWorker->moveToThread(captureWorkerThread);
|
47 |
captureWorker->moveToThread(captureWorkerThread);
|
47 |
captureWorkerThread->start();
|
48 |
captureWorkerThread->start();
|
48 |
|
49 |
|
49 |
// Connections
|
50 |
// Connections
|
50 |
connect(captureWorker, SIGNAL(newFrame(unsigned int, cv::Mat)), this, SLOT(onReceiveFrame(unsigned int, cv::Mat)));
|
51 |
connect(captureWorker, SIGNAL(newFrame(unsigned int, cv::Mat)), this, SLOT(onReceiveFrame(unsigned int, cv::Mat)));
|
51 |
connect(captureWorker, SIGNAL(newCalibrationSet(SMCalibrationSet)), this, SLOT(onReceiveCalibrationSet(SMCalibrationSet)));
|
52 |
connect(captureWorker, SIGNAL(newCalibrationSet(SMCalibrationSet)), this, SLOT(onReceiveCalibrationSet(SMCalibrationSet)));
|
52 |
connect(captureWorker, SIGNAL(newFrameSequence(SMFrameSequence)), this, SLOT(onReceiveFrameSequence(SMFrameSequence)));
|
53 |
connect(captureWorker, SIGNAL(newFrameSequence(SMFrameSequence)), this, SLOT(onReceiveFrameSequence(SMFrameSequence)));
|
53 |
connect(captureWorker, SIGNAL(rotatedTo(float)), this, SLOT(onReceiveRotatedTo(float)));
|
54 |
connect(captureWorker, SIGNAL(rotatedTo(float)), this, SLOT(onReceiveRotatedTo(float)));
|
54 |
|
55 |
|
55 |
// Start capturing
|
56 |
// Start capturing
|
56 |
QMetaObject::invokeMethod(captureWorker, "setup");
|
57 |
QMetaObject::invokeMethod(captureWorker, "setup");
|
57 |
QMetaObject::invokeMethod(captureWorker, "doWork");
|
58 |
QMetaObject::invokeMethod(captureWorker, "doWork");
|
58 |
|
59 |
|
59 |
// Set up calibration thread
|
60 |
// Set up calibration thread
|
60 |
calibrationWorker = new SMCalibrationWorker;
|
61 |
calibrationWorker = new SMCalibrationWorker;
|
61 |
calibrationWorkerThread = new QThread(this);
|
62 |
calibrationWorkerThread = new QThread(this);
|
62 |
calibrationWorkerThread->setObjectName("calibrationWorkerThread");
|
63 |
calibrationWorkerThread->setObjectName("calibrationWorkerThread");
|
63 |
calibrationWorker->moveToThread(calibrationWorkerThread);
|
64 |
calibrationWorker->moveToThread(calibrationWorkerThread);
|
64 |
calibrationWorkerThread->start();
|
65 |
calibrationWorkerThread->start();
|
65 |
|
66 |
|
66 |
// Connections
|
67 |
// Connections
|
67 |
connect(calibrationWorker, SIGNAL(newCheckerboardResult(int, SMCalibrationSet)), this, SLOT(onReceiveCheckerboardResult(int, SMCalibrationSet)));
|
68 |
connect(calibrationWorker, SIGNAL(newCheckerboardResult(int, SMCalibrationSet)), this, SLOT(onReceiveCheckerboardResult(int, SMCalibrationSet)));
|
68 |
connect(calibrationWorker, SIGNAL(done()), this, SLOT(onReceiveCalibrationDone()));
|
69 |
connect(calibrationWorker, SIGNAL(done()), this, SLOT(onReceiveCalibrationDone()));
|
69 |
connect(calibrationWorker, SIGNAL(done()), ui->pointCloudWidget, SLOT(updateCalibrationParameters()));
|
70 |
connect(calibrationWorker, SIGNAL(done()), ui->pointCloudWidget, SLOT(updateCalibrationParameters()));
|
70 |
// connect(calibrationWorker, SIGNAL(done()), calibrationWorkerThread, SLOT(quit()));
|
71 |
// connect(calibrationWorker, SIGNAL(done()), calibrationWorkerThread, SLOT(quit()));
|
71 |
// connect(calibrationWorker, SIGNAL(done()), calibrationWorker, SLOT(deleteLater()));
|
72 |
// connect(calibrationWorker, SIGNAL(done()), calibrationWorker, SLOT(deleteLater()));
|
72 |
connect(calibrationWorker, SIGNAL(logMessage(QString)), &logDialog, SLOT(showLogMessage(QString)));
|
73 |
connect(calibrationWorker, SIGNAL(logMessage(QString)), &logDialog, SLOT(showLogMessage(QString)));
|
73 |
|
74 |
|
74 |
// Set up reconstruction thread
|
75 |
// Set up reconstruction thread
|
75 |
reconstructionWorker = new SMReconstructionWorker;
|
76 |
reconstructionWorker = new SMReconstructionWorker;
|
76 |
reconstructionWorkerThread = new QThread(this);
|
77 |
reconstructionWorkerThread = new QThread(this);
|
77 |
reconstructionWorkerThread->setObjectName("reconstructionWorkerThread");
|
78 |
reconstructionWorkerThread->setObjectName("reconstructionWorkerThread");
|
78 |
reconstructionWorker->moveToThread(reconstructionWorkerThread);
|
79 |
reconstructionWorker->moveToThread(reconstructionWorkerThread);
|
79 |
reconstructionWorkerThread->start();
|
80 |
reconstructionWorkerThread->start();
|
80 |
|
81 |
|
81 |
// Connections
|
82 |
// Connections
|
82 |
connect(reconstructionWorker, SIGNAL(newPointCloud(SMPointCloud)), this, SLOT(onReceivePointCloud(SMPointCloud)));
|
83 |
connect(reconstructionWorker, SIGNAL(newPointCloud(SMPointCloud)), this, SLOT(onReceivePointCloud(SMPointCloud)));
|
83 |
connect(reconstructionWorker, SIGNAL(done()), reconstructionWorkerThread, SLOT(quit()));
|
84 |
connect(reconstructionWorker, SIGNAL(done()), reconstructionWorkerThread, SLOT(quit()));
|
84 |
connect(reconstructionWorker, SIGNAL(done()), reconstructionWorker, SLOT(deleteLater()));
|
85 |
connect(reconstructionWorker, SIGNAL(done()), reconstructionWorker, SLOT(deleteLater()));
|
85 |
|
86 |
|
86 |
}
|
87 |
}
|
87 |
|
88 |
|
88 |
void SMScanner::onReceiveFrame(unsigned int camId, cv::Mat frame){
|
89 |
void SMScanner::onReceiveFrame(unsigned int camId, cv::Mat frame){
|
89 |
|
90 |
|
90 |
if(camId == 0){
|
91 |
if(camId == 0){
|
91 |
if(!calibrationReviewMode)
|
92 |
if(!calibrationReviewMode)
|
92 |
ui->calibrationCamera0Widget->showImageCV(frame);
|
93 |
ui->calibrationCamera0Widget->showImageCV(frame);
|
93 |
if(!captureReviewMode)
|
94 |
if(!captureReviewMode)
|
94 |
ui->captureCamera0Widget->showImageCV(frame);
|
95 |
ui->captureCamera0Widget->showImageCV(frame);
|
95 |
} else if(camId == 1){
|
96 |
} else if(camId == 1){
|
96 |
if(!calibrationReviewMode)
|
97 |
if(!calibrationReviewMode)
|
97 |
ui->calibrationCamera1Widget->showImageCV(frame);
|
98 |
ui->calibrationCamera1Widget->showImageCV(frame);
|
98 |
if(!captureReviewMode)
|
99 |
if(!captureReviewMode)
|
99 |
ui->captureCamera1Widget->showImageCV(frame);
|
100 |
ui->captureCamera1Widget->showImageCV(frame);
|
100 |
}
|
101 |
}
|
101 |
}
|
102 |
}
|
102 |
|
103 |
|
103 |
void SMScanner::on_actionPreferences_triggered(){
|
104 |
void SMScanner::on_actionPreferences_triggered(){
|
104 |
|
105 |
|
105 |
connect(&preferenceDialog, SIGNAL(accepted()), this, SLOT(onPreferencesChanged()));
|
106 |
connect(&preferenceDialog, SIGNAL(accepted()), this, SLOT(onPreferencesChanged()));
|
106 |
|
107 |
|
107 |
preferenceDialog.show();
|
108 |
preferenceDialog.show();
|
108 |
}
|
109 |
}
|
109 |
|
110 |
|
110 |
void SMScanner::onPreferencesChanged(){
|
111 |
void SMScanner::onPreferencesChanged(){
|
111 |
|
112 |
|
112 |
// Stop capture worker
|
113 |
// Stop capture worker
|
113 |
// connect(captureWorker, SIGNAL(finished()), captureWorker, SLOT(deleteLater()));
|
114 |
// connect(captureWorker, SIGNAL(finished()), captureWorker, SLOT(deleteLater()));
|
114 |
// connect(captureWorker, SIGNAL(finished()), captureWorkerThread, SLOT(quit()));
|
115 |
// connect(captureWorker, SIGNAL(finished()), captureWorkerThread, SLOT(quit()));
|
115 |
QMetaObject::invokeMethod(captureWorker, "stopWork");
|
116 |
QMetaObject::invokeMethod(captureWorker, "stopWork");
|
116 |
// captureWorkerThread->quit();
|
117 |
// captureWorkerThread->quit();
|
117 |
// captureWorkerThread->wait();
|
118 |
// captureWorkerThread->wait();
|
118 |
|
119 |
|
119 |
// // Restart capture worker
|
120 |
// // Restart capture worker
|
120 |
// captureWorker = new SMCaptureWorker;
|
121 |
// captureWorker = new SMCaptureWorker;
|
121 |
// captureWorkerThread = new QThread(this);
|
122 |
// captureWorkerThread = new QThread(this);
|
122 |
// captureWorkerThread->setObjectName("captureWorkerThread");
|
123 |
// captureWorkerThread->setObjectName("captureWorkerThread");
|
123 |
// captureWorker->moveToThread(captureWorkerThread);
|
124 |
// captureWorker->moveToThread(captureWorkerThread);
|
124 |
// captureWorkerThread->start();
|
125 |
// captureWorkerThread->start();
|
125 |
|
126 |
|
126 |
// connect(captureWorker, SIGNAL(newFrame(unsigned int, cv::Mat)), this, SLOT(onReceiveFrame(unsigned int, cv::Mat)));
|
127 |
// connect(captureWorker, SIGNAL(newFrame(unsigned int, cv::Mat)), this, SLOT(onReceiveFrame(unsigned int, cv::Mat)));
|
127 |
// connect(captureWorker, SIGNAL(newCalibrationSet(SMCalibrationSet)), this, SLOT(onReceiveCalibrationSet(SMCalibrationSet)));
|
128 |
// connect(captureWorker, SIGNAL(newCalibrationSet(SMCalibrationSet)), this, SLOT(onReceiveCalibrationSet(SMCalibrationSet)));
|
128 |
// connect(captureWorker, SIGNAL(newFrameSequence(SMFrameSequence)), this, SLOT(onReceiveFrameSequence(SMFrameSequence)));
|
129 |
// connect(captureWorker, SIGNAL(newFrameSequence(SMFrameSequence)), this, SLOT(onReceiveFrameSequence(SMFrameSequence)));
|
129 |
// connect(captureWorker, SIGNAL(rotatedTo(float)), this, SLOT(onReceiveRotatedTo(float)));
|
130 |
// connect(captureWorker, SIGNAL(rotatedTo(float)), this, SLOT(onReceiveRotatedTo(float)));
|
130 |
|
131 |
|
131 |
QMetaObject::invokeMethod(captureWorker, "setup");
|
132 |
QMetaObject::invokeMethod(captureWorker, "setup");
|
132 |
QMetaObject::invokeMethod(captureWorker, "doWork");
|
133 |
QMetaObject::invokeMethod(captureWorker, "doWork");
|
133 |
|
134 |
|
134 |
}
|
135 |
}
|
135 |
|
136 |
|
136 |
void SMScanner::closeEvent(QCloseEvent *event){
|
137 |
void SMScanner::closeEvent(QCloseEvent *event){
|
137 |
|
138 |
|
138 |
// Close dialogs
|
139 |
// Close dialogs
|
139 |
preferenceDialog.close();
|
140 |
preferenceDialog.close();
|
140 |
logDialog.close();
|
141 |
logDialog.close();
|
141 |
|
142 |
|
142 |
// Stop capturing thread
|
143 |
// Stop capturing thread
|
143 |
connect(captureWorker, SIGNAL(finished()), captureWorker, SLOT(deleteLater()));
|
144 |
connect(captureWorker, SIGNAL(finished()), captureWorker, SLOT(deleteLater()));
|
144 |
connect(captureWorker, SIGNAL(finished()), captureWorkerThread, SLOT(quit()));
|
145 |
connect(captureWorker, SIGNAL(finished()), captureWorkerThread, SLOT(quit()));
|
145 |
QMetaObject::invokeMethod(captureWorker, "stopWork");
|
146 |
QMetaObject::invokeMethod(captureWorker, "stopWork");
|
146 |
captureWorkerThread->quit();
|
147 |
captureWorkerThread->quit();
|
147 |
captureWorkerThread->wait();
|
148 |
captureWorkerThread->wait();
|
148 |
|
149 |
|
149 |
// Save window geometry
|
150 |
// Save window geometry
|
150 |
settings.setValue("geometry/mainwindow", this->saveGeometry());
|
151 |
settings.setValue("geometry/mainwindow", this->saveGeometry());
|
151 |
settings.setValue("state/mainwindow", this->saveState());
|
152 |
settings.setValue("state/mainwindow", this->saveState());
|
152 |
|
153 |
|
153 |
event->accept();
|
154 |
event->accept();
|
154 |
|
155 |
|
155 |
}
|
156 |
}
|
156 |
|
157 |
|
157 |
SMScanner::~SMScanner(){
|
158 |
SMScanner::~SMScanner(){
|
158 |
delete ui;
|
159 |
delete ui;
|
159 |
}
|
160 |
}
|
160 |
|
161 |
|
161 |
void SMScanner::on_singleCalibrationButton_clicked(){
|
162 |
void SMScanner::on_singleCalibrationButton_clicked(){
|
162 |
|
163 |
|
163 |
// If in review mode, go back to aquisition mode
|
164 |
// If in review mode, go back to aquisition mode
|
164 |
if(calibrationReviewMode){
|
165 |
if(calibrationReviewMode){
|
165 |
ui->calibrationListWidget->clearSelection();
|
166 |
ui->calibrationListWidget->clearSelection();
|
166 |
ui->singleCalibrationButton->setText("Single Aquisition");
|
167 |
ui->singleCalibrationButton->setText("Single Aquisition");
|
167 |
ui->batchCalibrationButton->setText("Batch Aquisition");
|
168 |
ui->batchCalibrationButton->setText("Batch Aquisition");
|
168 |
calibrationReviewMode = false;
|
169 |
calibrationReviewMode = false;
|
169 |
return;
|
170 |
return;
|
170 |
}
|
171 |
}
|
171 |
|
172 |
|
172 |
QMetaObject::invokeMethod(captureWorker, "acquireCalibrationSet", Q_ARG(float, -1.0));
|
173 |
QMetaObject::invokeMethod(captureWorker, "acquireCalibrationSet", Q_ARG(float, -1.0));
|
173 |
|
174 |
|
174 |
}
|
175 |
}
|
175 |
|
176 |
|
176 |
|
177 |
|
177 |
void SMScanner::on_batchCalibrationButton_clicked(){
|
178 |
void SMScanner::on_batchCalibrationButton_clicked(){
|
178 |
|
179 |
|
179 |
// If in review mode, go back to aquisition mode
|
180 |
// If in review mode, go back to aquisition mode
|
180 |
if(calibrationReviewMode){
|
181 |
if(calibrationReviewMode){
|
181 |
ui->calibrationListWidget->clearSelection();
|
182 |
ui->calibrationListWidget->clearSelection();
|
182 |
ui->singleCalibrationButton->setText("Single Aquisition");
|
183 |
ui->singleCalibrationButton->setText("Single Aquisition");
|
183 |
ui->batchCalibrationButton->setText("Batch Aquisition");
|
184 |
ui->batchCalibrationButton->setText("Batch Aquisition");
|
184 |
calibrationReviewMode = false;
|
185 |
calibrationReviewMode = false;
|
185 |
return;
|
186 |
return;
|
186 |
}
|
187 |
}
|
187 |
|
188 |
|
188 |
// Construct vector of angles
|
189 |
// Construct vector of angles
|
189 |
int angleStart = ui->calibrationBatchStartSpinBox->value();
|
190 |
int angleStart = ui->calibrationBatchStartSpinBox->value();
|
190 |
int angleEnd = ui->calibrationBatchEndSpinBox->value();
|
191 |
int angleEnd = ui->calibrationBatchEndSpinBox->value();
|
191 |
int angleStep = ui->calibrationBatchStepSpinBox->value();
|
192 |
int angleStep = ui->calibrationBatchStepSpinBox->value();
|
192 |
|
193 |
|
193 |
if(angleStart > angleEnd)
|
194 |
if(angleStart > angleEnd)
|
194 |
angleEnd += 360;
|
195 |
angleEnd += 360;
|
195 |
|
196 |
|
196 |
std::vector<float> angles;
|
197 |
std::vector<float> angles;
|
197 |
for(int i=angleStart; i<=angleEnd; i+=angleStep)
|
198 |
for(int i=angleStart; i<=angleEnd; i+=angleStep)
|
198 |
angles.push_back(i % 360);
|
199 |
angles.push_back(i % 360);
|
199 |
|
200 |
|
200 |
QMetaObject::invokeMethod(captureWorker, "acquireCalibrationSets", Q_ARG(std::vector<float>, angles));
|
201 |
QMetaObject::invokeMethod(captureWorker, "acquireCalibrationSets", Q_ARG(std::vector<float>, angles));
|
201 |
|
202 |
|
202 |
std::cout << "Aquiring sets at ";
|
203 |
std::cout << "Aquiring sets at ";
|
203 |
for(unsigned int i=0; i<angles.size(); i++)
|
204 |
for(unsigned int i=0; i<angles.size(); i++)
|
204 |
std::cout << angles[i] << " ";
|
205 |
std::cout << angles[i] << " ";
|
205 |
std::cout << " degrees" <<std::endl;
|
206 |
std::cout << " degrees" <<std::endl;
|
206 |
}
|
207 |
}
|
207 |
|
208 |
|
208 |
|
209 |
|
209 |
void SMScanner::on_calibrationRotationDial_sliderReleased(){
|
210 |
void SMScanner::on_calibrationRotationDial_sliderReleased(){
|
210 |
|
211 |
|
211 |
float angle = ui->calibrationRotationDial->value();
|
212 |
float angle = ui->calibrationRotationDial->value();
|
212 |
std::cout << "Rotation stage target: " << angle << std::endl;
|
213 |
std::cout << "Rotation stage target: " << angle << std::endl;
|
213 |
QMetaObject::invokeMethod(captureWorker, "rotateTo", Q_ARG(float, angle));
|
214 |
QMetaObject::invokeMethod(captureWorker, "rotateTo", Q_ARG(float, angle));
|
214 |
|
215 |
|
215 |
ui->calibrationRotationSpinBox->setValue(angle);
|
216 |
ui->calibrationRotationSpinBox->setValue(angle);
|
216 |
|
217 |
|
217 |
ui->captureRotationDial->setValue(angle);
|
218 |
ui->captureRotationDial->setValue(angle);
|
218 |
ui->captureRotationSpinBox->setValue(angle);
|
219 |
ui->captureRotationSpinBox->setValue(angle);
|
219 |
}
|
220 |
}
|
220 |
|
221 |
|
221 |
|
222 |
|
222 |
void SMScanner::on_calibrationRotationSpinBox_editingFinished(){
|
223 |
void SMScanner::on_calibrationRotationSpinBox_editingFinished(){
|
223 |
|
224 |
|
224 |
float angle = ui->calibrationRotationSpinBox->value();
|
225 |
float angle = ui->calibrationRotationSpinBox->value();
|
225 |
std::cout << "Rotation stage target: " << angle << std::endl;
|
226 |
std::cout << "Rotation stage target: " << angle << std::endl;
|
226 |
QMetaObject::invokeMethod(captureWorker, "rotateTo", Q_ARG(float, angle));
|
227 |
QMetaObject::invokeMethod(captureWorker, "rotateTo", Q_ARG(float, angle));
|
227 |
|
228 |
|
228 |
ui->calibrationRotationDial->setValue(angle);
|
229 |
ui->calibrationRotationDial->setValue(angle);
|
229 |
|
230 |
|
230 |
ui->captureRotationSpinBox->setValue(angle);
|
231 |
ui->captureRotationSpinBox->setValue(angle);
|
231 |
ui->captureRotationDial->setValue(angle);
|
232 |
ui->captureRotationDial->setValue(angle);
|
232 |
}
|
233 |
}
|
233 |
|
234 |
|
234 |
void SMScanner::onReceiveCalibrationSet(SMCalibrationSet calibrationSet){
|
235 |
void SMScanner::onReceiveCalibrationSet(SMCalibrationSet calibrationSet){
|
235 |
|
236 |
|
236 |
// Send to checkerboard detection on calibration thread
|
237 |
// Send to checkerboard detection on calibration thread
|
237 |
QMetaObject::invokeMethod(calibrationWorker, "checkerboardDetection", Q_ARG(SMCalibrationSet, calibrationSet));
|
238 |
QMetaObject::invokeMethod(calibrationWorker, "checkerboardDetection", Q_ARG(SMCalibrationSet, calibrationSet));
|
238 |
|
239 |
|
239 |
}
|
240 |
}
|
240 |
|
241 |
|
241 |
void SMScanner::on_calibrateCamerasButton_clicked(){
|
242 |
void SMScanner::on_calibrateCamerasButton_clicked(){
|
242 |
|
243 |
|
243 |
// disable ui elements
|
244 |
// disable ui elements
|
244 |
ui->calibrateCamerasButton->setEnabled(false);
|
245 |
ui->calibrateCamerasButton->setEnabled(false);
|
245 |
ui->calibrateRotationStageButton->setEnabled(false);
|
246 |
ui->calibrateRotationStageButton->setEnabled(false);
|
246 |
ui->calibrationFrame->setEnabled(false);
|
247 |
ui->calibrationFrame->setEnabled(false);
|
247 |
|
248 |
|
248 |
// if none items are selected, we will use all available items
|
249 |
// if none items are selected, we will use all available items
|
249 |
if(ui->calibrationListWidget->selectedItems().empty())
|
250 |
if(ui->calibrationListWidget->selectedItems().empty())
|
250 |
ui->calibrationListWidget->selectAll();
|
251 |
ui->calibrationListWidget->selectAll();
|
251 |
|
252 |
|
252 |
// set selected flags
|
253 |
// set selected flags
|
253 |
for(unsigned int i=0; i<calibrationData.size(); i++){
|
254 |
for(unsigned int i=0; i<calibrationData.size(); i++){
|
254 |
if(ui->calibrationListWidget->item(i)->isSelected())
|
255 |
if(ui->calibrationListWidget->item(i)->isSelected())
|
255 |
calibrationData[i].selected = true;
|
256 |
calibrationData[i].selected = true;
|
256 |
else
|
257 |
else
|
257 |
calibrationData[i].selected = false;
|
258 |
calibrationData[i].selected = false;
|
258 |
}
|
259 |
}
|
259 |
|
260 |
|
260 |
logDialog.show();
|
261 |
logDialog.show();
|
261 |
|
262 |
|
262 |
// start calibration
|
263 |
// start calibration
|
263 |
QMetaObject::invokeMethod(calibrationWorker, "cameraCalibration", Q_ARG(std::vector<SMCalibrationSet>, calibrationData));
|
264 |
QMetaObject::invokeMethod(calibrationWorker, "cameraCalibration", Q_ARG(std::vector<SMCalibrationSet>, calibrationData));
|
264 |
|
265 |
|
265 |
}
|
266 |
}
|
266 |
|
267 |
|
267 |
void SMScanner::onReceiveCheckerboardResult(int idx, SMCalibrationSet calibrationSet){
|
268 |
void SMScanner::onReceiveCheckerboardResult(int idx, SMCalibrationSet calibrationSet){
|
268 |
|
269 |
|
269 |
int id = ui->calibrationListWidget->count();
|
270 |
int id = ui->calibrationListWidget->count();
|
270 |
calibrationSet.id = id;
|
271 |
calibrationSet.id = id;
|
271 |
|
272 |
|
272 |
calibrationData.push_back(calibrationSet);
|
273 |
calibrationData.push_back(calibrationSet);
|
273 |
|
274 |
|
274 |
// Add identifier to list
|
275 |
// Add identifier to list
|
275 |
QListWidgetItem* item = new QListWidgetItem(QString("Calibration Set %1 -- %2 deg").arg(id).arg(calibrationSet.rotationAngle), ui->calibrationListWidget);
|
276 |
QListWidgetItem* item = new QListWidgetItem(QString("Calibration Set %1 -- %2 deg").arg(id).arg(calibrationSet.rotationAngle), ui->calibrationListWidget);
|
276 |
ui->calibrationListWidget->addItem(item);
|
277 |
ui->calibrationListWidget->addItem(item);
|
277 |
item->setSelected(true);
|
278 |
item->setSelected(true);
|
278 |
ui->calibrationListWidget->setCurrentItem(item);
|
279 |
ui->calibrationListWidget->setCurrentItem(item);
|
279 |
|
280 |
|
280 |
// Enable calibration button
|
281 |
// Enable calibration button
|
281 |
if(calibrationData.size() >= 2){
|
282 |
if(calibrationData.size() >= 2){
|
282 |
ui->calibrateCamerasButton->setEnabled(true);
|
283 |
ui->calibrateCamerasButton->setEnabled(true);
|
283 |
ui->calibrateRotationStageButton->setEnabled(true);
|
284 |
ui->calibrateRotationStageButton->setEnabled(true);
|
284 |
}
|
285 |
}
|
285 |
|
286 |
|
286 |
//ui->calibrationListWidget->setCurrentRow(idx);
|
287 |
//ui->calibrationListWidget->setCurrentRow(idx);
|
287 |
}
|
288 |
}
|
288 |
|
289 |
|
289 |
void SMScanner::onReceiveCalibrationDone(){
|
290 |
void SMScanner::onReceiveCalibrationDone(){
|
290 |
|
291 |
|
291 |
std::cout << "Calibration done!" << std::endl;
|
292 |
std::cout << "Calibration done!" << std::endl;
|
292 |
ui->calibrateCamerasButton->setEnabled(true);
|
293 |
ui->calibrateCamerasButton->setEnabled(true);
|
293 |
ui->calibrateRotationStageButton->setEnabled(true);
|
294 |
ui->calibrateRotationStageButton->setEnabled(true);
|
294 |
ui->calibrationFrame->setEnabled(true);
|
295 |
ui->calibrationFrame->setEnabled(true);
|
295 |
|
296 |
|
296 |
}
|
297 |
}
|
297 |
|
298 |
|
298 |
void SMScanner::on_calibrationListWidget_itemSelectionChanged(){
|
299 |
void SMScanner::on_calibrationListWidget_itemSelectionChanged(){
|
299 |
|
300 |
|
300 |
// if selection is just cleared
|
301 |
// if selection is just cleared
|
301 |
if(ui->calibrationListWidget->selectedItems().empty())
|
302 |
if(ui->calibrationListWidget->selectedItems().empty())
|
302 |
return;
|
303 |
return;
|
303 |
|
304 |
|
304 |
calibrationReviewMode = true;
|
305 |
calibrationReviewMode = true;
|
305 |
ui->singleCalibrationButton->setText("Live View");
|
306 |
ui->singleCalibrationButton->setText("Live View");
|
306 |
ui->batchCalibrationButton->setText("Live View");
|
307 |
ui->batchCalibrationButton->setText("Live View");
|
307 |
|
308 |
|
308 |
int currentRow = ui->calibrationListWidget->currentRow();
|
309 |
int currentRow = ui->calibrationListWidget->currentRow();
|
309 |
if(currentRow < 0)
|
310 |
if(currentRow < 0)
|
310 |
return;
|
311 |
return;
|
311 |
|
312 |
|
312 |
assert(currentRow < (int)calibrationData.size());
|
313 |
assert(currentRow < (int)calibrationData.size());
|
313 |
|
314 |
|
314 |
// if checkerboard results are available, show them, otherwise show the frame
|
315 |
// if checkerboard results are available, show them, otherwise show the frame
|
315 |
if(calibrationData[currentRow].frame0Result.empty())
|
316 |
if(calibrationData[currentRow].frame0Result.empty())
|
316 |
ui->calibrationCamera0Widget->showImageCV(calibrationData[currentRow].frame0);
|
317 |
ui->calibrationCamera0Widget->showImageCV(calibrationData[currentRow].frame0);
|
317 |
else
|
318 |
else
|
318 |
ui->calibrationCamera0Widget->showImageCV(calibrationData[currentRow].frame0Result);
|
319 |
ui->calibrationCamera0Widget->showImageCV(calibrationData[currentRow].frame0Result);
|
319 |
|
320 |
|
320 |
if(calibrationData[currentRow].frame1Result.empty())
|
321 |
if(calibrationData[currentRow].frame1Result.empty())
|
321 |
ui->calibrationCamera1Widget->showImageCV(calibrationData[currentRow].frame1);
|
322 |
ui->calibrationCamera1Widget->showImageCV(calibrationData[currentRow].frame1);
|
322 |
else
|
323 |
else
|
323 |
ui->calibrationCamera1Widget->showImageCV(calibrationData[currentRow].frame1Result);
|
324 |
ui->calibrationCamera1Widget->showImageCV(calibrationData[currentRow].frame1Result);
|
324 |
|
325 |
|
325 |
}
|
326 |
}
|
326 |
|
327 |
|
327 |
void SMScanner::on_captureRotationDial_sliderReleased(){
|
328 |
void SMScanner::on_captureRotationDial_sliderReleased(){
|
328 |
|
329 |
|
329 |
float angle = ui->captureRotationDial->value();
|
330 |
float angle = ui->captureRotationDial->value();
|
330 |
std::cout << "Rotation stage target: " << angle << std::endl;
|
331 |
std::cout << "Rotation stage target: " << angle << std::endl;
|
331 |
QMetaObject::invokeMethod(captureWorker, "rotateTo", Q_ARG(float, angle));
|
332 |
QMetaObject::invokeMethod(captureWorker, "rotateTo", Q_ARG(float, angle));
|
332 |
|
333 |
|
333 |
ui->captureRotationSpinBox->setValue(ui->captureRotationDial->value());
|
334 |
ui->captureRotationSpinBox->setValue(ui->captureRotationDial->value());
|
334 |
|
335 |
|
335 |
ui->calibrationRotationDial->setValue(ui->captureRotationDial->value());
|
336 |
ui->calibrationRotationDial->setValue(ui->captureRotationDial->value());
|
336 |
ui->calibrationRotationSpinBox->setValue(ui->captureRotationDial->value());
|
337 |
ui->calibrationRotationSpinBox->setValue(ui->captureRotationDial->value());
|
337 |
}
|
338 |
}
|
338 |
|
339 |
|
339 |
void SMScanner::on_captureRotationSpinBox_editingFinished(){
|
340 |
void SMScanner::on_captureRotationSpinBox_editingFinished(){
|
340 |
|
341 |
|
341 |
float angle = ui->captureRotationSpinBox->value();
|
342 |
float angle = ui->captureRotationSpinBox->value();
|
342 |
std::cout << "Rotation stage target: " << angle << std::endl;
|
343 |
std::cout << "Rotation stage target: " << angle << std::endl;
|
343 |
QMetaObject::invokeMethod(captureWorker, "rotateTo", Q_ARG(float, angle));
|
344 |
QMetaObject::invokeMethod(captureWorker, "rotateTo", Q_ARG(float, angle));
|
344 |
|
345 |
|
345 |
ui->captureRotationDial->setValue(angle);
|
346 |
ui->captureRotationDial->setValue(angle);
|
346 |
|
347 |
|
347 |
ui->calibrationRotationSpinBox->setValue(angle);
|
348 |
ui->calibrationRotationSpinBox->setValue(angle);
|
348 |
ui->calibrationRotationDial->setValue(angle);
|
349 |
ui->calibrationRotationDial->setValue(angle);
|
349 |
}
|
350 |
}
|
350 |
|
351 |
|
351 |
void SMScanner::on_singleCaptureButton_clicked(){
|
352 |
void SMScanner::on_singleCaptureButton_clicked(){
|
352 |
|
353 |
|
353 |
// If in review mode, go back to aquisition mode
|
354 |
// If in review mode, go back to aquisition mode
|
354 |
if(captureReviewMode){
|
355 |
if(captureReviewMode){
|
355 |
ui->captureTreeWidget->clearSelection();
|
356 |
ui->captureTreeWidget->clearSelection();
|
356 |
ui->singleCaptureButton->setText("Single Aquisition");
|
357 |
ui->singleCaptureButton->setText("Single Aquisition");
|
357 |
ui->batchCaptureButton->setText("Batch Aquisition");
|
358 |
ui->batchCaptureButton->setText("Batch Aquisition");
|
358 |
captureReviewMode = false;
|
359 |
captureReviewMode = false;
|
359 |
return;
|
360 |
return;
|
360 |
}
|
361 |
}
|
361 |
|
362 |
|
362 |
QMetaObject::invokeMethod(captureWorker, "acquireFrameSequence", Q_ARG(float, -1.0));
|
363 |
QMetaObject::invokeMethod(captureWorker, "acquireFrameSequence", Q_ARG(float, -1.0));
|
363 |
|
364 |
|
364 |
}
|
365 |
}
|
365 |
|
366 |
|
366 |
|
367 |
|
367 |
void SMScanner::on_batchCaptureButton_clicked(){
|
368 |
void SMScanner::on_batchCaptureButton_clicked(){
|
368 |
|
369 |
|
369 |
// If in review mode, go back to aquisition mode
|
370 |
// If in review mode, go back to aquisition mode
|
370 |
if(captureReviewMode){
|
371 |
if(captureReviewMode){
|
371 |
ui->captureTreeWidget->clearSelection();
|
372 |
ui->captureTreeWidget->clearSelection();
|
372 |
ui->singleCaptureButton->setText("Single Aquisition");
|
373 |
ui->singleCaptureButton->setText("Single Aquisition");
|
373 |
ui->batchCaptureButton->setText("Batch Aquisition");
|
374 |
ui->batchCaptureButton->setText("Batch Aquisition");
|
374 |
captureReviewMode = false;
|
375 |
captureReviewMode = false;
|
375 |
return;
|
376 |
return;
|
376 |
}
|
377 |
}
|
377 |
|
378 |
|
378 |
// Construct vector of angles
|
379 |
// Construct vector of angles
|
379 |
int angleStart = ui->captureBatchStartSpinBox->value();
|
380 |
int angleStart = ui->captureBatchStartSpinBox->value();
|
380 |
int angleEnd = ui->captureBatchEndSpinBox->value();
|
381 |
int angleEnd = ui->captureBatchEndSpinBox->value();
|
381 |
int angleStep = ui->captureBatchStepSpinBox->value();
|
382 |
int angleStep = ui->captureBatchStepSpinBox->value();
|
382 |
|
383 |
|
383 |
if(angleStart > angleEnd)
|
384 |
if(angleStart > angleEnd)
|
384 |
angleEnd += 360;
|
385 |
angleEnd += 360;
|
385 |
|
386 |
|
386 |
std::vector<float> angles;
|
387 |
std::vector<float> angles;
|
387 |
for(int i=angleStart; i<=angleEnd; i+=angleStep)
|
388 |
for(int i=angleStart; i<=angleEnd; i+=angleStep)
|
388 |
angles.push_back(i % 360);
|
389 |
angles.push_back(i % 360);
|
389 |
|
390 |
|
390 |
std::cout << "Aquiring sequences at ";
|
391 |
std::cout << "Aquiring sequences at ";
|
391 |
for(unsigned int i=0; i<angles.size(); i++)
|
392 |
for(unsigned int i=0; i<angles.size(); i++)
|
392 |
std::cout << angles[i] << " ";
|
393 |
std::cout << angles[i] << " ";
|
393 |
std::cout << " degrees" <<std::endl;
|
394 |
std::cout << " degrees" <<std::endl;
|
394 |
|
395 |
|
395 |
QMetaObject::invokeMethod(captureWorker, "acquireFrameSequences", Q_ARG(std::vector<float>, angles));
|
396 |
QMetaObject::invokeMethod(captureWorker, "acquireFrameSequences", Q_ARG(std::vector<float>, angles));
|
396 |
}
|
397 |
}
|
397 |
|
398 |
|
398 |
void SMScanner::onReceiveFrameSequence(SMFrameSequence frameSequence){
|
399 |
void SMScanner::onReceiveFrameSequence(SMFrameSequence frameSequence){
|
399 |
|
400 |
|
400 |
frameSequence.id = ++lastCaptureId;
|
401 |
frameSequence.id = ++lastCaptureId;
|
401 |
|
402 |
|
402 |
// Add identifier to list
|
403 |
// Add identifier to list
|
403 |
QTreeWidgetItem* item = new QTreeWidgetItem(ui->captureTreeWidget);
|
404 |
QTreeWidgetItem* item = new QTreeWidgetItem(ui->captureTreeWidget);
|
404 |
item->setText(0, QString("Frame Sequence %1 -- %2 deg").arg(frameSequence.id).arg(frameSequence.rotationAngle));
|
405 |
item->setText(0, QString("Frame Sequence %1 -- %2 deg").arg(frameSequence.id).arg(frameSequence.rotationAngle));
|
405 |
//item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
406 |
//item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
406 |
item->setData(0, Qt::UserRole, QPoint(frameSequence.id, -1));
|
407 |
item->setData(0, Qt::UserRole, QPoint(frameSequence.id, -1));
|
407 |
//item->setCheckState(0, Qt::Checked);
|
408 |
//item->setCheckState(0, Qt::Checked);
|
408 |
//ui->captureTreeWidget->addItem(item);
|
409 |
//ui->captureTreeWidget->addItem(item);
|
409 |
|
410 |
|
410 |
for(unsigned int i=0; i<frameSequence.frames0.size(); i++){
|
411 |
for(unsigned int i=0; i<frameSequence.frames0.size(); i++){
|
411 |
QTreeWidgetItem* subItem = new QTreeWidgetItem(item);
|
412 |
QTreeWidgetItem* subItem = new QTreeWidgetItem(item);
|
412 |
subItem->setText(0, QString("frames %1").arg(i));
|
413 |
subItem->setText(0, QString("frames %1").arg(i));
|
413 |
subItem->setData(0, Qt::UserRole, QPoint(frameSequence.id, i));
|
414 |
subItem->setData(0, Qt::UserRole, QPoint(frameSequence.id, i));
|
414 |
}
|
415 |
}
|
415 |
|
416 |
|
416 |
// Indicate that the current item is currently reconstructing
|
417 |
// Indicate that the current item is currently reconstructing
|
417 |
item->setTextColor(0, QColor(128, 128, 128));
|
418 |
item->setTextColor(0, QColor(128, 128, 128));
|
418 |
item->setIcon(0, QIcon::fromTheme("system-run"));
|
419 |
item->setIcon(0, QIcon::fromTheme("system-run"));
|
419 |
|
420 |
|
420 |
// Reconstruct the frame sequence
|
421 |
// Reconstruct the frame sequence
|
421 |
//QMetaObject::invokeMethod(reconstructionWorker, "reconstructPointCloud", Q_ARG(SMFrameSequence, frameSequence));
|
422 |
//QMetaObject::invokeMethod(reconstructionWorker, "reconstructPointCloud", Q_ARG(SMFrameSequence, frameSequence));
|
422 |
frameSequence.reconstructed = true;
|
423 |
frameSequence.reconstructed = true;
|
423 |
|
424 |
|
424 |
captureData.push_back(frameSequence);
|
425 |
captureData.push_back(frameSequence);
|
425 |
|
426 |
|
426 |
}
|
427 |
}
|
427 |
|
428 |
|
428 |
void SMScanner::on_captureTreeWidget_itemSelectionChanged(){
|
429 |
void SMScanner::on_captureTreeWidget_itemSelectionChanged(){
|
429 |
|
430 |
|
430 |
// if selection is just cleared
|
431 |
// if selection is just cleared
|
431 |
if(ui->captureTreeWidget->selectedItems().empty())
|
432 |
if(ui->captureTreeWidget->selectedItems().empty())
|
432 |
return;
|
433 |
return;
|
433 |
|
434 |
|
434 |
QTreeWidgetItem *item = ui->captureTreeWidget->currentItem();
|
435 |
QTreeWidgetItem *item = ui->captureTreeWidget->currentItem();
|
435 |
|
436 |
|
436 |
captureReviewMode = true;
|
437 |
captureReviewMode = true;
|
437 |
|
438 |
|
438 |
ui->singleCaptureButton->setText("Live View");
|
439 |
ui->singleCaptureButton->setText("Live View");
|
439 |
ui->batchCaptureButton->setText("Live View");
|
440 |
ui->batchCaptureButton->setText("Live View");
|
440 |
|
441 |
|
441 |
QPoint idx = item->data(0, Qt::UserRole).toPoint();
|
442 |
QPoint idx = item->data(0, Qt::UserRole).toPoint();
|
442 |
|
443 |
|
443 |
if( idx.y() != -1 && idx.x()>=0 && idx.x()<(int)captureData.size()
|
444 |
if( idx.y() != -1 && idx.x()>=0 && idx.x()<(int)captureData.size()
|
444 |
&& idx.y()<(int)captureData[idx.x()].frames0.size()
|
445 |
&& idx.y()<(int)captureData[idx.x()].frames0.size()
|
445 |
&& idx.y()<(int)captureData[idx.x()].frames1.size() ){
|
446 |
&& idx.y()<(int)captureData[idx.x()].frames1.size() ){
|
446 |
// TODO idx.x() can & WILL be out of bounds
|
447 |
// TODO idx.x() can & WILL be out of bounds
|
447 |
ui->captureCamera0Widget->showImageCV(captureData[idx.x()].frames0[idx.y()]);
|
448 |
ui->captureCamera0Widget->showImageCV(captureData[idx.x()].frames0[idx.y()]);
|
448 |
ui->captureCamera1Widget->showImageCV(captureData[idx.x()].frames1[idx.y()]);
|
449 |
ui->captureCamera1Widget->showImageCV(captureData[idx.x()].frames1[idx.y()]);
|
449 |
}
|
450 |
}
|
450 |
|
451 |
|
451 |
// std::cout << "on_captureTreeWidget_itemSelectionChanged" << std::endl;
|
452 |
// std::cout << "on_captureTreeWidget_itemSelectionChanged" << std::endl;
|
452 |
}
|
453 |
}
|
453 |
|
454 |
|
454 |
|
455 |
|
455 |
void SMScanner::onReceiveRotatedTo(float angle){
|
456 |
void SMScanner::onReceiveRotatedTo(float angle){
|
456 |
|
457 |
|
457 |
// update ui with new position
|
458 |
// update ui with new position
|
458 |
ui->calibrationRotationDial->setValue(angle);
|
459 |
ui->calibrationRotationDial->setValue(angle);
|
459 |
ui->captureRotationDial->setValue(angle);
|
460 |
ui->captureRotationDial->setValue(angle);
|
460 |
|
461 |
|
461 |
ui->calibrationRotationSpinBox->setValue(angle);
|
462 |
ui->calibrationRotationSpinBox->setValue(angle);
|
462 |
ui->captureRotationSpinBox->setValue(angle);
|
463 |
ui->captureRotationSpinBox->setValue(angle);
|
463 |
}
|
464 |
}
|
464 |
|
465 |
|
465 |
void SMScanner::on_actionExport_Sets_triggered(){
|
466 |
void SMScanner::on_actionExport_Sets_triggered(){
|
466 |
|
467 |
|
467 |
QString dirName = QFileDialog::getExistingDirectory(this, "Export calibration sets", QString());
|
468 |
QString dirName = QFileDialog::getExistingDirectory(this, "Export calibration sets", QString());
|
468 |
|
469 |
|
469 |
QProgressDialog progressDialog("Exporting Sets...", "Cancel", 0, 100, this);
|
470 |
QProgressDialog progressDialog("Exporting Sets...", "Cancel", 0, 100, this);
|
470 |
progressDialog.setWindowModality(Qt::WindowModal);
|
471 |
progressDialog.setWindowModality(Qt::WindowModal);
|
471 |
progressDialog.setMinimumDuration(1000);
|
472 |
progressDialog.setMinimumDuration(1000);
|
472 |
|
473 |
|
473 |
progressDialog.show();
|
474 |
progressDialog.show();
|
474 |
cv::Mat frameBGR;
|
475 |
cv::Mat frameBGR;
|
475 |
for(unsigned int i=0; i<calibrationData.size(); i++){
|
476 |
for(unsigned int i=0; i<calibrationData.size(); i++){
|
476 |
QString fileName = QString("%1/frame0_%2.png").arg(dirName).arg(i);
|
477 |
QString fileName = QString("%1/frame0_%2.png").arg(dirName).arg(i);
|
477 |
|
478 |
|
478 |
progressDialog.setValue(100.0*i/calibrationData.size());
|
479 |
progressDialog.setValue(100.0*i/calibrationData.size());
|
479 |
|
480 |
|
480 |
// Convert to BGR
|
481 |
// Convert to BGR
|
481 |
if(calibrationData[i].frame0.channels() == 1)
|
482 |
if(calibrationData[i].frame0.channels() == 1)
|
482 |
cv::cvtColor(calibrationData[i].frame0, frameBGR, CV_BayerBG2BGR);
|
483 |
cv::cvtColor(calibrationData[i].frame0, frameBGR, CV_BayerBG2BGR);
|
483 |
else
|
484 |
else
|
484 |
cv::cvtColor(calibrationData[i].frame1, frameBGR, CV_RGB2BGR);
|
485 |
cv::cvtColor(calibrationData[i].frame1, frameBGR, CV_RGB2BGR);
|
485 |
|
486 |
|
486 |
cv::imwrite(fileName.toStdString(), frameBGR);
|
487 |
cv::imwrite(fileName.toStdString(), frameBGR);
|
487 |
fileName = QString("%1/frame1_%2.png").arg(dirName).arg(i);
|
488 |
fileName = QString("%1/frame1_%2.png").arg(dirName).arg(i);
|
488 |
|
489 |
|
489 |
// Convert to BGR
|
490 |
// Convert to BGR
|
490 |
if(calibrationData[i].frame1.channels() == 1)
|
491 |
if(calibrationData[i].frame1.channels() == 1)
|
491 |
cv::cvtColor(calibrationData[i].frame1, frameBGR, CV_BayerBG2BGR);
|
492 |
cv::cvtColor(calibrationData[i].frame1, frameBGR, CV_BayerBG2BGR);
|
492 |
else
|
493 |
else
|
493 |
cv::cvtColor(calibrationData[i].frame1, frameBGR, CV_RGB2BGR);
|
494 |
cv::cvtColor(calibrationData[i].frame1, frameBGR, CV_RGB2BGR);
|
494 |
|
495 |
|
495 |
cv::imwrite(fileName.toStdString(), frameBGR);
|
496 |
cv::imwrite(fileName.toStdString(), frameBGR);
|
496 |
|
497 |
|
497 |
// Necessary to prevent pileup of video frame signals
|
498 |
// Necessary to prevent pileup of video frame signals
|
498 |
QCoreApplication::processEvents();
|
499 |
QCoreApplication::processEvents();
|
499 |
|
500 |
|
500 |
if(progressDialog.wasCanceled())
|
501 |
if(progressDialog.wasCanceled())
|
501 |
return;
|
502 |
return;
|
502 |
}
|
503 |
}
|
503 |
|
504 |
|
504 |
}
|
505 |
}
|
505 |
|
506 |
|
506 |
void SMScanner::on_actionExport_Sequences_triggered(){
|
507 |
void SMScanner::on_actionExport_Sequences_triggered(){
|
507 |
|
508 |
|
508 |
QString dirName = QFileDialog::getExistingDirectory(this, "Export frame sequences", QString());
|
509 |
QString dirName = QFileDialog::getExistingDirectory(this, "Export frame sequences", QString());
|
509 |
|
510 |
|
510 |
QProgressDialog progressDialog("Exporting Sequences...", "Cancel", 0, 100, this);
|
511 |
QProgressDialog progressDialog("Exporting Sequences...", "Cancel", 0, 100, this);
|
511 |
progressDialog.setWindowModality(Qt::WindowModal);
|
512 |
progressDialog.setWindowModality(Qt::WindowModal);
|
512 |
progressDialog.setMinimumDuration(1000);
|
513 |
progressDialog.setMinimumDuration(1000);
|
513 |
|
514 |
|
514 |
progressDialog.show();
|
515 |
progressDialog.show();
|
515 |
|
516 |
|
516 |
cv::Mat frameBGR;
|
517 |
cv::Mat frameBGR;
|
517 |
for(unsigned int i=0; i<captureData.size(); i++){
|
518 |
for(unsigned int i=0; i<captureData.size(); i++){
|
518 |
|
519 |
|
519 |
QString format;
|
520 |
QString format;
|
520 |
if(captureData[i].frames0[0].depth() == CV_32F)
|
521 |
if(captureData[i].frames0[0].depth() == CV_32F)
|
521 |
format = "hdr";
|
522 |
format = "hdr";
|
522 |
else
|
523 |
else
|
523 |
format = "png";
|
524 |
format = "png";
|
524 |
|
525 |
|
525 |
QString seqDirName = QString("%1/sequence_%2").arg(dirName).arg(i);
|
526 |
QString seqDirName = QString("%1/sequence_%2").arg(dirName).arg(i);
|
526 |
if(!QDir().mkdir(seqDirName))
|
527 |
if(!QDir().mkdir(seqDirName))
|
527 |
std::cerr << "Could not create directory " << seqDirName.toStdString() << std::endl;
|
528 |
std::cerr << "Could not create directory " << seqDirName.toStdString() << std::endl;
|
528 |
for(unsigned int j=0; j<captureData[i].frames0.size(); j++){
|
529 |
for(unsigned int j=0; j<captureData[i].frames0.size(); j++){
|
529 |
|
530 |
|
530 |
progressDialog.setValue(100.0*i/captureData.size() + 100.0/captureData.size()*j/captureData[i].frames0.size());
|
531 |
progressDialog.setValue(100.0*i/captureData.size() + 100.0/captureData.size()*j/captureData[i].frames0.size());
|
531 |
|
532 |
|
532 |
QString fileName0 = QString("%1/frames0_%2.%3").arg(seqDirName).arg(j).arg(format);
|
533 |
QString fileName0 = QString("%1/frames0_%2.%3").arg(seqDirName).arg(j).arg(format);
|
533 |
// Convert Bayer to rgb (png needs BGR order)
|
534 |
// Convert Bayer to rgb (png needs BGR order)
|
534 |
cv::cvtColor(captureData[i].frames0[j], frameBGR, CV_BayerBG2BGR);
|
535 |
cv::cvtColor(captureData[i].frames0[j], frameBGR, CV_BayerBG2BGR);
|
535 |
cv::imwrite(fileName0.toStdString(), frameBGR);
|
536 |
cv::imwrite(fileName0.toStdString(), frameBGR);
|
536 |
|
537 |
|
537 |
// Necessary to prevent pileup of video frame signals
|
538 |
// Necessary to prevent pileup of video frame signals
|
538 |
QCoreApplication::processEvents();
|
539 |
QCoreApplication::processEvents();
|
539 |
|
540 |
|
540 |
QString fileName1 = QString("%1/frames1_%2.%3").arg(seqDirName).arg(j).arg(format);
|
541 |
QString fileName1 = QString("%1/frames1_%2.%3").arg(seqDirName).arg(j).arg(format);
|
541 |
// Convert Bayer to rgb (png needs BGR order)
|
542 |
// Convert Bayer to rgb (png needs BGR order)
|
542 |
cv::cvtColor(captureData[i].frames1[j], frameBGR, CV_BayerBG2BGR);
|
543 |
cv::cvtColor(captureData[i].frames1[j], frameBGR, CV_BayerBG2BGR);
|
543 |
cv::imwrite(fileName1.toStdString(), frameBGR);
|
544 |
cv::imwrite(fileName1.toStdString(), frameBGR);
|
544 |
|
545 |
|
545 |
// Necessary to prevent pileup of video frame signals
|
546 |
// Necessary to prevent pileup of video frame signals
|
546 |
QCoreApplication::processEvents();
|
547 |
QCoreApplication::processEvents();
|
547 |
if(progressDialog.wasCanceled())
|
548 |
if(progressDialog.wasCanceled())
|
548 |
return;
|
549 |
return;
|
549 |
}
|
550 |
}
|
550 |
}
|
551 |
}
|
551 |
}
|
552 |
}
|
552 |
|
553 |
|
553 |
void SMScanner::on_actionExport_White_Frames_triggered(){
|
554 |
void SMScanner::on_actionExport_White_Frames_triggered(){
|
554 |
|
555 |
|
555 |
QString dirName = QFileDialog::getExistingDirectory(this, "Export frame sequences", QString());
|
556 |
QString dirName = QFileDialog::getExistingDirectory(this, "Export frame sequences", QString());
|
556 |
|
557 |
|
557 |
QProgressDialog progressDialog("Exporting White Frames...", "Cancel", 0, 100, this);
|
558 |
QProgressDialog progressDialog("Exporting White Frames...", "Cancel", 0, 100, this);
|
558 |
progressDialog.setWindowModality(Qt::WindowModal);
|
559 |
progressDialog.setWindowModality(Qt::WindowModal);
|
559 |
progressDialog.setMinimumDuration(1000);
|
560 |
progressDialog.setMinimumDuration(1000);
|
560 |
|
561 |
|
561 |
cv::Mat frameBGR;
|
562 |
cv::Mat frameBGR;
|
562 |
for(unsigned int i=0; i<captureData.size(); i++){
|
563 |
for(unsigned int i=0; i<captureData.size(); i++){
|
563 |
|
564 |
|
564 |
progressDialog.setValue(100.0*i/captureData.size());
|
565 |
progressDialog.setValue(100.0*i/captureData.size());
|
565 |
|
566 |
|
566 |
QString seqDirName = QString("%1/sequence_%2").arg(dirName).arg(i);
|
567 |
QString seqDirName = QString("%1/sequence_%2").arg(dirName).arg(i);
|
567 |
if(!QDir().mkdir(seqDirName))
|
568 |
if(!QDir().mkdir(seqDirName))
|
568 |
std::cerr << "Could not create directory " << seqDirName.toStdString() << std::endl;
|
569 |
std::cerr << "Could not create directory " << seqDirName.toStdString() << std::endl;
|
569 |
|
570 |
|
570 |
QString fileName = QString("%1/frames0_0.png").arg(seqDirName);
|
571 |
QString fileName = QString("%1/frames0_0.png").arg(seqDirName);
|
571 |
// Convert Bayer to rgb (png needs BGR order)
|
572 |
// Convert Bayer to rgb (png needs BGR order)
|
572 |
cv::cvtColor(captureData[i].frames0[0], frameBGR, CV_BayerBG2BGR);
|
573 |
cv::cvtColor(captureData[i].frames0[0], frameBGR, CV_BayerBG2BGR);
|
573 |
cv::imwrite(fileName.toStdString(), frameBGR);
|
574 |
cv::imwrite(fileName.toStdString(), frameBGR);
|
574 |
// Necessary to prevent memory pileup
|
575 |
// Necessary to prevent memory pileup
|
575 |
QCoreApplication::processEvents();
|
576 |
QCoreApplication::processEvents();
|
576 |
|
577 |
|
577 |
fileName = QString("%1/frames1_0.png").arg(seqDirName);
|
578 |
fileName = QString("%1/frames1_0.png").arg(seqDirName);
|
578 |
// Convert Bayer to rgb (png needs BGR order)
|
579 |
// Convert Bayer to rgb (png needs BGR order)
|
579 |
cv::cvtColor(captureData[i].frames1[0], frameBGR, CV_BayerBG2BGR);
|
580 |
cv::cvtColor(captureData[i].frames1[0], frameBGR, CV_BayerBG2BGR);
|
580 |
cv::imwrite(fileName.toStdString(), frameBGR);
|
581 |
cv::imwrite(fileName.toStdString(), frameBGR);
|
581 |
// Necessary to prevent memory pileup
|
582 |
// Necessary to prevent memory pileup
|
582 |
QCoreApplication::processEvents();
|
583 |
QCoreApplication::processEvents();
|
583 |
if(progressDialog.wasCanceled())
|
584 |
if(progressDialog.wasCanceled())
|
584 |
return;
|
585 |
return;
|
585 |
}
|
586 |
}
|
586 |
|
587 |
|
587 |
}
|
588 |
}
|
588 |
|
589 |
|
589 |
|
590 |
|
590 |
void SMScanner::onReceivePointCloud(SMPointCloud smCloud){
|
591 |
void SMScanner::onReceivePointCloud(SMPointCloud smCloud){
|
591 |
|
592 |
|
592 |
pointCloudData.push_back(smCloud);
|
593 |
pointCloudData.push_back(smCloud);
|
593 |
|
594 |
|
594 |
// Add identifier to list
|
595 |
// Add identifier to list
|
595 |
QListWidgetItem* item = new QListWidgetItem(QString("Point Cloud %1 -- %2 deg").arg(smCloud.id).arg(smCloud.rotationAngle));
|
596 |
QListWidgetItem* item = new QListWidgetItem(QString("Point Cloud %1 -- %2 deg").arg(smCloud.id).arg(smCloud.rotationAngle));
|
596 |
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
597 |
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
597 |
item->setData(Qt::UserRole, QVariant(smCloud.id));
|
598 |
item->setData(Qt::UserRole, QVariant(smCloud.id));
|
598 |
item->setCheckState(Qt::Checked);
|
599 |
item->setCheckState(Qt::Checked);
|
599 |
|
600 |
|
600 |
ui->pointCloudsListWidget->addItem(item);
|
601 |
ui->pointCloudsListWidget->addItem(item);
|
601 |
ui->pointCloudWidget->addPointCloud(smCloud, smCloud.id);
|
602 |
ui->pointCloudWidget->addPointCloud(smCloud, smCloud.id);
|
602 |
|
603 |
|
603 |
// Indicate completed reconstruction in captureTreeWidget
|
604 |
// Indicate completed reconstruction in captureTreeWidget
|
604 |
for(int i=0; i<ui->captureTreeWidget->topLevelItemCount(); i++){
|
605 |
for(int i=0; i<ui->captureTreeWidget->topLevelItemCount(); i++){
|
605 |
QTreeWidgetItem *captureItem = ui->captureTreeWidget->topLevelItem(i);
|
606 |
QTreeWidgetItem *captureItem = ui->captureTreeWidget->topLevelItem(i);
|
606 |
if(captureItem->data(0, Qt::UserRole).toPoint() == QPoint(smCloud.id, -1)){
|
607 |
if(captureItem->data(0, Qt::UserRole).toPoint() == QPoint(smCloud.id, -1)){
|
607 |
captureItem->setTextColor(0, QColor(0, 0, 0));
|
608 |
captureItem->setTextColor(0, QColor(0, 0, 0));
|
608 |
captureItem->setIcon(0, QIcon());
|
609 |
captureItem->setIcon(0, QIcon());
|
609 |
}
|
610 |
}
|
610 |
}
|
611 |
}
|
611 |
|
612 |
|
612 |
}
|
613 |
}
|
613 |
|
614 |
|
614 |
void SMScanner::on_actionExport_Point_Clouds_triggered(){
|
615 |
void SMScanner::on_actionExport_Point_Clouds_triggered(){
|
615 |
|
616 |
|
616 |
QString directory = QFileDialog::getExistingDirectory(this, "Export Point Clouds", QString());
|
617 |
QString directory = QFileDialog::getExistingDirectory(this, "Export Point Clouds", QString());
|
617 |
|
618 |
|
618 |
// // Non native file dialog
|
619 |
// // Non native file dialog
|
619 |
// QFileDialog saveDirectoryDialog(this, "Export Point Clouds", QString(), "*.pcd;;*.ply;;*.vtk;;*.png;;*.txt");
|
620 |
// QFileDialog saveDirectoryDialog(this, "Export Point Clouds", QString(), "*.pcd;;*.ply;;*.vtk;;*.png;;*.txt");
|
620 |
// saveDirectoryDialog.setDefaultSuffix("ply");
|
621 |
// saveDirectoryDialog.setDefaultSuffix("ply");
|
621 |
// saveDirectoryDialog.setFileMode(QFileDialog::Directory);
|
622 |
// saveDirectoryDialog.setFileMode(QFileDialog::Directory);
|
622 |
// saveDirectoryDialog.exec();
|
623 |
// saveDirectoryDialog.exec();
|
623 |
// QString directory = saveDirectoryDialog.directory().path();
|
624 |
// QString directory = saveDirectoryDialog.directory().path();
|
624 |
// QString type = saveDirectoryDialog.selectedNameFilter();
|
625 |
// QString type = saveDirectoryDialog.selectedNameFilter();
|
625 |
|
626 |
|
626 |
QProgressDialog progressDialog("Exporting Point Clouds...", "Cancel", 0, 100, this);
|
627 |
QProgressDialog progressDialog("Exporting Point Clouds...", "Cancel", 0, 100, this);
|
627 |
progressDialog.setWindowModality(Qt::WindowModal);
|
628 |
progressDialog.setWindowModality(Qt::WindowModal);
|
628 |
progressDialog.setMinimumDuration(1000);
|
629 |
progressDialog.setMinimumDuration(1000);
|
629 |
|
630 |
|
630 |
// save point clouds in ply format
|
631 |
// save point clouds in ply format
|
631 |
for(unsigned int i=0; i<pointCloudData.size(); i++){
|
632 |
for(unsigned int i=0; i<pointCloudData.size(); i++){
|
632 |
|
633 |
|
633 |
progressDialog.setValue(100.0*i/pointCloudData.size());
|
634 |
progressDialog.setValue(100.0*i/pointCloudData.size());
|
634 |
if(pointCloudData[i].id != -1){
|
635 |
if(pointCloudData[i].id != -1){
|
635 |
QString fileName = QString("%1/pointcloud_%2.ply").arg(directory).arg(i);
|
636 |
QString fileName = QString("%1/pointcloud_%2.ply").arg(directory).arg(i);
|
636 |
pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr pointCloudPCL(pointCloudData[i].pointCloud);
|
637 |
pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr pointCloudPCL(pointCloudData[i].pointCloud);
|
637 |
//pcl::io::savePLYFileBinary(fileName.toStdString(), *pointCloudPCL);
|
638 |
//pcl::io::savePLYFileBinary(fileName.toStdString(), *pointCloudPCL);
|
638 |
pcl::PLYWriter w;
|
639 |
pcl::PLYWriter w;
|
639 |
// Write to ply in binary without camera
|
640 |
// Write to ply in binary without camera
|
640 |
w.write<pcl::PointXYZRGBNormal> (fileName.toStdString(), *pointCloudPCL, true, false);
|
641 |
w.write<pcl::PointXYZRGBNormal> (fileName.toStdString(), *pointCloudPCL, true, false);
|
641 |
}
|
642 |
}
|
642 |
QCoreApplication::processEvents();
|
643 |
QCoreApplication::processEvents();
|
643 |
if(progressDialog.wasCanceled())
|
644 |
if(progressDialog.wasCanceled())
|
644 |
return;
|
645 |
return;
|
645 |
}
|
646 |
}
|
646 |
|
647 |
|
647 |
// save meshlab aln project file
|
648 |
// save meshlab aln project file
|
648 |
std::ofstream s(QString("%1/alignment.aln").arg(directory).toLocal8Bit());
|
649 |
std::ofstream s(QString("%1/alignment.aln").arg(directory).toLocal8Bit());
|
649 |
s << pointCloudData.size() << std::endl;
|
650 |
s << pointCloudData.size() << std::endl;
|
650 |
for(unsigned int i=0; i<pointCloudData.size(); i++){
|
651 |
for(unsigned int i=0; i<pointCloudData.size(); i++){
|
651 |
if(pointCloudData[i].id != -1){
|
652 |
if(pointCloudData[i].id != -1){
|
652 |
QString fileName = QString("pointcloud_%1.ply").arg(pointCloudData[i].id);
|
653 |
QString fileName = QString("pointcloud_%1.ply").arg(pointCloudData[i].id);
|
653 |
s << fileName.toStdString() << std::endl << "#" << std::endl;
|
654 |
s << fileName.toStdString() << std::endl << "#" << std::endl;
|
654 |
cv::Mat Tr = cv::Mat::eye(4, 4, CV_32F);
|
655 |
cv::Mat Tr = cv::Mat::eye(4, 4, CV_32F);
|
655 |
cv::Mat(pointCloudData[i].R.t()).copyTo(Tr.colRange(0, 3).rowRange(0, 3));
|
656 |
cv::Mat(pointCloudData[i].R.t()).copyTo(Tr.colRange(0, 3).rowRange(0, 3));
|
656 |
cv::Mat(-pointCloudData[i].R.t()*pointCloudData[i].T).copyTo(Tr.col(3).rowRange(0, 3));
|
657 |
cv::Mat(-pointCloudData[i].R.t()*pointCloudData[i].T).copyTo(Tr.col(3).rowRange(0, 3));
|
657 |
for(int j=0; j<Tr.rows; j++){
|
658 |
for(int j=0; j<Tr.rows; j++){
|
658 |
for(int k=0; k<Tr.cols; k++){
|
659 |
for(int k=0; k<Tr.cols; k++){
|
659 |
s << Tr.at<float>(j,k) << " ";
|
660 |
s << Tr.at<float>(j,k) << " ";
|
660 |
}
|
661 |
}
|
661 |
s << std::endl;
|
662 |
s << std::endl;
|
662 |
}
|
663 |
}
|
663 |
}
|
664 |
}
|
664 |
}
|
665 |
}
|
665 |
s << "0" << std::flush;
|
666 |
s << "0" << std::flush;
|
666 |
s.close();
|
667 |
s.close();
|
667 |
}
|
668 |
}
|
668 |
|
669 |
|
669 |
void SMScanner::on_pointCloudsListWidget_itemChanged(QListWidgetItem *item){
|
670 |
void SMScanner::on_pointCloudsListWidget_itemChanged(QListWidgetItem *item){
|
670 |
|
671 |
|
671 |
int id = item->data(Qt::UserRole).toInt();
|
672 |
int id = item->data(Qt::UserRole).toInt();
|
672 |
assert((int)pointCloudData.size()>id);
|
673 |
assert((int)pointCloudData.size()>id);
|
673 |
|
674 |
|
674 |
if(item->checkState() == Qt::Checked){
|
675 |
if(item->checkState() == Qt::Checked){
|
675 |
id = std::min(int(pointCloudData.size())-1,std::max(0,id));// clamp range
|
676 |
id = std::min(int(pointCloudData.size())-1,std::max(0,id));// clamp range
|
676 |
ui->pointCloudWidget->addPointCloud(pointCloudData[id], id);
|
677 |
ui->pointCloudWidget->addPointCloud(pointCloudData[id], id);
|
677 |
}
|
678 |
}
|
678 |
else
|
679 |
else
|
679 |
ui->pointCloudWidget->removePointCloud(id);
|
680 |
ui->pointCloudWidget->removePointCloud(id);
|
680 |
|
681 |
|
681 |
}
|
682 |
}
|
682 |
|
683 |
|
683 |
void SMScanner::on_actionExport_Parameters_triggered(){
|
684 |
void SMScanner::on_actionExport_Parameters_triggered(){
|
684 |
|
685 |
|
685 |
QString fileName = QFileDialog::getSaveFileName(this, "Export calibration parameters", QString(), "*.xml");
|
686 |
QString fileName = QFileDialog::getSaveFileName(this, "Export calibration parameters", QString(), "*.xml");
|
686 |
QFileInfo info(fileName);
|
687 |
QFileInfo info(fileName);
|
687 |
QString type = info.suffix();
|
688 |
QString type = info.suffix();
|
688 |
if(type == ""){
|
689 |
if(type == ""){
|
689 |
fileName.append(".xml");
|
690 |
fileName.append(".xml");
|
690 |
}
|
691 |
}
|
691 |
|
692 |
|
692 |
SMCalibrationParameters calibration = settings.value("calibration/parameters").value<SMCalibrationParameters>();
|
693 |
SMCalibrationParameters calibration = settings.value("calibration/parameters").value<SMCalibrationParameters>();
|
693 |
calibration.exportToXML(fileName);
|
694 |
calibration.exportToXML(fileName);
|
694 |
}
|
695 |
}
|
695 |
|
696 |
|
696 |
void SMScanner::on_actionClear_Sequences_triggered(){
|
697 |
void SMScanner::on_actionClear_Sequences_triggered(){
|
697 |
|
698 |
|
698 |
int res = QMessageBox::question(this, "Clear Captured Sequences", "Clear all captured data?", QMessageBox::Ok, QMessageBox::Cancel);
|
699 |
int res = QMessageBox::question(this, "Clear Captured Sequences", "Clear all captured data?", QMessageBox::Ok, QMessageBox::Cancel);
|
699 |
|
700 |
|
700 |
if(res == QMessageBox::Ok){
|
701 |
if(res == QMessageBox::Ok){
|
701 |
captureData.clear();
|
702 |
captureData.clear();
|
702 |
ui->captureTreeWidget->clear();
|
703 |
ui->captureTreeWidget->clear();
|
703 |
lastCaptureId=-1;
|
704 |
lastCaptureId=-1;
|
704 |
}
|
705 |
}
|
705 |
}
|
706 |
}
|
706 |
|
707 |
|
707 |
|
708 |
|
708 |
|
709 |
|
709 |
void SMScanner::on_actionImport_Parameters_triggered(){
|
710 |
void SMScanner::on_actionImport_Parameters_triggered(){
|
710 |
|
711 |
|
711 |
QString fileName = QFileDialog::getOpenFileName(this, "Import calibration parameters", QString(), "*.xml");
|
712 |
QString fileName = QFileDialog::getOpenFileName(this, "Import calibration parameters", QString(), "*.xml");
|
712 |
QFileInfo info(fileName);
|
713 |
QFileInfo info(fileName);
|
713 |
QString type = info.suffix();
|
714 |
QString type = info.suffix();
|
714 |
if(type != "xml"){
|
715 |
if(type != "xml"){
|
715 |
std::cerr << "Error: calibration parameters must be in .xml file." << std::endl;
|
716 |
std::cerr << "Error: calibration parameters must be in .xml file." << std::endl;
|
716 |
return;
|
717 |
return;
|
717 |
}
|
718 |
}
|
718 |
|
719 |
|
719 |
SMCalibrationParameters cal;
|
720 |
SMCalibrationParameters cal;
|
720 |
cal.importFromXML(fileName);
|
721 |
cal.importFromXML(fileName);
|
721 |
|
722 |
|
722 |
settings.setValue("calibration/parameters", QVariant::fromValue(cal));
|
723 |
settings.setValue("calibration/parameters", QVariant::fromValue(cal));
|
723 |
ui->pointCloudWidget->updateCalibrationParameters();
|
724 |
ui->pointCloudWidget->updateCalibrationParameters();
|
724 |
|
725 |
|
725 |
std::cout << "Imported calibration parameters " << fileName.toStdString() << std::endl;
|
726 |
std::cout << "Imported calibration parameters " << fileName.toStdString() << std::endl;
|
726 |
}
|
727 |
}
|
727 |
|
728 |
|
728 |
void SMScanner::on_actionImport_Sets_triggered(){
|
729 |
void SMScanner::on_actionImport_Sets_triggered(){
|
729 |
|
730 |
|
730 |
QString dirName = QFileDialog::getExistingDirectory(this, "Import calibration sets", QString());
|
731 |
QString dirName = QFileDialog::getExistingDirectory(this, "Import calibration sets", QString());
|
731 |
|
732 |
|
732 |
QDir dir(dirName);
|
733 |
QDir dir(dirName);
|
733 |
QStringList fileNames0 = dir.entryList(QStringList("frame0_*.png"));
|
734 |
QStringList fileNames0 = dir.entryList(QStringList("frame0_*.png"));
|
734 |
QStringList fileNames1 = dir.entryList(QStringList("frame1_*.png"));
|
735 |
QStringList fileNames1 = dir.entryList(QStringList("frame1_*.png"));
|
735 |
|
736 |
|
736 |
if(fileNames0.empty() || fileNames1.empty() || fileNames0.count() != fileNames1.count()){
|
737 |
if(fileNames0.empty() || fileNames1.empty() || fileNames0.count() != fileNames1.count()){
|
737 |
std::cerr << "Error: could not load calibration sets. Directory must contain .png files for both cameras." << std::endl;
|
738 |
std::cerr << "Error: could not load calibration sets. Directory must contain .png files for both cameras." << std::endl;
|
738 |
return;
|
739 |
return;
|
739 |
}
|
740 |
}
|
740 |
|
741 |
|
741 |
calibrationData.clear();
|
742 |
calibrationData.clear();
|
742 |
ui->calibrationListWidget->clear();
|
743 |
ui->calibrationListWidget->clear();
|
743 |
|
744 |
|
744 |
QProgressDialog progressDialog("Importing Sets...", "Cancel", 0, 100, this);
|
745 |
QProgressDialog progressDialog("Importing Sets...", "Cancel", 0, 100, this);
|
745 |
progressDialog.setWindowModality(Qt::WindowModal);
|
746 |
progressDialog.setWindowModality(Qt::WindowModal);
|
746 |
progressDialog.setMinimumDuration(1000);
|
747 |
progressDialog.setMinimumDuration(1000);
|
747 |
|
748 |
|
748 |
size_t nSets = fileNames0.size();
|
749 |
size_t nSets = fileNames0.size();
|
749 |
for(unsigned int i=0; i<nSets; i++){
|
750 |
for(unsigned int i=0; i<nSets; i++){
|
750 |
|
751 |
|
751 |
progressDialog.setValue(100.0*i/nSets);
|
752 |
progressDialog.setValue(100.0*i/nSets);
|
752 |
|
753 |
|
753 |
SMCalibrationSet calibrationSet;
|
754 |
SMCalibrationSet calibrationSet;
|
754 |
|
755 |
|
755 |
QString fileName0 = QString("%1/frame0_%2.png").arg(dirName).arg(i);
|
756 |
QString fileName0 = QString("%1/frame0_%2.png").arg(dirName).arg(i);
|
756 |
cv::Mat frame0BGR = cv::imread(fileName0.toStdString());
|
757 |
cv::Mat frame0BGR = cv::imread(fileName0.toStdString());
|
757 |
cvtools::cvtColorBGRToBayerBG(frame0BGR, calibrationSet.frame0);
|
758 |
cvtools::cvtColorBGRToBayerBG(frame0BGR, calibrationSet.frame0);
|
758 |
|
759 |
|
759 |
QString fileName1 = QString("%1/frame1_%2.png").arg(dirName).arg(i);
|
760 |
QString fileName1 = QString("%1/frame1_%2.png").arg(dirName).arg(i);
|
760 |
cv::Mat frame1BGR = cv::imread(fileName1.toStdString());
|
761 |
cv::Mat frame1BGR = cv::imread(fileName1.toStdString());
|
761 |
cvtools::cvtColorBGRToBayerBG(frame1BGR, calibrationSet.frame1);
|
762 |
cvtools::cvtColorBGRToBayerBG(frame1BGR, calibrationSet.frame1);
|
762 |
|
763 |
|
763 |
// int id = ui->calibrationListWidget->count();
|
764 |
// int id = ui->calibrationListWidget->count();
|
764 |
// calibrationSet.id = id;
|
765 |
// calibrationSet.id = id;
|
765 |
|
766 |
|
766 |
// calibrationData.push_back(calibrationSet);
|
767 |
// calibrationData.push_back(calibrationSet);
|
767 |
|
768 |
|
768 |
// // Add identifier to list
|
769 |
// // Add identifier to list
|
769 |
// QListWidgetItem* item = new QListWidgetItem(QString("Calibration Set %1 -- %2 deg").arg(id).arg(calibrationSet.rotationAngle), ui->calibrationListWidget);
|
770 |
// QListWidgetItem* item = new QListWidgetItem(QString("Calibration Set %1 -- %2 deg").arg(id).arg(calibrationSet.rotationAngle), ui->calibrationListWidget);
|
770 |
// item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
771 |
// item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
771 |
// item->setCheckState(Qt::Checked);
|
772 |
// item->setCheckState(Qt::Checked);
|
772 |
// ui->calibrationListWidget->addItem(item);
|
773 |
// ui->calibrationListWidget->addItem(item);
|
773 |
|
774 |
|
774 |
this->onReceiveCalibrationSet(calibrationSet);
|
775 |
this->onReceiveCalibrationSet(calibrationSet);
|
775 |
|
776 |
|
776 |
QCoreApplication::processEvents();
|
777 |
QCoreApplication::processEvents();
|
777 |
if(progressDialog.wasCanceled())
|
778 |
if(progressDialog.wasCanceled())
|
778 |
return;
|
779 |
return;
|
779 |
}
|
780 |
}
|
780 |
|
781 |
|
781 |
// Set enabled checkmark
|
782 |
// Set enabled checkmark
|
782 |
if(calibrationData.size() >= 2){
|
783 |
if(calibrationData.size() >= 2){
|
783 |
ui->calibrateCamerasButton->setEnabled(true);
|
784 |
ui->calibrateCamerasButton->setEnabled(true);
|
784 |
ui->calibrateRotationStageButton->setEnabled(true);
|
785 |
ui->calibrateRotationStageButton->setEnabled(true);
|
785 |
}
|
786 |
}
|
786 |
}
|
787 |
}
|
787 |
|
788 |
|
788 |
void SMScanner::on_actionImport_Sequences_triggered(){
|
789 |
void SMScanner::on_actionImport_Sequences_triggered(){
|
789 |
|
790 |
|
790 |
// NOTE: we do not know which algorithm was used!!!
|
791 |
// NOTE: we do not know which algorithm was used!!!
|
791 |
|
792 |
|
792 |
QString dirName = QFileDialog::getExistingDirectory(this, "Import captured sequences", QString());
|
793 |
QString dirName = QFileDialog::getExistingDirectory(this, "Import captured sequences", QString());
|
793 |
|
794 |
|
794 |
QDir dir(dirName);
|
795 |
QDir dir(dirName);
|
795 |
QStringList sequenceDirNames = dir.entryList(QStringList("sequence_*"));
|
796 |
QStringList sequenceDirNames = dir.entryList(QStringList("sequence_*"));
|
796 |
|
797 |
|
797 |
if(sequenceDirNames.empty()){
|
798 |
if(sequenceDirNames.empty()){
|
798 |
std::cerr << "Error: could not find sequences." << std::endl;
|
799 |
std::cerr << "Error: could not find sequences." << std::endl;
|
799 |
return;
|
800 |
return;
|
800 |
}
|
801 |
}
|
801 |
|
802 |
|
802 |
captureData.clear();
|
803 |
captureData.clear();
|
803 |
ui->captureTreeWidget->clear();
|
804 |
ui->captureTreeWidget->clear();
|
804 |
lastCaptureId=-1;
|
805 |
lastCaptureId=-1;
|
805 |
|
806 |
|
806 |
QProgressDialog progressDialog("Importing Sequences...", "Cancel", 0, 100, this);
|
807 |
QProgressDialog progressDialog("Importing Sequences...", "Cancel", 0, 100, this);
|
807 |
progressDialog.setWindowModality(Qt::WindowModal);
|
808 |
progressDialog.setWindowModality(Qt::WindowModal);
|
808 |
progressDialog.setMinimumDuration(1000);
|
809 |
progressDialog.setMinimumDuration(1000);
|
809 |
|
810 |
|
810 |
for(int s=0; s<sequenceDirNames.count(); s++){
|
811 |
for(int s=0; s<sequenceDirNames.count(); s++){
|
811 |
|
812 |
|
812 |
QDir sequenceDir(QString("%1/%2").arg(dirName).arg(sequenceDirNames.at(s)));
|
813 |
QDir sequenceDir(QString("%1/%2").arg(dirName).arg(sequenceDirNames.at(s)));
|
813 |
|
814 |
|
814 |
QStringList fileNames0 = sequenceDir.entryList(QStringList("frames0_*.png"));
|
815 |
QStringList fileNames0 = sequenceDir.entryList(QStringList("frames0_*.png"));
|
815 |
QStringList fileNames1 = sequenceDir.entryList(QStringList("frames1_*.png"));
|
816 |
QStringList fileNames1 = sequenceDir.entryList(QStringList("frames1_*.png"));
|
816 |
|
817 |
|
817 |
if(fileNames0.empty() || fileNames1.empty() || fileNames0.count() != fileNames1.count()){
|
818 |
if(fileNames0.empty() || fileNames1.empty() || fileNames0.count() != fileNames1.count()){
|
818 |
std::cerr << "Error: could not load sequence. Directory must contain .png files for both cameras." << std::endl;
|
819 |
std::cerr << "Error: could not load sequence. Directory must contain .png files for both cameras." << std::endl;
|
819 |
return;
|
820 |
return;
|
820 |
}
|
821 |
}
|
821 |
|
822 |
|
822 |
int nFrames = fileNames0.size();
|
823 |
int nFrames = fileNames0.size();
|
823 |
|
824 |
|
824 |
SMFrameSequence sequence;
|
825 |
SMFrameSequence sequence;
|
825 |
|
826 |
|
826 |
for(int f=0; f<nFrames; f++){
|
827 |
for(int f=0; f<nFrames; f++){
|
827 |
|
828 |
|
828 |
progressDialog.setValue(100.0*s/sequenceDirNames.count() + 100.0/sequenceDirNames.count()*f/nFrames);
|
829 |
progressDialog.setValue(100.0*s/sequenceDirNames.count() + 100.0/sequenceDirNames.count()*f/nFrames);
|
829 |
|
830 |
|
830 |
cv::Mat frame0BGR, frame0BayerBG, frame1BGR, frame1BayerBG;
|
831 |
cv::Mat frame0BGR, frame0BayerBG, frame1BGR, frame1BayerBG;
|
831 |
|
832 |
|
832 |
QString fileName0 = QString("%1/%2/frames0_%3.png").arg(dirName).arg(sequenceDirNames.at(s)).arg(f);
|
833 |
QString fileName0 = QString("%1/%2/frames0_%3.png").arg(dirName).arg(sequenceDirNames.at(s)).arg(f);
|
833 |
frame0BGR = cv::imread(fileName0.toStdString());
|
834 |
frame0BGR = cv::imread(fileName0.toStdString());
|
834 |
cvtools::cvtColorBGRToBayerBG(frame0BGR, frame0BayerBG);
|
835 |
cvtools::cvtColorBGRToBayerBG(frame0BGR, frame0BayerBG);
|
835 |
|
836 |
|
836 |
QString fileName1 = QString("%1/%2/frames1_%3.png").arg(dirName).arg(sequenceDirNames.at(s)).arg(f);
|
837 |
QString fileName1 = QString("%1/%2/frames1_%3.png").arg(dirName).arg(sequenceDirNames.at(s)).arg(f);
|
837 |
frame1BGR = cv::imread(fileName1.toStdString());
|
838 |
frame1BGR = cv::imread(fileName1.toStdString());
|
838 |
cvtools::cvtColorBGRToBayerBG(frame1BGR, frame1BayerBG);
|
839 |
cvtools::cvtColorBGRToBayerBG(frame1BGR, frame1BayerBG);
|
839 |
|
840 |
|
840 |
sequence.frames0.push_back(frame0BayerBG);
|
841 |
sequence.frames0.push_back(frame0BayerBG);
|
841 |
sequence.frames1.push_back(frame1BayerBG);
|
842 |
sequence.frames1.push_back(frame1BayerBG);
|
842 |
|
843 |
|
843 |
QCoreApplication::processEvents();
|
844 |
QCoreApplication::processEvents();
|
844 |
if(progressDialog.wasCanceled())
|
845 |
if(progressDialog.wasCanceled())
|
845 |
return;
|
846 |
return;
|
846 |
}
|
847 |
}
|
847 |
|
848 |
|
848 |
// Assign whatever algorithm is configured
|
849 |
// Assign whatever algorithm is configured
|
849 |
sequence.codec = settings.value("algorithm").toString();
|
850 |
sequence.codec = settings.value("algorithm").toString();
|
850 |
sequence.rotationAngle = 0;
|
851 |
sequence.rotationAngle = 0;
|
851 |
sequence.reconstructed = false;
|
852 |
sequence.reconstructed = false;
|
852 |
|
853 |
|
853 |
onReceiveFrameSequence(sequence);
|
854 |
onReceiveFrameSequence(sequence);
|
854 |
}
|
855 |
}
|
855 |
|
856 |
|
856 |
}
|
857 |
}
|
857 |
|
858 |
|
858 |
void SMScanner::on_actionClear_Point_Clouds_triggered(){
|
859 |
void SMScanner::on_actionClear_Point_Clouds_triggered(){
|
859 |
|
860 |
|
860 |
int res = QMessageBox::question(this, "Clear Reconstructed Point Clouds", "Clear all reconstructed point clouds?", QMessageBox::Ok, QMessageBox::Cancel);
|
861 |
int res = QMessageBox::question(this, "Clear Reconstructed Point Clouds", "Clear all reconstructed point clouds?", QMessageBox::Ok, QMessageBox::Cancel);
|
861 |
|
862 |
|
862 |
if(res == QMessageBox::Ok){
|
863 |
if(res == QMessageBox::Ok){
|
863 |
|
864 |
|
864 |
pointCloudData.clear();
|
865 |
pointCloudData.clear();
|
865 |
ui->pointCloudsListWidget->clear();
|
866 |
ui->pointCloudsListWidget->clear();
|
866 |
ui->pointCloudWidget->removeAllPointClouds();
|
867 |
ui->pointCloudWidget->removeAllPointClouds();
|
867 |
|
868 |
|
868 |
for(unsigned int i=0; i<captureData.size(); i++)
|
869 |
for(unsigned int i=0; i<captureData.size(); i++)
|
869 |
captureData[i].reconstructed = false;
|
870 |
captureData[i].reconstructed = false;
|
870 |
}
|
871 |
}
|
871 |
}
|
872 |
}
|
872 |
|
873 |
|
873 |
|
874 |
|
874 |
void SMScanner::on_actionProject_Focusing_Pattern_triggered(){
|
875 |
void SMScanner::on_actionProject_Focusing_Pattern_triggered(){
|
875 |
|
876 |
|
876 |
bool projectFocusingPattern = ui->actionProject_Focusing_Pattern->isChecked();
|
877 |
bool projectFocusingPattern = ui->actionProject_Focusing_Pattern->isChecked();
|
877 |
QMetaObject::invokeMethod(captureWorker, "setProjectFocusingPattern", Q_ARG(bool, projectFocusingPattern));
|
878 |
QMetaObject::invokeMethod(captureWorker, "setProjectFocusingPattern", Q_ARG(bool, projectFocusingPattern));
|
878 |
|
879 |
|
879 |
}
|
880 |
}
|
880 |
|
881 |
|
881 |
void SMScanner::on_calibrateRotationStageButton_clicked(){
|
882 |
void SMScanner::on_calibrateRotationStageButton_clicked(){
|
882 |
|
883 |
|
883 |
// disable ui elements
|
884 |
// disable ui elements
|
884 |
ui->calibrateCamerasButton->setEnabled(false);
|
885 |
ui->calibrateCamerasButton->setEnabled(false);
|
885 |
ui->calibrateRotationStageButton->setEnabled(false);
|
886 |
ui->calibrateRotationStageButton->setEnabled(false);
|
886 |
ui->calibrationFrame->setEnabled(false);
|
887 |
ui->calibrationFrame->setEnabled(false);
|
887 |
|
888 |
|
888 |
// if none items are selected, we will use all available items
|
889 |
// if none items are selected, we will use all available items
|
889 |
if(ui->calibrationListWidget->selectedItems().empty())
|
890 |
if(ui->calibrationListWidget->selectedItems().empty())
|
890 |
ui->calibrationListWidget->selectAll();
|
891 |
ui->calibrationListWidget->selectAll();
|
891 |
|
892 |
|
892 |
// set selected flags
|
893 |
// set selected flags
|
893 |
for(unsigned int i=0; i<calibrationData.size(); i++){
|
894 |
for(unsigned int i=0; i<calibrationData.size(); i++){
|
894 |
if(ui->calibrationListWidget->item(i)->isSelected())
|
895 |
if(ui->calibrationListWidget->item(i)->isSelected())
|
895 |
calibrationData[i].selected = true;
|
896 |
calibrationData[i].selected = true;
|
896 |
else
|
897 |
else
|
897 |
calibrationData[i].selected = false;
|
898 |
calibrationData[i].selected = false;
|
898 |
}
|
899 |
}
|
899 |
|
900 |
|
900 |
logDialog.show();
|
901 |
logDialog.show();
|
901 |
logDialog.activateWindow();
|
902 |
logDialog.activateWindow();
|
902 |
|
903 |
|
903 |
// start calibration
|
904 |
// start calibration
|
904 |
QMetaObject::invokeMethod(calibrationWorker, "rotationStageCalibration", Q_ARG(std::vector<SMCalibrationSet>, calibrationData));
|
905 |
QMetaObject::invokeMethod(calibrationWorker, "rotationStageCalibration", Q_ARG(std::vector<SMCalibrationSet>, calibrationData));
|
905 |
|
906 |
|
906 |
}
|
907 |
}
|
907 |
|
908 |
|
908 |
|
909 |
|
909 |
void SMScanner::on_actionView_Log_Messages_triggered()
|
910 |
void SMScanner::on_actionView_Log_Messages_triggered()
|
910 |
{
|
911 |
{
|
911 |
logDialog.show();
|
912 |
logDialog.show();
|
912 |
logDialog.activateWindow();
|
913 |
logDialog.activateWindow();
|
913 |
}
|
914 |
}
|
914 |
|
915 |
|
915 |
void SMScanner::on_tabWidget_currentChanged(int index)
|
916 |
void SMScanner::on_tabWidget_currentChanged(int index)
|
916 |
{
|
917 |
{
|
917 |
if(index==0){
|
918 |
if(index==0){
|
918 |
ui->calibrationCamera0Widget->fitImage();
|
919 |
ui->calibrationCamera0Widget->fitImage();
|
919 |
ui->calibrationCamera1Widget->fitImage();
|
920 |
ui->calibrationCamera1Widget->fitImage();
|
920 |
}
|
921 |
}
|
921 |
if(index==1){
|
922 |
if(index==1){
|
922 |
ui->captureCamera0Widget->fitImage();
|
923 |
ui->captureCamera0Widget->fitImage();
|
923 |
ui->captureCamera1Widget->fitImage();
|
924 |
ui->captureCamera1Widget->fitImage();
|
924 |
}
|
925 |
}
|
925 |
}
|
926 |
}
|
926 |
|
927 |
|
927 |
void SMScanner::on_calibrationListWidget_currentRowChanged(int currentRow)
|
928 |
void SMScanner::on_calibrationListWidget_currentRowChanged(int currentRow)
|
928 |
{
|
929 |
{
|
929 |
std::cout << "Current row: " << currentRow << std::endl;
|
930 |
std::cout << "Current row: " << currentRow << std::endl;
|
930 |
on_calibrationListWidget_itemSelectionChanged();
|
931 |
on_calibrationListWidget_itemSelectionChanged();
|
931 |
}
|
932 |
}
|
- |
|
933 |
|
- |
|
934 |
void SMScanner::on_actionEdit_Configuration_File_triggered()
|
- |
|
935 |
{
|
- |
|
936 |
QDesktopServices::openUrl(QUrl::fromLocalFile(settings.fileName()));
|
- |
|
937 |
}
|
932 |
|
938 |
|