Subversion Repositories seema-scanner

Rev

Rev 222 | Rev 226 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 222 Rev 225
Line 1... Line 1...
1
#include "SMScanner.h"
1
#include "SMScanner.h"
-
 
2
 
2
#include "ui_SMScanner.h"
3
#include "ui_SMScanner.h"
3
 
4
 
4
#include <QMetaObject>
5
#include <QMetaObject>
5
#include <QFileDialog>
6
#include <QFileDialog>
6
#include <QMessageBox>
7
#include <QMessageBox>
Line 36... Line 37...
36
 
37
 
37
    // Restore geometry
38
    // Restore geometry
38
    this->restoreGeometry(settings.value("geometry/mainwindow").toByteArray());
39
    this->restoreGeometry(settings.value("geometry/mainwindow").toByteArray());
39
    this->restoreState(settings.value("state/mainwindow").toByteArray());
40
    this->restoreState(settings.value("state/mainwindow").toByteArray());
40
 
41
 
41
    // Set up threads
42
    // Set up capture thread
42
    captureWorker = new SMCaptureWorker;
43
    captureWorker = new SMCaptureWorker;
43
    captureWorkerThread = new QThread(this);
44
    captureWorkerThread = new QThread(this);
44
    captureWorkerThread->setObjectName("captureWorkerThread");
45
    captureWorkerThread->setObjectName("captureWorkerThread");
45
    captureWorker->moveToThread(captureWorkerThread);
46
    captureWorker->moveToThread(captureWorkerThread);
46
    captureWorkerThread->start();
47
    captureWorkerThread->start();
Line 53... Line 54...
53
 
54
 
54
    // Start capturing
55
    // Start capturing
55
    QMetaObject::invokeMethod(captureWorker, "setup");
56
    QMetaObject::invokeMethod(captureWorker, "setup");
56
    QMetaObject::invokeMethod(captureWorker, "doWork");
57
    QMetaObject::invokeMethod(captureWorker, "doWork");
57
 
58
 
-
 
59
    // Set up calibration thread
-
 
60
    calibrationWorker = new SMCalibrationWorker;
-
 
61
    calibrationWorkerThread = new QThread(this);
-
 
62
    calibrationWorkerThread->setObjectName("calibrationWorkerThread");
-
 
63
    calibrationWorker->moveToThread(calibrationWorkerThread);
-
 
64
    calibrationWorkerThread->start();
-
 
65
 
-
 
66
    // Connections
-
 
67
    connect(calibrationWorker, SIGNAL(newCheckerboardResult(int, SMCalibrationSet)), this, SLOT(onReceiveCheckerboardResult(int, SMCalibrationSet)));
-
 
68
    connect(calibrationWorker, SIGNAL(done()), this, SLOT(onReceiveCalibrationDone()));
-
 
69
    connect(calibrationWorker, SIGNAL(done()), ui->pointCloudWidget, SLOT(updateCalibrationParameters()));
-
 
70
//    connect(calibrationWorker, SIGNAL(done()), calibrationWorkerThread, SLOT(quit()));
-
 
71
//    connect(calibrationWorker, SIGNAL(done()), calibrationWorker, SLOT(deleteLater()));
-
 
72
    connect(calibrationWorker, SIGNAL(logMessage(QString)), &logDialog, SLOT(showLogMessage(QString)));
-
 
73
 
-
 
74
    // Set up reconstruction thread
-
 
75
    reconstructionWorker = new SMReconstructionWorker;
-
 
76
    reconstructionWorkerThread = new QThread(this);
-
 
77
    reconstructionWorkerThread->setObjectName("reconstructionWorkerThread");
-
 
78
    reconstructionWorker->moveToThread(reconstructionWorkerThread);
-
 
79
    reconstructionWorkerThread->start();
58
 
80
 
-
 
81
    // Connections
-
 
82
    connect(reconstructionWorker, SIGNAL(newPointCloud(SMPointCloud)), this, SLOT(onReceivePointCloud(SMPointCloud)));
-
 
83
    connect(reconstructionWorker, SIGNAL(done()), reconstructionWorkerThread, SLOT(quit()));
59
//ui->captureCamera0ScrollArea->setWidget(ui->captureCamera0Widget);
84
    connect(reconstructionWorker, SIGNAL(done()), reconstructionWorker, SLOT(deleteLater()));
60
 
85
 
61
}
86
}
62
 
87
 
