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