1 |
jakw |
1 |
#include "SMScanner.h"
|
|
|
2 |
#include "ui_SMScanner.h"
|
|
|
3 |
|
4 |
jakw |
4 |
#include <QMetaObject>
|
|
|
5 |
|
2 |
jakw |
6 |
SMScanner::SMScanner(QWidget *parent) :QMainWindow(parent), ui(new Ui::SMScanner){
|
1 |
jakw |
7 |
ui->setupUi(this);
|
4 |
jakw |
8 |
|
|
|
9 |
// Restore geometry
|
|
|
10 |
this->restoreGeometry(settings.value("geometry/mainwindow").toByteArray());
|
|
|
11 |
this->restoreState(settings.value("state/mainwindow").toByteArray());
|
|
|
12 |
|
|
|
13 |
// Set up threads
|
|
|
14 |
captureWorker = new SMCaptureWorker;
|
|
|
15 |
captureWorkerThread = new QThread(this);
|
|
|
16 |
captureWorkerThread->setObjectName("captureWorkerThread");
|
|
|
17 |
captureWorker->moveToThread(captureWorkerThread);
|
|
|
18 |
captureWorkerThread->start();
|
|
|
19 |
|
|
|
20 |
// Connections
|
|
|
21 |
qRegisterMetaType<cv::Mat>("cv::Mat");
|
|
|
22 |
qRegisterMetaType< std::vector<cv::Mat> >("std::vector<cv::Mat>");
|
23 |
jakw |
23 |
connect(captureWorker, SIGNAL(newFrame(unsigned int, cv::Mat)), this, SLOT(onReceiveFrame(unsigned int, cv::Mat)));
|
4 |
jakw |
24 |
|
|
|
25 |
// Start capturing
|
|
|
26 |
QMetaObject::invokeMethod(captureWorker, "setup");
|
|
|
27 |
QMetaObject::invokeMethod(captureWorker, "doWork");
|
|
|
28 |
|
1 |
jakw |
29 |
}
|
|
|
30 |
|
23 |
jakw |
31 |
void SMScanner::onReceiveFrame(unsigned int camId, cv::Mat frame){
|
4 |
jakw |
32 |
|
23 |
jakw |
33 |
if(camId == 0){
|
|
|
34 |
ui->calibrationCamera0Widget->showImageCV(frame);
|
|
|
35 |
ui->captureCamera0Widget->showImageCV(frame);
|
|
|
36 |
} else if(camId == 1){
|
|
|
37 |
ui->calibrationCamera1Widget->showImageCV(frame);
|
|
|
38 |
ui->captureCamera1Widget->showImageCV(frame);
|
|
|
39 |
}
|
|
|
40 |
}
|
4 |
jakw |
41 |
|
23 |
jakw |
42 |
void SMScanner::on_actionPreferences_triggered(){
|
4 |
jakw |
43 |
|
|
|
44 |
preferenceDialog.show();
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
void SMScanner::closeEvent(QCloseEvent *event){
|
|
|
48 |
|
23 |
jakw |
49 |
// Stop capturing thread
|
|
|
50 |
connect(captureWorker, SIGNAL(finished()), captureWorker, SLOT(deleteLater()));
|
|
|
51 |
connect(captureWorker, SIGNAL(finished()), captureWorkerThread, SLOT(quit()));
|
|
|
52 |
QMetaObject::invokeMethod(captureWorker, "stopWork");
|
|
|
53 |
captureWorkerThread->quit();
|
|
|
54 |
captureWorkerThread->wait();
|
|
|
55 |
|
4 |
jakw |
56 |
// Save window geometry
|
|
|
57 |
settings.setValue("geometry/mainwindow", this->saveGeometry());
|
|
|
58 |
settings.setValue("state/mainwindow", this->saveState());
|
|
|
59 |
|
|
|
60 |
event->accept();
|
|
|
61 |
|
|
|
62 |
}
|
|
|
63 |
|
2 |
jakw |
64 |
SMScanner::~SMScanner(){
|
1 |
jakw |
65 |
delete ui;
|
|
|
66 |
}
|
4 |
jakw |
67 |
|
23 |
jakw |
68 |
void SMScanner::on_singleCalibrationButton_clicked(){
|
|
|
69 |
|
|
|
70 |
float position = ui->calibrationRotationDial->value();
|
|
|
71 |
QMetaObject::invokeMethod(captureWorker, "acquireCalibrationSet", Q_ARG(float, position));
|
|
|
72 |
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
void SMScanner::on_calibrationRotationDial_sliderReleased(){
|
|
|
76 |
float angle = ui->calibrationRotationDial->value();
|
|
|
77 |
std::cout << "Rotation stage target: " << angle << std::endl;
|
|
|
78 |
QMetaObject::invokeMethod(captureWorker, "rotateTo", Q_ARG(float, angle));
|
|
|
79 |
}
|
24 |
jakw |
80 |
|
23 |
jakw |
81 |
void SMScanner::onReceiveCalibrationSet(CalibrationSet calibrationSet){
|
|
|
82 |
calibrationData.push_back(calibrationSet);
|
|
|
83 |
}
|