63
void SMScanner::onReceiveFrame(unsigned int camId, cv::Mat frame){
88
void SMScanner::onReceiveFrame(unsigned int camId, cv::Mat frame){
64
 
89
 
Line 82... Line 107...
82
    preferenceDialog.show();
107
    preferenceDialog.show();
83
}
108
}
84
 
109
 
85
void SMScanner::onPreferencesChanged(){
110
void SMScanner::onPreferencesChanged(){
86
 
111
 
87
    // Stop capturing thread
112
    // Stop capture worker
88
    connect(captureWorker, SIGNAL(finished()), captureWorker, SLOT(deleteLater()));
113
//    connect(captureWorker, SIGNAL(finished()), captureWorker, SLOT(deleteLater()));
89
    connect(captureWorker, SIGNAL(finished()), captureWorkerThread, SLOT(quit()));
114
//    connect(captureWorker, SIGNAL(finished()), captureWorkerThread, SLOT(quit()));
90
    QMetaObject::invokeMethod(captureWorker, "stopWork");
115
    QMetaObject::invokeMethod(captureWorker, "stopWork");
91
    captureWorkerThread->quit();
116
//    captureWorkerThread->quit();
92
    captureWorkerThread->wait();
117
//    captureWorkerThread->wait();
93
 
-
 
94
    // Restart capture worker
-
 
95
    captureWorker = new SMCaptureWorker;
-
 
96
    captureWorkerThread = new QThread(this);
-
 
97
    captureWorkerThread->setObjectName("captureWorkerThread");
-
 
98
    captureWorker->moveToThread(captureWorkerThread);
-
 
99
    captureWorkerThread->start();
-
 
100
 
118
 
-
 
119
//    // Restart capture worker
-
 
120
//    captureWorker = new SMCaptureWorker;
-
 
121
//    captureWorkerThread = new QThread(this);
-
 
122
//    captureWorkerThread->setObjectName("captureWorkerThread");
-
 
123
//    captureWorker->moveToThread(captureWorkerThread);
-
 
124
//    captureWorkerThread->start();
-
 
125
 
101
    connect(captureWorker, SIGNAL(newFrame(unsigned int, cv::Mat)), this, SLOT(onReceiveFrame(unsigned int, cv::Mat)));
126
//    connect(captureWorker, SIGNAL(newFrame(unsigned int, cv::Mat)), this, SLOT(onReceiveFrame(unsigned int, cv::Mat)));
102
    connect(captureWorker, SIGNAL(newCalibrationSet(SMCalibrationSet)), this, SLOT(onReceiveCalibrationSet(SMCalibrationSet)));
127
//    connect(captureWorker, SIGNAL(newCalibrationSet(SMCalibrationSet)), this, SLOT(onReceiveCalibrationSet(SMCalibrationSet)));
103
    connect(captureWorker, SIGNAL(newFrameSequence(SMFrameSequence)), this, SLOT(onReceiveFrameSequence(SMFrameSequence)));
128
//    connect(captureWorker, SIGNAL(newFrameSequence(SMFrameSequence)), this, SLOT(onReceiveFrameSequence(SMFrameSequence)));
104
    connect(captureWorker, SIGNAL(rotatedTo(float)), this, SLOT(onReceiveRotatedTo(float)));
129
//    connect(captureWorker, SIGNAL(rotatedTo(float)), this, SLOT(onReceiveRotatedTo(float)));
105
 
130
 
106
    QMetaObject::invokeMethod(captureWorker, "setup");
131
    QMetaObject::invokeMethod(captureWorker, "setup");
107
    QMetaObject::invokeMethod(captureWorker, "doWork");
132
    QMetaObject::invokeMethod(captureWorker, "doWork");
108
 
133
 
109
//    QMessageBox::warning(this, "Information", "You must quit and restart the program for new settings to take effect!", QMessageBox::Ok);
-
 
110
 
-
 
111
}
134
}
112
 
135
 
