Subversion Repositories seema-scanner

Rev

Rev 23 | Rev 25 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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