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