113
void SMScanner::closeEvent(QCloseEvent *event){
136
void SMScanner::closeEvent(QCloseEvent *event){
114
 
137
 
-
 
138
    // Close dialogs
-
 
139
    preferenceDialog.close();
-
 
140
    logDialog.close();
-
 
141
 
115
    // Stop capturing thread
142
    // Stop capturing thread
116
    connect(captureWorker, SIGNAL(finished()), captureWorker, SLOT(deleteLater()));
143
    connect(captureWorker, SIGNAL(finished()), captureWorker, SLOT(deleteLater()));
117
    connect(captureWorker, SIGNAL(finished()), captureWorkerThread, SLOT(quit()));
144
    connect(captureWorker, SIGNAL(finished()), captureWorkerThread, SLOT(quit()));
118
    QMetaObject::invokeMethod(captureWorker, "stopWork");
145
    QMetaObject::invokeMethod(captureWorker, "stopWork");
119
    captureWorkerThread->quit();
146
    captureWorkerThread->quit();
Line 211... Line 238...
211
 
238
 
212
    calibrationData.push_back(calibrationSet);
239
    calibrationData.push_back(calibrationSet);
213
 
240
 
214
    // Add identifier to list
241
    // Add identifier to list
215
    QListWidgetItem* item = new QListWidgetItem(QString("Calibration Set %1 -- %2 deg").arg(id).arg(calibrationSet.rotationAngle), ui->calibrationListWidget);
242
    QListWidgetItem* item = new QListWidgetItem(QString("Calibration Set %1 -- %2 deg").arg(id).arg(calibrationSet.rotationAngle), ui->calibrationListWidget);
216
    item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
-
 
217
    item->setCheckState(Qt::Checked);
-
 
218
    ui->calibrationListWidget->addItem(item);
243
    ui->calibrationListWidget->addItem(item);
-
 
244
    item->setSelected(true);
219
 
245
 
-
 
246
    // Send to checkerboard detection on calibration thread
-
 
247
    QMetaObject::invokeMethod(calibrationWorker, "checkerboardDetection", Q_ARG(SMCalibrationSet, calibrationSet));
-
 
248
 
220
    // Set enabled checkmark
249
    // Enable calibration button
221
    if(calibrationData.size() >= 2)
250
    if(calibrationData.size() >= 2){
222
        ui->calibrateButton->setEnabled(true);
251
        ui->calibrateCamerasButton->setEnabled(true);
-
 
252
        ui->calibrateRotationStageButton->setEnabled(true);
-
 
253
    }
223
}
254
}
224
 
255
 
225
void SMScanner::on_calibrateButton_clicked(){
256
void SMScanner::on_calibrateCamerasButton_clicked(){
226
 
257
 
227
    // disable ui elements
258
    // disable ui elements
228
    ui->calibrateButton->setEnabled(false);
259
    ui->calibrateCamerasButton->setEnabled(false);
-
 
260
    ui->calibrateRotationStageButton->setEnabled(false);
229
    ui->calibrationFrame->setEnabled(false);
261
    ui->calibrationFrame->setEnabled(false);
230
 
262
 
-
 
263
    // if none items are selected, we will use all available items
-
 
264
    if(ui->calibrationListWidget->selectedItems().empty())
-
 
265
        ui->calibrationListWidget->selectAll();
-
 
266
 
231
    // set checked flags
267
    // set selected flags
232
    for(unsigned int i=0; i<calibrationData.size(); i++){
268
    for(unsigned int i=0; i<calibrationData.size(); i++){
233
        calibrationData[i].checked = (ui->calibrationListWidget->item(i)->checkState() == Qt::Checked);
269
        if(ui->calibrationListWidget->item(i)->isSelected())
-
 
270
            calibrationData[i].selected = true;
-
 
271
        else
-
 
272
            calibrationData[i].selected = false;
234
    }
273
    }
235
 
274
 
236
//    SMCalibrationWorker calibrationWorker;
275
    logDialog.show();
237
//    calibrationWorker.performCalibration(calibrationData);
-
 
238
 
276
 
239
    // Set up calibration thread
-
 
240
    calibrationWorker = new SMCalibrationWorker;
-
 
241
    calibrationWorkerThread = new QThread(this);
-
 
242
    calibrationWorkerThread->setObjectName("calibrationWorkerThread");
-
 
243
    calibrationWorker->moveToThread(calibrationWorkerThread);
-
 
244
    calibrationWorkerThread->start();
-
 
245
 
-
 
246
    // Connections
-
 
247
    connect(calibrationWorker, SIGNAL(newSetProcessed(int)), this, SLOT(onCalibrationSetProcessed(int)));
-
 
248
    connect(calibrationWorker, SIGNAL(newFrameResult(int,int,bool,cv::Mat)), this, SLOT(onCalibrationFrameResult(int,int,bool,cv::Mat)));
-
 
249
    connect(calibrationWorker, SIGNAL(done()), this, SLOT(onCalibrationDone()));
-
 
250
    connect(calibrationWorker, SIGNAL(done()), ui->pointCloudWidget, SLOT(updateCalibrationParameters()));
-
 
251
    connect(calibrationWorker, SIGNAL(done()), calibrationWorkerThread, SLOT(quit()));
-
 
252
    connect(calibrationWorker, SIGNAL(done()), calibrationWorker, SLOT(deleteLater()));
-
 
253
 
-
 
254
    // Start calibration
277
    // start calibration
255
    QMetaObject::invokeMethod(calibrationWorker, "performCameraCalibration", Q_ARG(std::vector<SMCalibrationSet>, calibrationData));
278
    QMetaObject::invokeMethod(calibrationWorker, "cameraCalibration", Q_ARG(std::vector<SMCalibrationSet>, calibrationData));
256
 
279
 
257
}
280
}
258
 
