1 |
jakw |
1 |
#include "SMScanner.h"
|
|
|
2 |
#include "ui_SMScanner.h"
|
|
|
3 |
|
25 |
jakw |
4 |
#include "SMCalibrator.h"
|
|
|
5 |
|
4 |
jakw |
6 |
#include <QMetaObject>
|
|
|
7 |
|
25 |
jakw |
8 |
SMScanner::SMScanner(QWidget *parent) :QMainWindow(parent), ui(new Ui::SMScanner), calibrationReviewMode(false){
|
1 |
jakw |
9 |
ui->setupUi(this);
|
4 |
jakw |
10 |
|
|
|
11 |
// Restore geometry
|
|
|
12 |
this->restoreGeometry(settings.value("geometry/mainwindow").toByteArray());
|
|
|
13 |
this->restoreState(settings.value("state/mainwindow").toByteArray());
|
|
|
14 |
|
|
|
15 |
// Set up threads
|
|
|
16 |
captureWorker = new SMCaptureWorker;
|
|
|
17 |
captureWorkerThread = new QThread(this);
|
|
|
18 |
captureWorkerThread->setObjectName("captureWorkerThread");
|
|
|
19 |
captureWorker->moveToThread(captureWorkerThread);
|
|
|
20 |
captureWorkerThread->start();
|
|
|
21 |
|
|
|
22 |
// Connections
|
|
|
23 |
qRegisterMetaType<cv::Mat>("cv::Mat");
|
|
|
24 |
qRegisterMetaType< std::vector<cv::Mat> >("std::vector<cv::Mat>");
|
25 |
jakw |
25 |
qRegisterMetaType<CalibrationSet>("CalibrationSet");
|
23 |
jakw |
26 |
connect(captureWorker, SIGNAL(newFrame(unsigned int, cv::Mat)), this, SLOT(onReceiveFrame(unsigned int, cv::Mat)));
|
25 |
jakw |
27 |
connect(captureWorker, SIGNAL(newCalibrationSet(CalibrationSet)), this, SLOT(onReceiveCalibrationSet(CalibrationSet)));
|
4 |
jakw |
28 |
|
|
|
29 |
// Start capturing
|
|
|
30 |
QMetaObject::invokeMethod(captureWorker, "setup");
|
|
|
31 |
QMetaObject::invokeMethod(captureWorker, "doWork");
|
|
|
32 |
|
1 |
jakw |
33 |
}
|
|
|
34 |
|
23 |
jakw |
35 |
void SMScanner::onReceiveFrame(unsigned int camId, cv::Mat frame){
|
4 |
jakw |
36 |
|
23 |
jakw |
37 |
if(camId == 0){
|
25 |
jakw |
38 |
if(!calibrationReviewMode)
|
|
|
39 |
ui->calibrationCamera0Widget->showImageCV(frame);
|
23 |
jakw |
40 |
ui->captureCamera0Widget->showImageCV(frame);
|
|
|
41 |
} else if(camId == 1){
|
25 |
jakw |
42 |
if(!calibrationReviewMode)
|
|
|
43 |
ui->calibrationCamera1Widget->showImageCV(frame);
|
23 |
jakw |
44 |
ui->captureCamera1Widget->showImageCV(frame);
|
|
|
45 |
}
|
|
|
46 |
}
|
4 |
jakw |
47 |
|
23 |
jakw |
48 |
void SMScanner::on_actionPreferences_triggered(){
|
4 |
jakw |
49 |
|
|
|
50 |
preferenceDialog.show();
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
void SMScanner::closeEvent(QCloseEvent *event){
|
|
|
54 |
|
23 |
jakw |
55 |
// Stop capturing thread
|
|
|
56 |
connect(captureWorker, SIGNAL(finished()), captureWorker, SLOT(deleteLater()));
|
|
|
57 |
connect(captureWorker, SIGNAL(finished()), captureWorkerThread, SLOT(quit()));
|
|
|
58 |
QMetaObject::invokeMethod(captureWorker, "stopWork");
|
|
|
59 |
captureWorkerThread->quit();
|
|
|
60 |
captureWorkerThread->wait();
|
|
|
61 |
|
4 |
jakw |
62 |
// Save window geometry
|
|
|
63 |
settings.setValue("geometry/mainwindow", this->saveGeometry());
|
|
|
64 |
settings.setValue("state/mainwindow", this->saveState());
|
|
|
65 |
|
|
|
66 |
event->accept();
|
|
|
67 |
|
|
|
68 |
}
|
|
|
69 |
|
2 |
jakw |
70 |
SMScanner::~SMScanner(){
|
1 |
jakw |
71 |
delete ui;
|
|
|
72 |
}
|
4 |
jakw |
73 |
|
23 |
jakw |
74 |
void SMScanner::on_singleCalibrationButton_clicked(){
|
|
|
75 |
|
25 |
jakw |
76 |
// If in review mode, go back to aquisition mode
|
|
|
77 |
if(calibrationReviewMode){
|
26 |
jakw |
78 |
ui->calibrationListWidget->clearSelection();
|
25 |
jakw |
79 |
ui->singleCalibrationButton->setText("Single Aquisition");
|
|
|
80 |
ui->batchCalibrationButton->setText("Batch Aquisition");
|
|
|
81 |
calibrationReviewMode = false;
|
|
|
82 |
return;
|
|
|
83 |
}
|
|
|
84 |
|
23 |
jakw |
85 |
float position = ui->calibrationRotationDial->value();
|
|
|
86 |
QMetaObject::invokeMethod(captureWorker, "acquireCalibrationSet", Q_ARG(float, position));
|
|
|
87 |
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
void SMScanner::on_calibrationRotationDial_sliderReleased(){
|
|
|
91 |
float angle = ui->calibrationRotationDial->value();
|
|
|
92 |
std::cout << "Rotation stage target: " << angle << std::endl;
|
|
|
93 |
QMetaObject::invokeMethod(captureWorker, "rotateTo", Q_ARG(float, angle));
|
|
|
94 |
}
|
24 |
jakw |
95 |
|
23 |
jakw |
96 |
void SMScanner::onReceiveCalibrationSet(CalibrationSet calibrationSet){
|
|
|
97 |
calibrationData.push_back(calibrationSet);
|
25 |
jakw |
98 |
|
|
|
99 |
// Add identifier to list
|
|
|
100 |
QListWidgetItem* item = new QListWidgetItem(QString("Set %1").arg(ui->calibrationListWidget->count()), ui->calibrationListWidget);
|
|
|
101 |
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
|
|
102 |
item->setCheckState(Qt::Checked);
|
|
|
103 |
ui->calibrationListWidget->addItem(item);
|
|
|
104 |
|
|
|
105 |
// Set enabled checkmark
|
|
|
106 |
if(calibrationData.size() >= 2)
|
|
|
107 |
ui->calibrateButton->setEnabled(true);
|
23 |
jakw |
108 |
}
|
25 |
jakw |
109 |
|
|
|
110 |
void SMScanner::on_calibrationListWidget_currentRowChanged(int currentRow){
|
|
|
111 |
|
|
|
112 |
calibrationReviewMode = true;
|
|
|
113 |
ui->singleCalibrationButton->setText("Live View");
|
|
|
114 |
ui->batchCalibrationButton->setText("Live View");
|
|
|
115 |
|
|
|
116 |
if(!calibrationData[currentRow].frame0Result.empty())
|
|
|
117 |
ui->calibrationCamera0Widget->showImageCV(calibrationData[currentRow].frame0Result);
|
|
|
118 |
else
|
|
|
119 |
ui->calibrationCamera0Widget->showImageCV(calibrationData[currentRow].frame0);
|
|
|
120 |
|
|
|
121 |
if(!calibrationData[currentRow].frame1Result.empty())
|
|
|
122 |
ui->calibrationCamera1Widget->showImageCV(calibrationData[currentRow].frame1Result);
|
|
|
123 |
else
|
|
|
124 |
ui->calibrationCamera1Widget->showImageCV(calibrationData[currentRow].frame1);
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
void SMScanner::on_calibrateButton_clicked(){
|
|
|
128 |
|
|
|
129 |
// set checked flags
|
|
|
130 |
for(int i=0; i<calibrationData.size(); i++){
|
|
|
131 |
calibrationData[i].checked = (ui->calibrationListWidget->item(i)->checkState() == Qt::Checked);
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
SMCalibrator calibrator;
|
|
|
135 |
calibrator.performCalibration(calibrationData);
|
|
|
136 |
|
|
|
137 |
}
|
26 |
jakw |
138 |
|
|
|
139 |
void SMScanner::onCalibrationSetProcessed(int idx){
|
|
|
140 |
ui->calibrationListWidget->setCurrentRow(idx);
|
|
|
141 |
}
|