Rev 4 | Rev 24 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#include "SMScanner.h"
#include "ui_SMScanner.h"
#include <QMetaObject>
SMScanner::SMScanner(QWidget *parent) :QMainWindow(parent), ui(new Ui::SMScanner){
ui->setupUi(this);
// Restore geometry
this->restoreGeometry(settings.value("geometry/mainwindow").toByteArray());
this->restoreState(settings.value("state/mainwindow").toByteArray());
// Set up threads
captureWorker = new SMCaptureWorker;
captureWorkerThread = new QThread(this);
captureWorkerThread->setObjectName("captureWorkerThread");
captureWorker->moveToThread(captureWorkerThread);
captureWorkerThread->start();
// Connections
qRegisterMetaType<cv::Mat>("cv::Mat");
qRegisterMetaType< std::vector<cv::Mat> >("std::vector<cv::Mat>");
connect(captureWorker, SIGNAL(newFrame(unsigned int, cv::Mat)), this, SLOT(onReceiveFrame(unsigned int, cv::Mat)));
// Start capturing
QMetaObject::invokeMethod(captureWorker, "setup");
QMetaObject::invokeMethod(captureWorker, "doWork");
}
void SMScanner::onReceiveFrame(unsigned int camId, cv::Mat frame){
if(camId == 0){
ui->calibrationCamera0Widget->showImageCV(frame);
ui->captureCamera0Widget->showImageCV(frame);
} else if(camId == 1){
ui->calibrationCamera1Widget->showImageCV(frame);
ui->captureCamera1Widget->showImageCV(frame);
}
}
void SMScanner::on_actionPreferences_triggered(){
preferenceDialog.show();
}
void SMScanner::closeEvent(QCloseEvent *event){
// Stop capturing thread
connect(captureWorker, SIGNAL(finished()), captureWorker, SLOT(deleteLater()));
connect(captureWorker, SIGNAL(finished()), captureWorkerThread, SLOT(quit()));
QMetaObject::invokeMethod(captureWorker, "stopWork");
captureWorkerThread->quit();
captureWorkerThread->wait();
// Save window geometry
settings.setValue("geometry/mainwindow", this->saveGeometry());
settings.setValue("state/mainwindow", this->saveState());
event->accept();
}
SMScanner::~SMScanner(){
delete ui;
}
void SMScanner::on_singleCalibrationButton_clicked(){
float position = ui->calibrationRotationDial->value();
QMetaObject::invokeMethod(captureWorker, "acquireCalibrationSet", Q_ARG(float, position));
}
void SMScanner::on_calibrationRotationDial_sliderReleased(){
float angle = ui->calibrationRotationDial->value();
std::cout << "Rotation stage target: " << angle << std::endl;
QMetaObject::invokeMethod(captureWorker, "rotateTo", Q_ARG(float, angle));
}
void SMScanner::onReceiveCalibrationSet(CalibrationSet calibrationSet){
calibrationData.push_back(calibrationSet);
}