1 |
jakw |
1 |
#include "SMScanner.h"
|
|
|
2 |
#include "ui_SMScanner.h"
|
|
|
3 |
|
4 |
jakw |
4 |
#include <QMetaObject>
|
36 |
jakw |
5 |
#include <QFileDialog>
|
4 |
jakw |
6 |
|
44 |
jakw |
7 |
#include <pcl/io/pcd_io.h>
|
|
|
8 |
#include <pcl/io/ascii_io.h>
|
|
|
9 |
#include <pcl/io/ply_io.h>
|
|
|
10 |
#include <pcl/io/png_io.h>
|
|
|
11 |
#include <pcl/io/vtk_io.h>
|
|
|
12 |
#include <vtkPolyDataWriter.h>
|
|
|
13 |
#include <pcl/conversions.h>
|
|
|
14 |
|
27 |
jakw |
15 |
SMScanner::SMScanner(QWidget *parent) :QMainWindow(parent), ui(new Ui::SMScanner),
|
|
|
16 |
calibrationReviewMode(false), captureReviewMode(false){
|
4 |
jakw |
17 |
|
27 |
jakw |
18 |
// Register metatypes
|
|
|
19 |
qRegisterMetaType<cv::Mat>("cv::Mat");
|
|
|
20 |
qRegisterMetaType< std::vector<cv::Mat> >("std::vector<cv::Mat>");
|
30 |
jakw |
21 |
qRegisterMetaType< std::vector<float> >("std::vector<float>");
|
27 |
jakw |
22 |
qRegisterMetaType<SMCalibrationSet>("SMCalibrationSet");
|
|
|
23 |
qRegisterMetaType<SMCalibrationParameters>("SMCalibrationParameters");
|
|
|
24 |
qRegisterMetaTypeStreamOperators<SMCalibrationParameters>("SMCalibrationParameters");
|
|
|
25 |
qRegisterMetaType< std::vector<SMCalibrationSet> >("std::vector<SMCalibrationSet>");
|
|
|
26 |
qRegisterMetaType<SMFrameSequence>("SMFrameSequence");
|
42 |
jakw |
27 |
qRegisterMetaType< std::vector<SMFrameSequence> >("std::vector<SMFrameSequence>");
|
45 |
jakw |
28 |
qRegisterMetaType<pcl::PointCloud<pcl::PointXYZRGB>::Ptr>("pcl::PointCloud<pcl::PointXYZRGB>::Ptr");
|
42 |
jakw |
29 |
qRegisterMetaType<SMPointCloud>("SMPointCloud");
|
27 |
jakw |
30 |
|
42 |
jakw |
31 |
// Setup ui (requires stream operators registered)
|
|
|
32 |
ui->setupUi(this);
|
|
|
33 |
|
4 |
jakw |
34 |
// Restore geometry
|
|
|
35 |
this->restoreGeometry(settings.value("geometry/mainwindow").toByteArray());
|
|
|
36 |
this->restoreState(settings.value("state/mainwindow").toByteArray());
|
|
|
37 |
|
|
|
38 |
// Set up threads
|
|
|
39 |
captureWorker = new SMCaptureWorker;
|
|
|
40 |
captureWorkerThread = new QThread(this);
|
|
|
41 |
captureWorkerThread->setObjectName("captureWorkerThread");
|
|
|
42 |
captureWorker->moveToThread(captureWorkerThread);
|
|
|
43 |
captureWorkerThread->start();
|
|
|
44 |
|
|
|
45 |
// Connections
|
23 |
jakw |
46 |
connect(captureWorker, SIGNAL(newFrame(unsigned int, cv::Mat)), this, SLOT(onReceiveFrame(unsigned int, cv::Mat)));
|
27 |
jakw |
47 |
connect(captureWorker, SIGNAL(newCalibrationSet(SMCalibrationSet)), this, SLOT(onReceiveCalibrationSet(SMCalibrationSet)));
|
|
|
48 |
connect(captureWorker, SIGNAL(newFrameSequence(SMFrameSequence)), this, SLOT(onReceiveFrameSequence(SMFrameSequence)));
|
30 |
jakw |
49 |
connect(captureWorker, SIGNAL(rotatedTo(float)), this, SLOT(onReceiveRotatedTo(float)));
|
4 |
jakw |
50 |
|
|
|
51 |
// Start capturing
|
|
|
52 |
QMetaObject::invokeMethod(captureWorker, "setup");
|
|
|
53 |
QMetaObject::invokeMethod(captureWorker, "doWork");
|
|
|
54 |
|
1 |
jakw |
55 |
}
|
|
|
56 |
|
23 |
jakw |
57 |
void SMScanner::onReceiveFrame(unsigned int camId, cv::Mat frame){
|
4 |
jakw |
58 |
|
23 |
jakw |
59 |
if(camId == 0){
|
25 |
jakw |
60 |
if(!calibrationReviewMode)
|
|
|
61 |
ui->calibrationCamera0Widget->showImageCV(frame);
|
27 |
jakw |
62 |
if(!captureReviewMode)
|
|
|
63 |
ui->captureCamera0Widget->showImageCV(frame);
|
23 |
jakw |
64 |
} else if(camId == 1){
|
25 |
jakw |
65 |
if(!calibrationReviewMode)
|
|
|
66 |
ui->calibrationCamera1Widget->showImageCV(frame);
|
27 |
jakw |
67 |
if(!captureReviewMode)
|
|
|
68 |
ui->captureCamera1Widget->showImageCV(frame);
|
23 |
jakw |
69 |
}
|
|
|
70 |
}
|
4 |
jakw |
71 |
|
23 |
jakw |
72 |
void SMScanner::on_actionPreferences_triggered(){
|
4 |
jakw |
73 |
|
|
|
74 |
preferenceDialog.show();
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
void SMScanner::closeEvent(QCloseEvent *event){
|
|
|
78 |
|
23 |
jakw |
79 |
// Stop capturing thread
|
|
|
80 |
connect(captureWorker, SIGNAL(finished()), captureWorker, SLOT(deleteLater()));
|
|
|
81 |
connect(captureWorker, SIGNAL(finished()), captureWorkerThread, SLOT(quit()));
|
|
|
82 |
QMetaObject::invokeMethod(captureWorker, "stopWork");
|
|
|
83 |
captureWorkerThread->quit();
|
|
|
84 |
captureWorkerThread->wait();
|
|
|
85 |
|
4 |
jakw |
86 |
// Save window geometry
|
|
|
87 |
settings.setValue("geometry/mainwindow", this->saveGeometry());
|
|
|
88 |
settings.setValue("state/mainwindow", this->saveState());
|
|
|
89 |
|
|
|
90 |
event->accept();
|
|
|
91 |
|
|
|
92 |
}
|
|
|
93 |
|
2 |
jakw |
94 |
SMScanner::~SMScanner(){
|
1 |
jakw |
95 |
delete ui;
|
|
|
96 |
}
|
4 |
jakw |
97 |
|
23 |
jakw |
98 |
void SMScanner::on_singleCalibrationButton_clicked(){
|
|
|
99 |
|
25 |
jakw |
100 |
// If in review mode, go back to aquisition mode
|
|
|
101 |
if(calibrationReviewMode){
|
26 |
jakw |
102 |
ui->calibrationListWidget->clearSelection();
|
25 |
jakw |
103 |
ui->singleCalibrationButton->setText("Single Aquisition");
|
|
|
104 |
ui->batchCalibrationButton->setText("Batch Aquisition");
|
|
|
105 |
calibrationReviewMode = false;
|
|
|
106 |
return;
|
|
|
107 |
}
|
|
|
108 |
|
27 |
jakw |
109 |
QMetaObject::invokeMethod(captureWorker, "acquireCalibrationSet", Q_ARG(float, -1.0));
|
23 |
jakw |
110 |
|
|
|
111 |
}
|
|
|
112 |
|
30 |
jakw |
113 |
|
|
|
114 |
void SMScanner::on_batchCalibrationButton_clicked(){
|
|
|
115 |
|
|
|
116 |
// If in review mode, go back to aquisition mode
|
|
|
117 |
if(calibrationReviewMode){
|
|
|
118 |
ui->calibrationListWidget->clearSelection();
|
|
|
119 |
ui->singleCalibrationButton->setText("Single Aquisition");
|
|
|
120 |
ui->batchCalibrationButton->setText("Batch Aquisition");
|
|
|
121 |
calibrationReviewMode = false;
|
|
|
122 |
return;
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
// Construct vector of angles
|
|
|
126 |
int angleStart = ui->calibrationBatchStartSpinBox->value();
|
|
|
127 |
int angleEnd = ui->calibrationBatchEndSpinBox->value();
|
|
|
128 |
int angleStep = ui->calibrationBatchStepSpinBox->value();
|
|
|
129 |
|
|
|
130 |
if(angleStart > angleEnd)
|
|
|
131 |
angleEnd += 360;
|
|
|
132 |
|
|
|
133 |
std::vector<float> angles;
|
|
|
134 |
for(int i=angleStart; i<=angleEnd; i+=angleStep)
|
|
|
135 |
angles.push_back(i % 360);
|
|
|
136 |
|
|
|
137 |
QMetaObject::invokeMethod(captureWorker, "acquireCalibrationSets", Q_ARG(std::vector<float>, angles));
|
|
|
138 |
|
|
|
139 |
std::cout << "Aquiring sets at ";
|
|
|
140 |
for(int i=0; i<angles.size(); i++)
|
|
|
141 |
std::cout << angles[i] << " ";
|
|
|
142 |
std::cout << " degrees" <<std::endl;
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
|
23 |
jakw |
146 |
void SMScanner::on_calibrationRotationDial_sliderReleased(){
|
27 |
jakw |
147 |
|
23 |
jakw |
148 |
float angle = ui->calibrationRotationDial->value();
|
|
|
149 |
std::cout << "Rotation stage target: " << angle << std::endl;
|
|
|
150 |
QMetaObject::invokeMethod(captureWorker, "rotateTo", Q_ARG(float, angle));
|
27 |
jakw |
151 |
|
|
|
152 |
ui->captureRotationDial->setValue(ui->calibrationRotationDial->value());
|
23 |
jakw |
153 |
}
|
24 |
jakw |
154 |
|
27 |
jakw |
155 |
void SMScanner::onReceiveCalibrationSet(SMCalibrationSet calibrationSet){
|
23 |
jakw |
156 |
calibrationData.push_back(calibrationSet);
|
25 |
jakw |
157 |
|
|
|
158 |
// Add identifier to list
|
29 |
jakw |
159 |
QListWidgetItem* item = new QListWidgetItem(QString("Calibration Set %1 -- %2 deg").arg(ui->calibrationListWidget->count()).arg(calibrationSet.rotationAngle), ui->calibrationListWidget);
|
25 |
jakw |
160 |
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
|
|
161 |
item->setCheckState(Qt::Checked);
|
|
|
162 |
ui->calibrationListWidget->addItem(item);
|
|
|
163 |
|
|
|
164 |
// Set enabled checkmark
|
|
|
165 |
if(calibrationData.size() >= 2)
|
|
|
166 |
ui->calibrateButton->setEnabled(true);
|
23 |
jakw |
167 |
}
|
25 |
jakw |
168 |
|
27 |
jakw |
169 |
void SMScanner::on_calibrateButton_clicked(){
|
25 |
jakw |
170 |
|
29 |
jakw |
171 |
// disable ui elements
|
|
|
172 |
ui->calibrateButton->setEnabled(false);
|
|
|
173 |
ui->calibrationFrame->setEnabled(false);
|
27 |
jakw |
174 |
|
|
|
175 |
// set checked flags
|
|
|
176 |
for(int i=0; i<calibrationData.size(); i++){
|
|
|
177 |
calibrationData[i].checked = (ui->calibrationListWidget->item(i)->checkState() == Qt::Checked);
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
// SMCalibrationWorker calibrationWorker;
|
|
|
181 |
// calibrationWorker.performCalibration(calibrationData);
|
|
|
182 |
|
|
|
183 |
// Set up calibration thread
|
|
|
184 |
calibrationWorker = new SMCalibrationWorker;
|
|
|
185 |
calibrationWorkerThread = new QThread(this);
|
|
|
186 |
calibrationWorkerThread->setObjectName("calibrationWorkerThread");
|
|
|
187 |
calibrationWorker->moveToThread(captureWorkerThread);
|
|
|
188 |
calibrationWorkerThread->start();
|
|
|
189 |
|
|
|
190 |
// Connections
|
28 |
jakw |
191 |
connect(calibrationWorker, SIGNAL(newSetProcessed(int)), this, SLOT(onCalibrationSetProcessed(int)));
|
29 |
jakw |
192 |
connect(calibrationWorker, SIGNAL(newFrameResult(int,int,bool,cv::Mat)), this, SLOT(onCalibrationFrameResult(int,int,bool,cv::Mat)));
|
27 |
jakw |
193 |
connect(calibrationWorker, SIGNAL(done()), this, SLOT(onCalibrationDone()));
|
32 |
jakw |
194 |
connect(calibrationWorker, SIGNAL(done()), ui->pointCloudWidget, SLOT(updateCalibrationParameters()));
|
27 |
jakw |
195 |
connect(calibrationWorker, SIGNAL(done()), calibrationWorkerThread, SLOT(quit()));
|
|
|
196 |
connect(calibrationWorker, SIGNAL(done()), calibrationWorker, SLOT(deleteLater()));
|
|
|
197 |
|
32 |
jakw |
198 |
// Start calibration
|
27 |
jakw |
199 |
QMetaObject::invokeMethod(calibrationWorker, "performCalibration", Q_ARG(std::vector<SMCalibrationSet>, calibrationData));
|
|
|
200 |
|
|
|
201 |
}
|
|
|
202 |
|
30 |
jakw |
203 |
|
|
|
204 |
|
27 |
jakw |
205 |
void SMScanner::onCalibrationSetProcessed(int idx){
|
|
|
206 |
|
|
|
207 |
ui->calibrationListWidget->setCurrentRow(idx);
|
|
|
208 |
}
|
|
|
209 |
|
|
|
210 |
void SMScanner::onCalibrationDone(){
|
|
|
211 |
|
|
|
212 |
std::cout << "Calibration done!" << std::endl;
|
29 |
jakw |
213 |
ui->calibrateButton->setEnabled(true);
|
|
|
214 |
ui->calibrationFrame->setEnabled(true);
|
27 |
jakw |
215 |
|
|
|
216 |
}
|
|
|
217 |
|
|
|
218 |
void SMScanner::on_calibrationListWidget_itemSelectionChanged(){
|
|
|
219 |
|
|
|
220 |
// if selection is just cleared
|
|
|
221 |
if(ui->calibrationListWidget->selectedItems().empty())
|
|
|
222 |
return;
|
|
|
223 |
|
|
|
224 |
int currentRow = ui->calibrationListWidget->currentRow();
|
|
|
225 |
|
25 |
jakw |
226 |
calibrationReviewMode = true;
|
|
|
227 |
ui->singleCalibrationButton->setText("Live View");
|
|
|
228 |
ui->batchCalibrationButton->setText("Live View");
|
|
|
229 |
|
|
|
230 |
if(!calibrationData[currentRow].frame0Result.empty())
|
|
|
231 |
ui->calibrationCamera0Widget->showImageCV(calibrationData[currentRow].frame0Result);
|
|
|
232 |
else
|
|
|
233 |
ui->calibrationCamera0Widget->showImageCV(calibrationData[currentRow].frame0);
|
|
|
234 |
|
|
|
235 |
if(!calibrationData[currentRow].frame1Result.empty())
|
|
|
236 |
ui->calibrationCamera1Widget->showImageCV(calibrationData[currentRow].frame1Result);
|
|
|
237 |
else
|
|
|
238 |
ui->calibrationCamera1Widget->showImageCV(calibrationData[currentRow].frame1);
|
27 |
jakw |
239 |
|
|
|
240 |
// std::cout << "on_calibrationListWidget_itemSelectionChanged" << std::endl;
|
25 |
jakw |
241 |
}
|
|
|
242 |
|
29 |
jakw |
243 |
void SMScanner::onCalibrationFrameResult(int idx, int camID, bool success, cv::Mat result){
|
25 |
jakw |
244 |
|
29 |
jakw |
245 |
// std::cout << "onCalibrationFrameResult " << idx << camID << std::endl;
|
27 |
jakw |
246 |
|
29 |
jakw |
247 |
if(!success)
|
|
|
248 |
ui->calibrationListWidget->item(idx)->setCheckState(Qt::Unchecked);
|
|
|
249 |
else {
|
|
|
250 |
if(camID == 0)
|
|
|
251 |
calibrationData[idx].frame0Result = result;
|
|
|
252 |
else if(camID == 1)
|
|
|
253 |
calibrationData[idx].frame1Result = result;
|
|
|
254 |
}
|
27 |
jakw |
255 |
|
|
|
256 |
}
|
|
|
257 |
|
|
|
258 |
void SMScanner::on_singleCaptureButton_clicked(){
|
|
|
259 |
|
|
|
260 |
// If in review mode, go back to aquisition mode
|
|
|
261 |
if(captureReviewMode){
|
|
|
262 |
ui->captureTreeWidget->clearSelection();
|
|
|
263 |
ui->singleCaptureButton->setText("Single Aquisition");
|
|
|
264 |
ui->batchCaptureButton->setText("Batch Aquisition");
|
|
|
265 |
captureReviewMode = false;
|
|
|
266 |
return;
|
25 |
jakw |
267 |
}
|
|
|
268 |
|
27 |
jakw |
269 |
QMetaObject::invokeMethod(captureWorker, "acquireFrameSequence", Q_ARG(float, -1.0));
|
25 |
jakw |
270 |
|
|
|
271 |
}
|
26 |
jakw |
272 |
|
27 |
jakw |
273 |
|
30 |
jakw |
274 |
void SMScanner::on_batchCaptureButton_clicked(){
|
|
|
275 |
|
|
|
276 |
// If in review mode, go back to aquisition mode
|
|
|
277 |
if(captureReviewMode){
|
|
|
278 |
ui->captureTreeWidget->clearSelection();
|
|
|
279 |
ui->singleCaptureButton->setText("Single Aquisition");
|
|
|
280 |
ui->batchCaptureButton->setText("Batch Aquisition");
|
|
|
281 |
captureReviewMode = false;
|
|
|
282 |
return;
|
|
|
283 |
}
|
|
|
284 |
|
|
|
285 |
// Construct vector of angles
|
|
|
286 |
int angleStart = ui->captureBatchStartSpinBox->value();
|
|
|
287 |
int angleEnd = ui->captureBatchEndSpinBox->value();
|
|
|
288 |
int angleStep = ui->captureBatchStepSpinBox->value();
|
|
|
289 |
|
|
|
290 |
if(angleStart > angleEnd)
|
|
|
291 |
angleEnd += 360;
|
|
|
292 |
|
|
|
293 |
std::vector<float> angles;
|
|
|
294 |
for(int i=angleStart; i<=angleEnd; i+=angleStep)
|
|
|
295 |
angles.push_back(i % 360);
|
|
|
296 |
|
|
|
297 |
std::cout << "Aquiring sequences at ";
|
|
|
298 |
for(int i=0; i<angles.size(); i++)
|
|
|
299 |
std::cout << angles[i] << " ";
|
|
|
300 |
std::cout << " degrees" <<std::endl;
|
|
|
301 |
|
|
|
302 |
QMetaObject::invokeMethod(captureWorker, "acquireFrameSequences", Q_ARG(std::vector<float>, angles));
|
|
|
303 |
}
|
|
|
304 |
|
27 |
jakw |
305 |
void SMScanner::on_captureRotationDial_sliderReleased(){
|
|
|
306 |
|
|
|
307 |
float angle = ui->captureRotationDial->value();
|
|
|
308 |
std::cout << "Rotation stage target: " << angle << std::endl;
|
|
|
309 |
QMetaObject::invokeMethod(captureWorker, "rotateTo", Q_ARG(float, angle));
|
|
|
310 |
|
|
|
311 |
ui->calibrationRotationDial->setValue(ui->captureRotationDial->value());
|
26 |
jakw |
312 |
}
|
27 |
jakw |
313 |
|
|
|
314 |
void SMScanner::onReceiveFrameSequence(SMFrameSequence frameSequence){
|
|
|
315 |
|
45 |
jakw |
316 |
int id = captureData.size();
|
|
|
317 |
frameSequence.id = id;
|
|
|
318 |
|
27 |
jakw |
319 |
captureData.push_back(frameSequence);
|
|
|
320 |
|
|
|
321 |
// Add identifier to list
|
|
|
322 |
QTreeWidgetItem* item = new QTreeWidgetItem(ui->captureTreeWidget);
|
45 |
jakw |
323 |
item->setText(0, QString("Frame Sequence %1 -- %2 deg").arg(id).arg(frameSequence.rotationAngle));
|
27 |
jakw |
324 |
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
45 |
jakw |
325 |
item->setData(0, Qt::UserRole, QPoint(id, -1));
|
27 |
jakw |
326 |
item->setCheckState(0, Qt::Checked);
|
|
|
327 |
//ui->captureTreeWidget->addItem(item);
|
|
|
328 |
|
|
|
329 |
for(int i=0; i<frameSequence.frames0.size(); i++){
|
|
|
330 |
QTreeWidgetItem* subItem = new QTreeWidgetItem(item);
|
|
|
331 |
subItem->setText(0, QString("frames %1").arg(i));
|
45 |
jakw |
332 |
subItem->setData(0, Qt::UserRole, QPoint(id, i));
|
27 |
jakw |
333 |
}
|
41 |
jakw |
334 |
|
|
|
335 |
ui->reconstructButton->setEnabled(true);
|
27 |
jakw |
336 |
}
|
|
|
337 |
|
|
|
338 |
void SMScanner::on_captureTreeWidget_itemSelectionChanged(){
|
|
|
339 |
|
|
|
340 |
// if selection is just cleared
|
|
|
341 |
if(ui->captureTreeWidget->selectedItems().empty())
|
|
|
342 |
return;
|
|
|
343 |
|
|
|
344 |
QTreeWidgetItem *item = ui->captureTreeWidget->currentItem();
|
|
|
345 |
|
|
|
346 |
captureReviewMode = true;
|
|
|
347 |
|
|
|
348 |
ui->singleCaptureButton->setText("Live View");
|
|
|
349 |
ui->batchCaptureButton->setText("Live View");
|
|
|
350 |
|
|
|
351 |
QPoint idx = item->data(0, Qt::UserRole).toPoint();
|
|
|
352 |
|
|
|
353 |
if(idx.y() != -1){
|
|
|
354 |
ui->captureCamera0Widget->showImageCV(captureData[idx.x()].frames0[idx.y()]);
|
|
|
355 |
ui->captureCamera1Widget->showImageCV(captureData[idx.x()].frames1[idx.y()]);
|
|
|
356 |
}
|
|
|
357 |
|
|
|
358 |
// std::cout << "on_captureTreeWidget_itemSelectionChanged" << std::endl;
|
|
|
359 |
}
|
30 |
jakw |
360 |
|
|
|
361 |
|
|
|
362 |
void SMScanner::onReceiveRotatedTo(float angle){
|
|
|
363 |
|
|
|
364 |
// update ui with new position
|
|
|
365 |
ui->calibrationRotationDial->setValue(angle);
|
|
|
366 |
ui->captureRotationDial->setValue(angle);
|
|
|
367 |
|
|
|
368 |
}
|
36 |
jakw |
369 |
|
|
|
370 |
void SMScanner::on_actionExport_Sets_triggered(){
|
|
|
371 |
|
|
|
372 |
QString dirName = QFileDialog::getExistingDirectory(this, "Export calibration sets", QString());
|
|
|
373 |
for(int i=0; i<calibrationData.size(); i++){
|
|
|
374 |
QString fileName = QString("%1/frame0_%2.png").arg(dirName).arg(i);
|
|
|
375 |
cv::Mat frameBGR;
|
|
|
376 |
cv::cvtColor(calibrationData[i].frame0, frameBGR, CV_RGB2BGR);
|
|
|
377 |
cv::imwrite(fileName.toStdString(), frameBGR);
|
|
|
378 |
fileName = QString("%1/frame1_%2.png").arg(dirName).arg(i);
|
|
|
379 |
cv::cvtColor(calibrationData[i].frame1, frameBGR, CV_RGB2BGR);
|
|
|
380 |
cv::imwrite(fileName.toStdString(), frameBGR);
|
|
|
381 |
}
|
|
|
382 |
|
|
|
383 |
}
|
|
|
384 |
|
|
|
385 |
void SMScanner::on_actionExport_Sequences_triggered(){
|
|
|
386 |
|
|
|
387 |
QString dirName = QFileDialog::getExistingDirectory(this, "Export frame sequences", QString());
|
|
|
388 |
|
|
|
389 |
for(int i=0; i<captureData.size(); i++){
|
|
|
390 |
QString seqDirName = QString("%1/sequence_%2").arg(dirName).arg(i);
|
|
|
391 |
if(!QDir().mkdir(seqDirName))
|
|
|
392 |
std::cerr << "Could not create directory " << seqDirName.toStdString() << std::endl;
|
|
|
393 |
for(int j=0; j<captureData[i].frames0.size(); j++){
|
|
|
394 |
QString fileName = QString("%1/frames0_%2.png").arg(seqDirName).arg(j);
|
|
|
395 |
cv::Mat frameBGR;
|
|
|
396 |
cv::cvtColor(captureData[i].frames0[j], frameBGR, CV_RGB2BGR);
|
|
|
397 |
cv::imwrite(fileName.toStdString(), frameBGR);
|
|
|
398 |
}
|
|
|
399 |
for(int j=0; j<captureData[i].frames1.size(); j++){
|
|
|
400 |
QString fileName = QString("%1/frames1_%2.png").arg(seqDirName).arg(j);
|
|
|
401 |
cv::Mat frameBGR;
|
|
|
402 |
cv::cvtColor(captureData[i].frames1[j], frameBGR, CV_RGB2BGR);
|
|
|
403 |
cv::imwrite(fileName.toStdString(), frameBGR);
|
|
|
404 |
}
|
|
|
405 |
}
|
|
|
406 |
}
|
41 |
jakw |
407 |
|
|
|
408 |
void SMScanner::on_reconstructButton_clicked(){
|
|
|
409 |
|
|
|
410 |
// Set up reconstruction thread
|
|
|
411 |
reconstructionWorker = new SMReconstructionWorker;
|
|
|
412 |
reconstructionWorkerThread = new QThread(this);
|
|
|
413 |
reconstructionWorkerThread->setObjectName("reconstructionWorkerThread");
|
|
|
414 |
reconstructionWorker->moveToThread(reconstructionWorkerThread);
|
|
|
415 |
reconstructionWorkerThread->start();
|
|
|
416 |
|
|
|
417 |
// Connections
|
42 |
jakw |
418 |
connect(reconstructionWorker, SIGNAL(newPointCloud(SMPointCloud)), this, SLOT(onNewPointCloud(SMPointCloud)));
|
41 |
jakw |
419 |
connect(reconstructionWorker, SIGNAL(done()), reconstructionWorkerThread, SLOT(quit()));
|
|
|
420 |
connect(reconstructionWorker, SIGNAL(done()), reconstructionWorker, SLOT(deleteLater()));
|
|
|
421 |
|
|
|
422 |
// Start reconstructing
|
42 |
jakw |
423 |
QMetaObject::invokeMethod(reconstructionWorker, "setup");
|
41 |
jakw |
424 |
|
45 |
jakw |
425 |
std::vector<SMFrameSequence> data;
|
|
|
426 |
for(int i=0; i<captureData.size(); i++){
|
|
|
427 |
if(!captureData[i].reconstructed & ui->captureTreeWidget->itemAt(QPoint(i, 0))->checkState(0) == Qt::Checked)
|
|
|
428 |
QMetaObject::invokeMethod(reconstructionWorker, "reconstructPointCloud", Q_ARG(SMFrameSequence, captureData[i]));
|
|
|
429 |
}
|
|
|
430 |
|
41 |
jakw |
431 |
}
|
|
|
432 |
|
42 |
jakw |
433 |
void SMScanner::onNewPointCloud(SMPointCloud smCloud){
|
41 |
jakw |
434 |
|
45 |
jakw |
435 |
int id = smCloud.id;
|
|
|
436 |
captureData[id].reconstructed = true;
|
|
|
437 |
|
41 |
jakw |
438 |
pointCloudData.push_back(smCloud);
|
|
|
439 |
|
42 |
jakw |
440 |
// Add identifier to list
|
43 |
jakw |
441 |
QListWidgetItem* item = new QListWidgetItem(QString("Point Cloud %1 -- %2 deg").arg(id).arg(smCloud.rotationAngle), ui->pointCloudsListWidget);
|
42 |
jakw |
442 |
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
44 |
jakw |
443 |
item->setData(Qt::UserRole, QVariant(id));
|
42 |
jakw |
444 |
item->setCheckState(Qt::Checked);
|
44 |
jakw |
445 |
|
42 |
jakw |
446 |
ui->pointCloudsListWidget->addItem(item);
|
|
|
447 |
|
44 |
jakw |
448 |
ui->pointCloudWidget->addPointCloud(smCloud, id);
|
41 |
jakw |
449 |
}
|
42 |
jakw |
450 |
|
|
|
451 |
|
44 |
jakw |
452 |
|
|
|
453 |
void SMScanner::on_actionExport_Point_Clouds_triggered(){
|
|
|
454 |
|
|
|
455 |
QString directory = QFileDialog::getExistingDirectory(this, "Export Point Clouds", QString());
|
|
|
456 |
|
|
|
457 |
// // Non native file dialog
|
|
|
458 |
// QFileDialog saveDirectoryDialog(this, "Export Point Clouds", QString(), "*.pcd;;*.ply;;*.vtk;;*.png;;*.txt");
|
|
|
459 |
// saveDirectoryDialog.setDefaultSuffix("ply");
|
|
|
460 |
// saveDirectoryDialog.setFileMode(QFileDialog::Directory);
|
|
|
461 |
// saveDirectoryDialog.exec();
|
|
|
462 |
// QString directory = saveDirectoryDialog.directory().path();
|
|
|
463 |
// QString type = saveDirectoryDialog.selectedNameFilter();
|
|
|
464 |
|
|
|
465 |
// save point clouds in ply format
|
|
|
466 |
for(int i=0; i<pointCloudData.size(); i++){
|
|
|
467 |
QString fileName = QString("%1/pointcloud_%2.ply").arg(directory).arg(i);
|
45 |
jakw |
468 |
pcl::PointCloud<pcl::PointXYZRGB>::Ptr pointCloudPCL(pointCloudData[i].pointCloud);
|
44 |
jakw |
469 |
//pcl::io::savePLYFileBinary(fileName.toStdString(), *pointCloudPCL);
|
|
|
470 |
pcl::PLYWriter w;
|
|
|
471 |
// Write to ply in binary without camera
|
45 |
jakw |
472 |
w.write<pcl::PointXYZRGB> (fileName.toStdString(), *pointCloudPCL, true, false);
|
44 |
jakw |
473 |
}
|
|
|
474 |
|
|
|
475 |
// save meshlab aln project file
|
|
|
476 |
std::ofstream s(QString("%1/alignment.aln").arg(directory).toLocal8Bit());
|
|
|
477 |
s << pointCloudData.size() << std::endl;
|
|
|
478 |
for(int i=0; i<pointCloudData.size(); i++){
|
|
|
479 |
QString fileName = QString("pointcloud_%1.ply").arg(i);
|
|
|
480 |
s << fileName.toStdString() << std::endl << "#" << std::endl;
|
|
|
481 |
cv::Mat Tr = cv::Mat::eye(4, 4, CV_32F);
|
|
|
482 |
cv::Mat(pointCloudData[i].R.t()).copyTo(Tr.colRange(0, 3).rowRange(0, 3));
|
|
|
483 |
cv::Mat(-pointCloudData[i].R.t()*pointCloudData[i].T).copyTo(Tr.col(3).rowRange(0, 3));
|
|
|
484 |
for(int j=0; j<Tr.rows; j++){
|
|
|
485 |
for(int k=0; k<Tr.cols; k++){
|
|
|
486 |
s << Tr.at<float>(j,k) << " ";
|
|
|
487 |
}
|
|
|
488 |
s << std::endl;
|
|
|
489 |
}
|
|
|
490 |
}
|
|
|
491 |
s << "0" << std::flush;
|
|
|
492 |
s.close();
|
|
|
493 |
}
|
|
|
494 |
|
|
|
495 |
void SMScanner::on_pointCloudsListWidget_itemChanged(QListWidgetItem *item){
|
|
|
496 |
|
|
|
497 |
int id = item->data(Qt::UserRole).toInt();
|
|
|
498 |
|
|
|
499 |
if(item->checkState() == Qt::Checked)
|
|
|
500 |
ui->pointCloudWidget->addPointCloud(pointCloudData[id], id);
|
|
|
501 |
else
|
|
|
502 |
ui->pointCloudWidget->removePointCloud(id);
|
|
|
503 |
|
|
|
504 |
}
|
|
|
505 |
|
|
|
506 |
void SMScanner::on_actionExport_Parameters_triggered(){
|
|
|
507 |
|
42 |
jakw |
508 |
QString fileName = QFileDialog::getSaveFileName(this, "Export calibration parameters", QString(), "*.xml");
|
|
|
509 |
QFileInfo info(fileName);
|
|
|
510 |
QString type = info.suffix();
|
|
|
511 |
if(type == ""){
|
|
|
512 |
fileName.append(".xml");
|
|
|
513 |
}
|
|
|
514 |
|
|
|
515 |
SMCalibrationParameters calibration = settings.value("calibration/parameters").value<SMCalibrationParameters>();
|
|
|
516 |
calibration.exportToXML(fileName);
|
|
|
517 |
}
|