2015-10-24 12:44:33 +00:00
|
|
|
#include "neuroui.h"
|
|
|
|
#include "ui_neuroui.h"
|
|
|
|
|
|
|
|
NeuroUI::NeuroUI(QWidget *parent) :
|
|
|
|
QMainWindow(parent),
|
|
|
|
ui(new Ui::NeuroUI)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2015-10-25 16:40:22 +00:00
|
|
|
|
|
|
|
ui->logView->addItem("Ready.");
|
2015-10-24 12:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NeuroUI::~NeuroUI()
|
|
|
|
{
|
2015-11-01 11:36:23 +00:00
|
|
|
if (m_netLearner != nullptr)
|
|
|
|
{
|
|
|
|
m_netLearner->cancelLearning();
|
|
|
|
m_netLearner->wait();
|
|
|
|
}
|
|
|
|
|
2015-10-24 12:44:33 +00:00
|
|
|
delete ui;
|
|
|
|
}
|
2015-10-24 16:03:07 +00:00
|
|
|
|
|
|
|
void NeuroUI::on_runButton_clicked()
|
|
|
|
{
|
|
|
|
ui->logView->clear();
|
2015-10-26 07:41:59 +00:00
|
|
|
ui->errorPlotter->clear();
|
2015-10-24 16:03:07 +00:00
|
|
|
|
|
|
|
if (m_netLearner == nullptr)
|
|
|
|
{
|
|
|
|
m_netLearner.reset(new NetLearner);
|
|
|
|
|
2015-10-26 16:54:06 +00:00
|
|
|
connect(m_netLearner.get(), &NetLearner::logMessage, this, &NeuroUI::logMessage);
|
|
|
|
connect(m_netLearner.get(), &NetLearner::progress, this, &NeuroUI::progress);
|
2015-10-24 16:03:07 +00:00
|
|
|
|
2015-10-26 16:54:06 +00:00
|
|
|
connect(m_netLearner.get(), &NetLearner::started, this, &NeuroUI::netLearnerStarted);
|
|
|
|
connect(m_netLearner.get(), &NetLearner::finished, this, &NeuroUI::netLearnerFinished);
|
2015-10-24 16:03:07 +00:00
|
|
|
|
2015-10-26 16:54:06 +00:00
|
|
|
connect(m_netLearner.get(), &NetLearner::currentNetError, ui->errorPlotter, &ErrorPlotter::addErrorValue);
|
2015-10-27 17:20:50 +00:00
|
|
|
|
|
|
|
connect(m_netLearner.get(), &NetLearner::sampleImageLoaded, this, &NeuroUI::setImage);
|
2015-10-26 16:54:06 +00:00
|
|
|
}
|
2015-10-26 07:41:59 +00:00
|
|
|
|
2015-10-24 16:03:07 +00:00
|
|
|
m_netLearner->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NeuroUI::logMessage(const QString &logMessage)
|
|
|
|
{
|
2015-11-16 16:49:40 +00:00
|
|
|
if (ui->logView->count() == static_cast<int>(m_logSize))
|
|
|
|
{
|
|
|
|
delete ui->logView->item(0);
|
|
|
|
}
|
|
|
|
|
2015-10-24 16:03:07 +00:00
|
|
|
ui->logView->addItem(logMessage);
|
|
|
|
ui->logView->scrollToBottom();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NeuroUI::netLearnerStarted()
|
|
|
|
{
|
|
|
|
ui->runButton->setEnabled(false);
|
2015-10-25 08:51:09 +00:00
|
|
|
ui->progressBar->setValue(0);
|
2015-10-24 16:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NeuroUI::netLearnerFinished()
|
|
|
|
{
|
|
|
|
ui->runButton->setEnabled(true);
|
2015-10-25 08:51:09 +00:00
|
|
|
ui->progressBar->setValue(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NeuroUI::progress(double progress)
|
|
|
|
{
|
|
|
|
double range = ui->progressBar->maximum() - ui->progressBar->minimum();
|
|
|
|
int value = ui->progressBar->minimum() + (int)(progress * range);
|
|
|
|
|
|
|
|
ui->progressBar->setValue(value);
|
2015-10-24 16:03:07 +00:00
|
|
|
}
|
2015-10-27 17:20:50 +00:00
|
|
|
|
|
|
|
void NeuroUI::setImage(const QImage &image)
|
|
|
|
{
|
|
|
|
QPixmap pixmap;
|
|
|
|
pixmap.convertFromImage(image);
|
|
|
|
ui->label->setPixmap(pixmap);
|
|
|
|
}
|