forked from AlexLeSang/ECOHT-ANN_2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
243 lines (215 loc) · 8.26 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#include "mainwindow.hpp"
#include "ui_mainwindow.h"
/*!
* \brief MainWindow::MainWindow
* \param parent
*/
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->stopButton->hide();
ui->qwtPlot->setTitle("Error");
ui->qwtPlot->setAxisTitle(ui->qwtPlot->xBottom, "Epoch");
ui->qwtPlot->setAxisTitle(ui->qwtPlot->yLeft,"Error");
ui->qwtPlot->setAxisAutoScale( ui->qwtPlot->xBottom, true );
ui->qwtPlot->setAxisAutoScale( ui->qwtPlot->yLeft, true );
ui->stopButton->setVisible( false );
ui->saveButton->setVisible( false );
zoom = new QwtPlotZoomer(ui->qwtPlot->canvas());
zoom->setRubberBandPen(QPen(Qt::white));
QPen pen = QPen( Qt::red );
curve.setRenderHint( QwtPlotItem::RenderAntialiased );
curve.setPen( pen );
curve.attach( ui->qwtPlot );
sendAlpha();
// INFO connect ui to mainwindow
{
QObject::connect( ui->saveImageButton, SIGNAL( clicked() ),
this, SLOT( saveImage() ) );
QObject::connect( ui->inputOpenButton, SIGNAL( clicked() ),
this, SLOT( openInputFile() ) );
QObject::connect( ui->saveButton, SIGNAL( clicked() ),
this, SLOT( openOutputFile() ) );
QObject::connect( ui->startButton, SIGNAL( clicked() ),
this, SLOT( start() ) );
QObject::connect( ui->startButton, SIGNAL( clicked( bool ) ),
ui->stopButton, SLOT( setVisible(bool) ) );
QObject::connect( ui->alphaMantiss, SIGNAL( valueChanged( double ) ),
this, SLOT( sendAlpha() ) );
QObject::connect( ui->alphaDegree, SIGNAL( valueChanged( int ) ),
this, SLOT( sendAlpha() ) );
}
// INFO connectio ui to ui
{
QObject::connect(ui->startButton,SIGNAL(clicked()),ui->stopButton,SLOT(show()));
}
// /* INFO connection ui to facade
{
QObject::connect( ui->stopButton, SIGNAL( clicked() ),
&Facade::getInstance(), SLOT( stopProcess() ) );
QObject::connect( ui->maxEpoch, SIGNAL( valueChanged(int) ),
&Facade::getInstance(), SLOT( setMaxNumberOfEpoh(int) ) );
QObject::connect( ui->numberOfNeurons, SIGNAL( valueChanged(int) ),
&Facade::getInstance(), SLOT( setNumberOfNeurons(int) ) );
}
// */
// /* INFO connection facade to ui
{
QObject::connect( &Facade::getInstance(), SIGNAL( processEnd() ),
ui->startButton, SLOT( show() ) );
QObject::connect( &Facade::getInstance(), SIGNAL( processEnd() ),
ui->saveButton, SLOT( show() ) );
QObject::connect( &Facade::getInstance(), SIGNAL( processEnd() ),
ui->stopButton, SLOT( hide() ) );
}
// */
// /* INFO connection facade to main window
{
// QObject::connect( &Facade::getInstance(), SIGNAL( sendInitialLayerInfo(LayerDescription)),
// this, SLOT( setInitialLayerInfo( LayerDescription ) ) );
QObject::connect( &Facade::getInstance(), SIGNAL( processEnd() ),
this, SLOT( displayResults() ) );
}
// */
// /* INFO connection main window to facade
{
QObject::connect( this, SIGNAL( setInputFileName(QString) ),
&Facade::getInstance(), SLOT( setInputFileName(QString) ) );
QObject::connect( this, SIGNAL( setOutputFileName(QString) ),
&Facade::getInstance(), SLOT( setOutputFileName(QString) ) );
QObject::connect( this, SIGNAL( setAlpha( double ) ),
&Facade::getInstance(), SLOT( setAlhpa( double ) ) );
}
// */
}
/*!
* \brief MainWindow::DisplayResults
*/
void MainWindow::displayResults()
{
// ui->qwtPlot->detachItems( QwtPlotItem::Rtti_PlotCurve, false );
// ui->qwtPlot->replot();
// const auto errorVector = Facade::getInstance().getErrors();
// QVector < QPointF > points( errorVector.size() );
// quint32 counter = 0;
// auto pointsIt = points.begin();
// // Create a
// for ( auto errorIt = errorVector.constBegin(); errorIt != errorVector.constEnd(); ++ errorIt, ++ pointsIt, ++ counter ) {
// (*pointsIt) = QPointF( counter, (*errorIt) );
// }
// QwtPointSeriesData * data = new QwtPointSeriesData(points);
// curve.setData(data);
// curve.attach( ui->qwtPlot );
// ui->qwtPlot->replot();
ui->qwtPlot->detachItems( QwtPlotItem::Rtti_PlotCurve, false );
ui->qwtPlot->replot();
const auto errorVector = Facade::getInstance().getErrors();
QVector < QPointF > points( errorVector.size() );
quint32 counter = 0;
auto pointsIt = points.begin();
// Create a
for ( auto errorIt = errorVector.constBegin(); errorIt != errorVector.constEnd(); ++ errorIt, ++ pointsIt, ++ counter ) {
(*pointsIt) = QPointF( counter, (*errorIt) );
}
QwtPointSeriesData * data = new QwtPointSeriesData(points);
curve.setData(data);
// curve.setSamples( QPolygonF ( points ) );
curve.attach( ui->qwtPlot );
ui->qwtPlot->replot();
}
/*!
* \brief MainWindow::saveImage
*/
void MainWindow::saveImage()
{
QString filename = QFileDialog::getSaveFileName(this,tr("Save Image"), "image.png", tr("Image Files (*.png *.jpg *.bmp)"));
QPixmap pixmap = QPixmap::grabWidget(ui->qwtPlot);
pixmap.save(filename);
}
/*!
* \brief MainWindow::changeLayers
* \param layersNumber
*/
/*!
* \brief MainWindow::showResults
* \param data
*/
void MainWindow::showResults(const Dataset & data)
{
const quint32 tableWidth = data.first().first.size() + data.first().second.size();
const quint32 inputLength = data.first().first.size();
//ui->resultsTable->setColumnCount( tableWidth );
//ui->resultsTable->setRowCount( data.size() );
QStringList labelsList;
for ( qint32 i=1; i <= data.first().first.size(); ++i ){
labelsList.append( QString( "x" ) + QString::number( i ) );
}
for ( qint32 i=1; i <= data.first().second.size(); ++i ){
labelsList.append( QString( "y" ) + QString::number( i ) );
}
//ui->resultsTable->setHorizontalHeaderLabels( labelsList );
for ( auto it = data.constBegin(); it != data.constEnd(); ++it ){
for ( auto itInputs = (*it).first.constBegin(); itInputs != (*it).first.constEnd(); ++itInputs ){
QTableWidgetItem *item = new QTableWidgetItem( QString::number( *itInputs ));
// ui->resultsTable->setItem( it - data.constBegin(), itInputs - (*it).first.constBegin(), item );
}
for ( auto itOutputs = (*it).second.constBegin(); itOutputs != (*it).second.constEnd(); ++itOutputs ){
QTableWidgetItem *item = new QTableWidgetItem( QString::number( *itOutputs ));
// ui->resultsTable->setItem( it - data.constBegin(), itOutputs - (*it).second.constBegin() + inputLength, item );
}
}
}
void MainWindow::keyPressEvent(QKeyEvent *e)
{
if(e->modifiers() == Qt::ControlModifier && (e->key() == Qt::Key_S || e->key() == Qt::Key_Z || e->key() == Qt::Key_X) && ui->stopButton->isHidden()){
this->start();
}
}
/*!
* \brief MainWindow::~MainWindow
*/
MainWindow::~MainWindow()
{
Facade::getInstance().stopProcess();
delete zoom;
delete ui;
}
/*!
* \brief MainWindow::openFile
*/
void MainWindow::openInputFile()
{
const QString fileName = QFileDialog::getOpenFileName( this, tr("Open data file"), "", tr("Data files (*.dat)"));
if(fileName.isNull()) return;
ui->currentFileName->setText( fileName );
emit setInputFileName( fileName );
}
/*!
* \brief MainWindow::openOutputFile
*/
void MainWindow::openOutputFile()
{
const QString fileName = QFileDialog::getOpenFileName( this, tr("Open result file"), "", tr("Result files (*.res)"));
if(fileName.isNull()) return;
emit setOutputFileName( fileName );
}
/*!
* \brief MainWindow::start
*/
void MainWindow::start()
{
if(!ui->currentFileName->text().isEmpty()){
Facade::getInstance().startProcess();}
ui->stopButton->show();
}
/*!
* \brief MainWindow::sendAlpha
*/
void MainWindow::sendAlpha()
{
const double mantis = ui->alphaMantiss->value();
const int deg = ui->alphaDegree->value();
emit setAlpha( mantis * pow10( deg ) );
}