281
 
-
 
282
void SMScanner::onReceiveCheckerboardResult(int idx, SMCalibrationSet set){
259
 
283
 
260
 
-
 
261
void SMScanner::onCalibrationSetProcessed(int idx){
284
    calibrationData[idx] = set;
262
 
-
 
263
    if(calibrationData[idx].frame0Result.empty() && calibrationData[idx].frame1Result.empty())
-
 
264
        ui->calibrationListWidget->item(idx)->setCheckState(Qt::Unchecked);
-
 
265
 
285
 
266
    ui->calibrationListWidget->setCurrentRow(idx);
286
    ui->calibrationListWidget->setCurrentRow(idx);
267
}
287
}
268
 
288
 
269
void SMScanner::onCalibrationDone(){
289
void SMScanner::onReceiveCalibrationDone(){
270
 
290
 
271
    std::cout << "Calibration done!" << std::endl;
291
    std::cout << "Calibration done!" << std::endl;
272
    ui->calibrateButton->setEnabled(true);
292
    ui->calibrateCamerasButton->setEnabled(true);
-
 
293
    ui->calibrateRotationStageButton->setEnabled(true);
273
    ui->calibrationFrame->setEnabled(true);
294
    ui->calibrationFrame->setEnabled(true);
274
 
295
 
275
}
296
}
276
 
297
 
277
void SMScanner::on_calibrationListWidget_itemSelectionChanged(){
298
void SMScanner::on_calibrationListWidget_itemSelectionChanged(){
278
 
299
 
279
    // if selection is just cleared
300
    // if selection is just cleared
280
    if(ui->calibrationListWidget->selectedItems().empty())
301
    if(ui->calibrationListWidget->selectedItems().empty())
281
        return;
302
        return;
282
 
303
 
283
    // clamp to available range
-
 
284
    if(ui->calibrationListWidget->currentRow() < 0)
-
 
285
        return;
-
 
286
    assert(ui->calibrationListWidget->currentRow() < calibrationData.size());
-
 
287
    int currentRow = std::min(int(calibrationData.size())-1,
-
 
288
                              std::max(0, ui->calibrationListWidget->currentRow()));
-
 
289
 
-
 
290
    calibrationReviewMode = true;
304
    calibrationReviewMode = true;
291
    ui->singleCalibrationButton->setText("Live View");
305
    ui->singleCalibrationButton->setText("Live View");
292
    ui->batchCalibrationButton->setText("Live View");
306
    ui->batchCalibrationButton->setText("Live View");
293
 
307
 
-
 
308
    int currentRow = ui->calibrationListWidget->currentRow();
-
 
309
    if(currentRow < 0)
-
 
310
        return;
-
 
311
 
-
 
312
    assert(currentRow < (int)calibrationData.size());
-
 
313
 
-
 
314
    // if checkerboard results are available, show them, otherwise show the frame
294
    if(calibrationData[currentRow].frame0Result.empty())
315
    if(calibrationData[currentRow].frame0Result.empty())
295
        ui->calibrationCamera0Widget->showImageCV(calibrationData[currentRow].frame0);
316
        ui->calibrationCamera0Widget->showImageCV(calibrationData[currentRow].frame0);
296
    else
317
    else
297
        ui->calibrationCamera0Widget->showImageCV(calibrationData[currentRow].frame0Result);
318
        ui->calibrationCamera0Widget->showImageCV(calibrationData[currentRow].frame0Result);
298
 
319
 
Line 302... Line 323...
302
        ui->calibrationCamera1Widget->showImageCV(calibrationData[currentRow].frame1Result);
323
        ui->calibrationCamera1Widget->showImageCV(calibrationData[currentRow].frame1Result);
303
 
324
 
304
//     std::cout << "on_calibrationListWidget_itemSelectionChanged" << std::endl;
325
//     std::cout << "on_calibrationListWidget_itemSelectionChanged" << std::endl;
305
}
326
}
306
 
327
 
