Subversion Repositories seema-scanner

Rev

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

Rev 24 Rev 25
Line 1... Line 1...
1
#include "SMScanner.h"
1
#include "SMScanner.h"
2
#include "ui_SMScanner.h"
2
#include "ui_SMScanner.h"
3
 
3
 
-
 
4
#include "SMCalibrator.h"
-
 
5
 
4
#include <QMetaObject>
6
#include <QMetaObject>
5
 
7
 
6
SMScanner::SMScanner(QWidget *parent) :QMainWindow(parent), ui(new Ui::SMScanner){
8
SMScanner::SMScanner(QWidget *parent) :QMainWindow(parent), ui(new Ui::SMScanner), calibrationReviewMode(false){
7
    ui->setupUi(this);
9
    ui->setupUi(this);
8
 
10
 
9
    // Restore geometry
11
    // Restore geometry
10
    this->restoreGeometry(settings.value("geometry/mainwindow").toByteArray());
12
    this->restoreGeometry(settings.value("geometry/mainwindow").toByteArray());
11
    this->restoreState(settings.value("state/mainwindow").toByteArray());
13
    this->restoreState(settings.value("state/mainwindow").toByteArray());
Line 18... Line 20...
18
    captureWorkerThread->start();
20
    captureWorkerThread->start();
19
 
21
 
20
    // Connections
22
    // Connections
21
    qRegisterMetaType<cv::Mat>("cv::Mat");
23
    qRegisterMetaType<cv::Mat>("cv::Mat");
22
    qRegisterMetaType< std::vector<cv::Mat> >("std::vector<cv::Mat>");
24
    qRegisterMetaType< std::vector<cv::Mat> >("std::vector<cv::Mat>");
-
 
25
    qRegisterMetaType<CalibrationSet>("CalibrationSet");
23
    connect(captureWorker, SIGNAL(newFrame(unsigned int, cv::Mat)), this, SLOT(onReceiveFrame(unsigned int, cv::Mat)));
26
    connect(captureWorker, SIGNAL(newFrame(unsigned int, cv::Mat)), this, SLOT(onReceiveFrame(unsigned int, cv::Mat)));
-
 
27
    connect(captureWorker, SIGNAL(newCalibrationSet(CalibrationSet)), this, SLOT(onReceiveCalibrationSet(CalibrationSet)));
24
 
28
 
25
    // Start capturing
29
    // Start capturing
26
    QMetaObject::invokeMethod(captureWorker, "setup");
30
    QMetaObject::invokeMethod(captureWorker, "setup");
27
    QMetaObject::invokeMethod(captureWorker, "doWork");
31
    QMetaObject::invokeMethod(captureWorker, "doWork");
28
 
32
 
29
}
33
}
30
 
34
 
31
void SMScanner::onReceiveFrame(unsigned int camId, cv::Mat frame){
35
void SMScanner::onReceiveFrame(unsigned int camId, cv::Mat frame){
32
 
36
 
33
    if(camId == 0){
37
    if(camId == 0){
-
 
38
        if(!calibrationReviewMode)
34
        ui->calibrationCamera0Widget->showImageCV(frame);
39
            ui->calibrationCamera0Widget->showImageCV(frame);
35
        ui->captureCamera0Widget->showImageCV(frame);
40
        ui->captureCamera0Widget->showImageCV(frame);
36
    } else if(camId == 1){
41
    } else if(camId == 1){
-
 
42
        if(!calibrationReviewMode)
37
        ui->calibrationCamera1Widget->showImageCV(frame);
43
            ui->calibrationCamera1Widget->showImageCV(frame);
38
        ui->captureCamera1Widget->showImageCV(frame);
44
        ui->captureCamera1Widget->showImageCV(frame);
39
    }
45
    }
40
}
46
}
41
 
47
 
42
void SMScanner::on_actionPreferences_triggered(){
48
void SMScanner::on_actionPreferences_triggered(){
Line 65... Line 71...
65
    delete ui;
71
    delete ui;
66
}
72
}
67
 
73
 
68
void SMScanner::on_singleCalibrationButton_clicked(){
74
void SMScanner::on_singleCalibrationButton_clicked(){
69
 
75
 
-
 
76
    // If in review mode, go back to aquisition mode
-
 
77
    if(calibrationReviewMode){
-
 
78
        ui->singleCalibrationButton->setText("Single Aquisition");
-
 
79
        ui->batchCalibrationButton->setText("Batch Aquisition");
-
 
80
        calibrationReviewMode = false;
-
 
81
        return;
-
 
82
    }
-
 
83
 
70
    float position = ui->calibrationRotationDial->value();
84
    float position = ui->calibrationRotationDial->value();
71
    QMetaObject::invokeMethod(captureWorker, "acquireCalibrationSet", Q_ARG(float, position));
85
    QMetaObject::invokeMethod(captureWorker, "acquireCalibrationSet", Q_ARG(float, position));
72
 
86
 
73
}
87
}
74
 
88
 
Line 78... Line 92...
78
    QMetaObject::invokeMethod(captureWorker, "rotateTo", Q_ARG(float, angle));
92
    QMetaObject::invokeMethod(captureWorker, "rotateTo", Q_ARG(float, angle));
79
}
93
}
80
 
94
 
81
void SMScanner::onReceiveCalibrationSet(CalibrationSet calibrationSet){
95
void SMScanner::onReceiveCalibrationSet(CalibrationSet calibrationSet){
82
    calibrationData.push_back(calibrationSet);
96
    calibrationData.push_back(calibrationSet);
-
 
97
 
-
 
98
    // Add identifier to list
-
 
99
    QListWidgetItem* item = new QListWidgetItem(QString("Set %1").arg(ui->calibrationListWidget->count()), ui->calibrationListWidget);
-
 
100
    item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
-
 
101
    item->setCheckState(Qt::Checked);
-
 
102
    ui->calibrationListWidget->addItem(item);
-
 
103
 
-
 
104
    // Set enabled checkmark
-
 
105
    if(calibrationData.size() >= 2)
-
 
106
        ui->calibrateButton->setEnabled(true);
-
 
107
}
-
 
108
 
-
 
109
void SMScanner::on_calibrationListWidget_currentRowChanged(int currentRow){
-
 
110
 
-
 
111
    calibrationReviewMode = true;
-
 
112
    ui->singleCalibrationButton->setText("Live View");
-
 
113
    ui->batchCalibrationButton->setText("Live View");
-
 
114
 
-
 
115
    if(!calibrationData[currentRow].frame0Result.empty())
-
 
116
        ui->calibrationCamera0Widget->showImageCV(calibrationData[currentRow].frame0Result);
-
 
117
    else
-
 
118
        ui->calibrationCamera0Widget->showImageCV(calibrationData[currentRow].frame0);
-
 
119
 
-
 
120
    if(!calibrationData[currentRow].frame1Result.empty())
-
 
121
        ui->calibrationCamera1Widget->showImageCV(calibrationData[currentRow].frame1Result);
-
 
122
    else
-
 
123
        ui->calibrationCamera1Widget->showImageCV(calibrationData[currentRow].frame1);
-
 
124
}
-
 
125
 
-
 
126
void SMScanner::on_calibrateButton_clicked(){
-
 
127
 
-
 
128
    // set checked flags
-
 
129
    for(int i=0; i<calibrationData.size(); i++){
-
 
130
        calibrationData[i].checked = (ui->calibrationListWidget->item(i)->checkState() == Qt::Checked);
-
 
131
    }
-
 
132
 
-
 
133
    SMCalibrator calibrator;
-
 
134
    calibrator.performCalibration(calibrationData);
-
 
135
 
83
}
136
}