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

Separates calibration from GUI

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