307
void SMScanner::onCalibrationFrameResult(int idx, int camID, bool success, cv::Mat result){
-
 
308
 
-
 
309
    if(success){
-
 
310
        if(camID == 0)
-
 
311
            calibrationData[idx].frame0Result = result;
-
 
312
        else if(camID == 1)
-
 
313
            calibrationData[idx].frame1Result = result;
-
 
314
    }
-
 
315
 
-
 
316
}
-
 
317
 
-
 
318
void SMScanner::on_captureRotationDial_sliderReleased(){
328
void SMScanner::on_captureRotationDial_sliderReleased(){
319
 
329
 
320
    float angle = ui->captureRotationDial->value();
330
    float angle = ui->captureRotationDial->value();
321
    std::cout << "Rotation stage target: " << angle << std::endl;
331
    std::cout << "Rotation stage target: " << angle << std::endl;
322
    QMetaObject::invokeMethod(captureWorker, "rotateTo", Q_ARG(float, angle));
332
    QMetaObject::invokeMethod(captureWorker, "rotateTo", Q_ARG(float, angle));
Line 385... Line 395...
385
 
395
 
386
    QMetaObject::invokeMethod(captureWorker, "acquireFrameSequences", Q_ARG(std::vector<float>, angles));
396
    QMetaObject::invokeMethod(captureWorker, "acquireFrameSequences", Q_ARG(std::vector<float>, angles));
387
}
397
}
388
 
398
 
389
void SMScanner::onReceiveFrameSequence(SMFrameSequence frameSequence){
399
void SMScanner::onReceiveFrameSequence(SMFrameSequence frameSequence){
-
 
400
 
390
    frameSequence.id = ++lastCaptureId;
401
    frameSequence.id = ++lastCaptureId;
391
    captureData.push_back(frameSequence);
-
 
392
 
402
 
393
    // Add identifier to list
403
    // Add identifier to list
394
    QTreeWidgetItem* item = new QTreeWidgetItem(ui->captureTreeWidget);
404
    QTreeWidgetItem* item = new QTreeWidgetItem(ui->captureTreeWidget);
395
    item->setText(0, QString("Frame Sequence %1 -- %2 deg").arg(frameSequence.id).arg(frameSequence.rotationAngle));
405
    item->setText(0, QString("Frame Sequence %1 -- %2 deg").arg(frameSequence.id).arg(frameSequence.rotationAngle));
396
    //item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
406
    //item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
397
    item->setData(0, Qt::UserRole, QPoint(captureData.size()-1, -1));
407
    item->setData(0, Qt::UserRole, QPoint(frameSequence.id, -1));
398
    //item->setCheckState(0, Qt::Checked);
408
    //item->setCheckState(0, Qt::Checked);
399
    //ui->captureTreeWidget->addItem(item);
409
    //ui->captureTreeWidget->addItem(item);
400
 
410
 
401
    for(unsigned int i=0; i<frameSequence.frames0.size(); i++){
411
    for(unsigned int i=0; i<frameSequence.frames0.size(); i++){
402
        QTreeWidgetItem* subItem = new QTreeWidgetItem(item);
412
        QTreeWidgetItem* subItem = new QTreeWidgetItem(item);
403
        subItem->setText(0, QString("frames %1").arg(i));
413
        subItem->setText(0, QString("frames %1").arg(i));
404
        subItem->setData(0, Qt::UserRole, QPoint(frameSequence.id, i));
414
        subItem->setData(0, Qt::UserRole, QPoint(frameSequence.id, i));
405
    }
415
    }
406
 
416
 
-
 
417
    // Indicate that the current item is currently reconstructing
-
 
418
    item->setTextColor(0, QColor(128, 128, 128));
-
 
419
    item->setIcon(0, QIcon::fromTheme("system-run"));
-
 
420
 
407
    ui->reconstructButton->setEnabled(true);
421
    // Reconstruct the frame sequence
-
 
422
    QMetaObject::invokeMethod(reconstructionWorker, "reconstructPointCloud", Q_ARG(SMFrameSequence, frameSequence));
-
 
423
    frameSequence.reconstructed = true;
-
 
424
 
-
 
425
    captureData.push_back(frameSequence);
-
 
426
 
408
}
427
}
409
 
428
 
