Commit 5a0bef49 authored by Thiago C. Santini's avatar Thiago C. Santini

Separates calibration from GUI

parent 178a692a
......@@ -3,6 +3,8 @@
Calibration::Calibration()
{
collecting = false;
calibrating = false;
calibrated = false;
reset();
}
......
......@@ -6,8 +6,6 @@ Gui::Gui(QWidget *parent) :
ui(new Ui::Gui)
{
ui->setupUi(this);
calibration.calibrating = false;
calibration.calibrated = false;
ui->calibrationStatus->setStyleSheet("color:red");
ui->calibrationStatus->setText("Not calibrated.");
ui->discardButton->hide();
......@@ -120,9 +118,9 @@ void Gui::update(JournalEntry journalEntry)
line(eyeCanvas, journalEntry.pupil.center - h, journalEntry.pupil.center + h, green, 3);
line(eyeCanvas, journalEntry.pupil.center - v, journalEntry.pupil.center + v, green, 3);
}
if (calibration.calibrating) {
calibration.addPoint(QPoint(journalEntry.pupil.center.x, journalEntry.pupil.center.y));
ui->calibrationStatus->setText(calibration.statusStr());
if (calibration->calibrating) {
calibration->addPoint(QPoint(journalEntry.pupil.center.x, journalEntry.pupil.center.y));
ui->calibrationStatus->setText(calibration->statusStr());
}
}
......@@ -134,11 +132,11 @@ void Gui::update(JournalEntry journalEntry)
// we get RGB anyway so we need to convert
cvtColor(journalEntry.fieldFrame, fieldCanvas, CV_RGB2BGR);
if (calibration.calibrating){
for (int i=0; i<calibration.fieldPoints.size(); i++){
circle(fieldCanvas, calibration.fieldPoints[i], 5, green, -1);
if (calibration->calibrating){
for (int i=0; i<calibration->fieldPoints.size(); i++){
circle(fieldCanvas, calibration->fieldPoints[i], 5, green, -1);
}
ui->discardButton->setText(calibration.discardButtonStr);
ui->discardButton->setText(calibration->discardButtonStr);
int w = fieldCanvas.cols;
int h = fieldCanvas.rows;
QPoint mousePosition = ui->fieldCamView->mapFromGlobal(QCursor::pos());
......@@ -148,7 +146,7 @@ void Gui::update(JournalEntry journalEntry)
}
}
if ( (calibration.calibrated) && (journalEntry.eye_valid!=0) ) {
if ( (calibration->calibrated) && (journalEntry.eye_valid!=0) ) {
int x = journalEntry.fieldProjection.x;
int y = journalEntry.fieldProjection.y;
int w = fieldCanvas.cols;
......@@ -160,7 +158,7 @@ void Gui::update(JournalEntry journalEntry)
}
// set views
if (calibration.calibrating || (!swapViews) ) {
if (calibration->calibrating || (!swapViews) ) {
ui->leftEyeCamView->setPixmap( matToPixmap(eyeCanvas).scaled(ui->leftEyeCamView->size()) );
ui->fieldCamView->setPixmap( matToPixmap(fieldCanvas).scaled(ui->fieldCamView->size()) );
} else {
......@@ -169,8 +167,8 @@ void Gui::update(JournalEntry journalEntry)
}
// Texts
ui->calibrationPoints->setText(QString("Points: %1").arg(calibration.pointCount));
if (calibration.calibrating && calibration.fieldPoints.size() > 0)
ui->calibrationPoints->setText(QString("Points: %1").arg(calibration->pointCount));
if (calibration->calibrating && calibration->fieldPoints.size() > 0)
ui->discardButton->setEnabled(true);
if (recording) {
......@@ -190,7 +188,7 @@ void Gui::update(JournalEntry journalEntry)
void Gui::mousePressEvent(QMouseEvent *event)
{
if (! calibration.calibrating)
if (! calibration->calibrating)
return;
int vx = ui->fieldCamView->pos().x();
......@@ -208,7 +206,7 @@ void Gui::mousePressEvent(QMouseEvent *event)
if ( (ey < vy) || ( ey > vy + vh) ) // outside the y axis
return;
calibration.startCollection(QPoint(
calibration->startCollection(QPoint(
event->pos().x() - vx,
event->pos().y() - vy
)
......@@ -227,38 +225,38 @@ void Gui::keyPressEvent(QKeyEvent *event)
void Gui::on_discardButton_clicked()
{
if (calibration.calibrating)
calibration.discardLast();
if (calibration->calibrating)
calibration->discardLast();
if (calibration.fieldPoints.size() == 0)
if (calibration->fieldPoints.size() == 0)
ui->discardButton->setEnabled(false);
}
void Gui::on_startCalibration_clicked()
{
if (calibration.calibrating) {
if (calibration.calibrate()) {
if (calibration->calibrating) {
if (calibration->calibrate()) {
ui->calibrationStatus->setStyleSheet("color:green");
ui->calibrationStatus->setText("Calibrated.");
calibration.calibrated = true;
calibration->calibrated = true;
}
else {
ui->calibrationStatus->setStyleSheet("color:red");
ui->calibrationStatus->setText("Not calibrated.");
}
ui->discardButton->hide();
calibration.calibrating = false;
calibration->calibrating = false;
ui->startCalibration->setText("Start");
ui->startRecording->setEnabled(true);
ui->changeSubject->setEnabled(true);
} else {
calibration.calibrated = false;
calibration.calibrating = true;
calibration.reset();
calibration->calibrated = false;
calibration->calibrating = true;
calibration->reset();
ui->calibrationStatus->setStyleSheet("color:black");
ui->calibrationStatus->setText(calibration.statusStr());
ui->calibrationStatus->setText(calibration->statusStr());
ui->startCalibration->setText("Finish");
......@@ -380,7 +378,7 @@ void Gui::on_swapViews_clicked()
void Gui::recordingStarted()
{
calibration.dumpCalibrationInfo();
calibration->dumpCalibrationInfo();
if (settings.value("trigger/keyboard").toBool())
keyboardTrigger.open(getNamePrefix().append(QString("keyboard-%1.txt").arg(gFileIndexStr)).toStdString());
}
......
......@@ -27,7 +27,7 @@ class Gui : public QMainWindow
public:
explicit Gui(QWidget *parent = 0);
~Gui();
Calibration calibration;
Calibration *calibration;
public slots:
void update(JournalEntry journalEntry);
......
......@@ -16,6 +16,8 @@
#include "Journal.h"
#include "Gui.h"
#include "Calibration.h"
#include "settings.h"
#include "utils.h"
......@@ -66,6 +68,8 @@ int main(int argc, char *argv[])
qInstallMessageHandler(logMessages);
initBanner();
Calibration *calibration = new Calibration();
/*********************************************************************
* Instantiate the stages
********************************************************************/
......@@ -97,12 +101,13 @@ int main(int argc, char *argv[])
splash.showMessage("Starting GUI...", Qt::AlignAbsolute, Qt::white);
app.processEvents();
Gui gui;
gui.calibration = calibration;
// User triggers that are not handled by other objects/threads
splash.showMessage("Starting triggers...", Qt::AlignAbsolute, Qt::white);
Trigger trigger;
imageProcessing.calibration = &gui.calibration;
imageProcessing.calibration = calibration;
/*********************************************************************
* Connect signals & slots
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment