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