410
void SMScanner::on_captureTreeWidget_itemSelectionChanged(){
429
void SMScanner::on_captureTreeWidget_itemSelectionChanged(){
411
 
430
 
412
    // if selection is just cleared
431
    // if selection is just cleared
Line 427... Line 446...
427
            && idx.y()<captureData[idx.x()].frames1.size() ){
446
            && idx.y()<captureData[idx.x()].frames1.size() ){
428
        // TODO idx.x() can & WILL be out of bounds
447
        // TODO idx.x() can & WILL be out of bounds
429
        ui->captureCamera0Widget->showImageCV(captureData[idx.x()].frames0[idx.y()]);
448
        ui->captureCamera0Widget->showImageCV(captureData[idx.x()].frames0[idx.y()]);
430
        ui->captureCamera1Widget->showImageCV(captureData[idx.x()].frames1[idx.y()]);
449
        ui->captureCamera1Widget->showImageCV(captureData[idx.x()].frames1[idx.y()]);
431
    }
450
    }
-
 
451
 
432
//     std::cout << "on_captureTreeWidget_itemSelectionChanged" << std::endl;
452
//     std::cout << "on_captureTreeWidget_itemSelectionChanged" << std::endl;
433
}
453
}
434
 
454
 
435
 
455
 
436
void SMScanner::onReceiveRotatedTo(float angle){
456
void SMScanner::onReceiveRotatedTo(float angle){
Line 559... Line 579...
559
            return;
579
            return;
560
    }
580
    }
561
 
581
 
562
}
582
}
563
 
583
 
564
void SMScanner::on_reconstructButton_clicked(){
-
 
565
 
-
 
566
    // Set up reconstruction thread
-
 
567
    reconstructionWorker = new SMReconstructionWorker;
-
 
568
    reconstructionWorkerThread = new QThread(this);
-
 
569
    reconstructionWorkerThread->setObjectName("reconstructionWorkerThread");
-
 
570
    reconstructionWorker->moveToThread(reconstructionWorkerThread);
-
 
571
    reconstructionWorkerThread->start();
-
 
572
 
-
 
573
    // Connections
-
 
574
    connect(reconstructionWorker, SIGNAL(newPointCloud(SMPointCloud)), this, SLOT(onReceivePointCloud(SMPointCloud)));
-
 
575
    connect(reconstructionWorker, SIGNAL(done()), reconstructionWorkerThread, SLOT(quit()));
-
 
576
    connect(reconstructionWorker, SIGNAL(done()), reconstructionWorker, SLOT(deleteLater()));
-
 
577
 
-
 
578
    // Start reconstructing
-
 
579
    QMetaObject::invokeMethod(reconstructionWorker, "setup");
-
 
580
 
-
 
581
    // TODO is a reference working here??
-
 
582
    QMetaObject::invokeMethod(reconstructionWorker, "reconstructPointClouds", Q_ARG(std::vector<SMFrameSequence>, captureData));
-
 
583
    for(unsigned int i=0; i<captureData.size(); i++){
-
 
584
        if(!captureData[i].reconstructed){ // & (ui->captureTreeWidget->topLevelItem(i)->checkState(0) == Qt::Checked))
-
 
585
            captureData[i].reconstructed = true;
-
 
586
            // now done before QMetaObject::invokeMethod(reconstructionWorker, "reconstructPointCloud", Q_ARG(SMFrameSequence, captureData[i]));
-
 
587
        }
-
 
588
    }
-
 
589
}
-
 
590
 
-
 
591
void SMScanner::on_meshButton_clicked(){
-
 
592
 
-
 
593
//    // Set up reconstruction thread
-
 
594
//    meshWorker = new SMMeshingWorker;
-
 
595
//    meshWorkerThread = new QThread(this);
-
 
596
//    meshWorkerThread->setObjectName("meshWorkerThread");
-
 
597
//    meshWorker->moveToThread(meshWorkerThread);
-
 
598
//    meshWorkerThread->start();
-
 
599
 
-
 
600
//    // Connections
-
 
601
//    //connect(meshWorker, SIGNAL(newMesh(pcl::PolygonMesh)), this, SLOT(onReceiveMesh(pcl::PolygonMesh)));
-
 
602
//    //connect(meshWorker, SIGNAL(done()), meshWorkerThread, SLOT(quit()));
-
 
603
//    //connect(meshWorker, SIGNAL(done()), meshWorker, SLOT(deleteLater()));
-
 
604
 
-
 
605
//    // Start reconstructing
-
 
606
//    //QMetaObject::invokeMethod(meshWorker, "setup");
-
 
607
 
-
 
608
//    // TODO is a reference working here??
-
 
609
//    QMetaObject::invokeMethod(meshWorker, "reconstructMesh",
-
 
610
//                              Q_ARG(std::vector<SMPointCloud>, pointCloudData));
-
 
611
}
-
 
612
 
584
 
613
void SMScanner::onReceivePointCloud(SMPointCloud smCloud){
585
void SMScanner::onReceivePointCloud(SMPointCloud smCloud){
614
//    for(int i=0; i<captureData.size(); i++){
-
 
615
//        if(captureData[i].id == id)
-
 
616
//            captureData[i].reconstructed = true;
-
 
617
//    }
-
 
618
 
586
 
619
    //pointCloudData.push_back(smCloud);
587
    pointCloudData.push_back(smCloud);
620
    // TODO on demand resizing here is evil
-
 
621
    if(pointCloudData.size()<=smCloud.id) pointCloudData.resize(smCloud.id+1);
-
 
622
    pointCloudData[smCloud.id] = smCloud;
-
 
623
 
588
 
624
    // Add identifier to list
589
    // Add identifier to list
625
    QListWidgetItem* item = new QListWidgetItem(QString("Point Cloud %1 -- %2 deg").arg(smCloud.id).arg(smCloud.rotationAngle));
590
    QListWidgetItem* item = new QListWidgetItem(QString("Point Cloud %1 -- %2 deg").arg(smCloud.id).arg(smCloud.rotationAngle));
626
    item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
591
    item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
627
    item->setData(Qt::UserRole, QVariant(smCloud.id));
592
    item->setData(Qt::UserRole, QVariant(smCloud.id));
628
    item->setCheckState(Qt::Checked);
593
    item->setCheckState(Qt::Checked);
629
 
594
 
630
    ui->pointCloudsListWidget->addItem(item);
595
    ui->pointCloudsListWidget->addItem(item);
631
    ui->pointCloudWidget->addPointCloud(smCloud, smCloud.id);
596
    ui->pointCloudWidget->addPointCloud(smCloud, smCloud.id);
632
 
597
 
633
    // TODO just to test
598
    // Indicate completed reconstruction in captureTreeWidget
-
 
599
    for(int i=0; i<ui->captureTreeWidget->topLevelItemCount(); i++){
-
 
600
        QTreeWidgetItem *captureItem = ui->captureTreeWidget->topLevelItem(i);
-
 
601
        if(captureItem->data(0, Qt::UserRole).toPoint() == QPoint(smCloud.id, -1)){
-
 
602
            captureItem->setTextColor(0, QColor(0, 0, 0));
634
    on_meshButton_clicked();
603
            captureItem->setIcon(0, QIcon());
-
 
604
        }
-
 
605
   }
-
 
606
 
635
}
607
}
636
 
608
 
637
void SMScanner::on_actionExport_Point_Clouds_triggered(){
609
void SMScanner::on_actionExport_Point_Clouds_triggered(){
638
 
610
 
639
    QString directory = QFileDialog::getExistingDirectory(this, "Export Point Clouds", QString());
611
    QString directory = QFileDialog::getExistingDirectory(this, "Export Point Clouds", QString());
Line 691... Line 663...
691
 
663
 
692
void SMScanner::on_pointCloudsListWidget_itemChanged(QListWidgetItem *item){
664
void SMScanner::on_pointCloudsListWidget_itemChanged(QListWidgetItem *item){
693
 
665
 
694
    int id = item->data(Qt::UserRole).toInt();
666
    int id = item->data(Qt::UserRole).toInt();
695
    assert(pointCloudData.size()>id);
667
    assert(pointCloudData.size()>id);
-
 
668
 
696
    if(item->checkState() == Qt::Checked){
669
    if(item->checkState() == Qt::Checked){
697
        id = std::min(int(pointCloudData.size())-1,std::max(0,id));// clamp range
670
        id = std::min(int(pointCloudData.size())-1,std::max(0,id));// clamp range
698
        ui->pointCloudWidget->addPointCloud(pointCloudData[id], id);
671
        ui->pointCloudWidget->addPointCloud(pointCloudData[id], id);
699
    }
672
    }
700
    else
673
    else
Line 780... Line 753...
780
 
753
 
781
        QString fileName1 = QString("%1/frame1_%2.png").arg(dirName).arg(i);
754
        QString fileName1 = QString("%1/frame1_%2.png").arg(dirName).arg(i);
782
        cv::Mat frame1BGR = cv::imread(fileName1.toStdString());
755
        cv::Mat frame1BGR = cv::imread(fileName1.toStdString());
783
        cvtools::cvtColorBGRToBayerBG(frame1BGR, calibrationSet.frame1);
756
        cvtools::cvtColorBGRToBayerBG(frame1BGR, calibrationSet.frame1);
784
 
757
 
-
 
758
//        int id = ui->calibrationListWidget->count();
-
 
759
//        calibrationSet.id = id;
785
 
760
 
786
        int id = ui->calibrationListWidget->count();
-
 
787
        calibrationSet.id = id;
761
//        calibrationData.push_back(calibrationSet);
788
 
762
 
-
 
763
//        // Add identifier to list
-
 
764
//        QListWidgetItem* item = new QListWidgetItem(QString("Calibration Set %1 -- %2 deg").arg(id).arg(calibrationSet.rotationAngle), ui->calibrationListWidget);
-
 
765
//        item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
-
 
766
//        item->setCheckState(Qt::Checked);
789
        calibrationData.push_back(calibrationSet);
767
//        ui->calibrationListWidget->addItem(item);
790
 
768
 
791
        // Add identifier to list
-
 
792
        QListWidgetItem* item = new QListWidgetItem(QString("Calibration Set %1 -- %2 deg").arg(id).arg(calibrationSet.rotationAngle), ui->calibrationListWidget);
-
 
793
        item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
-
 
794
        item->setCheckState(Qt::Checked);
-
 
795
        ui->calibrationListWidget->addItem(item);
769
        this->onReceiveCalibrationSet(calibrationSet);
796
 
770
 
797
        QCoreApplication::processEvents();
771
        QCoreApplication::processEvents();
798
        if(progressDialog.wasCanceled())
772
        if(progressDialog.wasCanceled())
799
            return;
773
            return;
800
    }
774
    }
801
 
775
 
802
    // Set enabled checkmark
776
    // Set enabled checkmark
803
    if(calibrationData.size() >= 2)
777
    if(calibrationData.size() >= 2){
804
        ui->calibrateButton->setEnabled(true);
778
        ui->calibrateCamerasButton->setEnabled(true);
-
 
779
        ui->calibrateRotationStageButton->setEnabled(true);
-
 
780
    }
805
}
781
}
806
 
782
 
807
void SMScanner::on_actionImport_Sequences_triggered(){
783
void SMScanner::on_actionImport_Sequences_triggered(){
808
 
784
 
809
    // NOTE: we do not know which algorithm was used!!!
785
    // NOTE: we do not know which algorithm was used!!!
Line 888... Line 864...
888
            captureData[i].reconstructed = false;
864
            captureData[i].reconstructed = false;
889
    }
865
    }
890
}
866
}
891
 
867
 
892
 
868
 
893
void SMScanner::on_actionProject_Focusing_Pattern_triggered()
869
void SMScanner::on_actionProject_Focusing_Pattern_triggered(){
894
{
870
 
895
    bool projectFocusingPattern = ui->actionProject_Focusing_Pattern->isChecked();
871
    bool projectFocusingPattern = ui->actionProject_Focusing_Pattern->isChecked();
896
    QMetaObject::invokeMethod(captureWorker, "setProjectFocusingPattern", Q_ARG(bool, projectFocusingPattern));
872
    QMetaObject::invokeMethod(captureWorker, "setProjectFocusingPattern", Q_ARG(bool, projectFocusingPattern));
897
 
873
 
898
}
874
}
-
 
875
 
-
 
876
void SMScanner::on_calibrateRotationStageButton_clicked(){
-
 
877
 
-
 
878
    // disable ui elements
-
 
879
    ui->calibrateCamerasButton->setEnabled(false);
-
 
880
    ui->calibrateRotationStageButton->setEnabled(false);
-
 
881
    ui->calibrationFrame->setEnabled(false);
-
 
882
 
-
 
883
    // if none items are selected, we will use all available items
-
 
884
    if(ui->calibrationListWidget->selectedItems().empty())
-
 
885
        ui->calibrationListWidget->selectAll();
-
 
886
 
-
 
887
    // set selected flags
-
 
888
    for(unsigned int i=0; i<calibrationData.size(); i++){
-
 
889
        if(ui->calibrationListWidget->item(i)->isSelected())
-
 
890
            calibrationData[i].selected = true;
-
 
891
        else
-
 
892
            calibrationData[i].selected = false;
-
 
893
    }
-
 
894
 
-
 
895
    logDialog.show();
-
 
896
 
-
 
897
    // start calibration
-
 
898
    QMetaObject::invokeMethod(calibrationWorker, "rotationStageCalibration", Q_ARG(std::vector<SMCalibrationSet>, calibrationData));
-
 
899
 
-
 
900
}
-
 
901
 
-
 
902
 
-
 
903
void SMScanner::on_actionView_Log_Messages_triggered()
-
 
904
{
-
 
905
     logDialog.show();
-
 
906
}