-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathwidget.h
80 lines (69 loc) · 2.46 KB
/
widget.h
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
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QImage>
#include <QVector>
#include <QMenuBar>
#include <stdint.h>
#include "poly.h"
extern QApplication* app;
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget();
~Widget();
static quint64 computeFitness(const QImage& target);
static QRect computeAutofocusFitness(const QImage& target);
Poly genPoly(); // Creates a new random polygon
QImage predraw(int polyIndex);
static void redraw(QImage& target, QVector<Poly>& polyList = polys);
void optimizeColors(int polyIndex, QVector<Poly>& newPolys=polys); // Will update generated directly
void optimizeColors(int polyIndex, QVector<Poly> &newPolys, QImage& predrawn); // Will update generated directly
void optimizeShape(int polyIndex, QVector<Poly> &newPolys=polys); // Will update generated directly
void optimizeShape(int polyIndex, QVector<Poly>& newPolys, QImage& predrawn); // Will update generated directly
void updateGuiFitness();
void run(); // Run the vectorizer's main loop
void setRunningGui();
void setStoppedGui();
bool virtual eventFilter(QObject *object, QEvent *event);
// Mutations
void tryAddPoly(); // Will gen one poly and add it to generated only if it improves fitness
void removePoly(QVector<Poly>&, QImage& target); // Will remove a poly, without testing if it improves fitness
void reorderPoly(QVector<Poly>&, QImage& target); // Will change the zorder of a poly, without testing if it improves fitness
void shapeOptPoly(QVector<Poly>& newPolys);
void movePoint(QVector<Poly>&, QImage& target);
static void setAutofocus(bool enabled);
protected:
void closeEvent(QCloseEvent *event);
private slots:
void openImageClicked();
void saveImageClicked();
void saveSVGClicked();
void importDnaClicked();
void exportDnaClicked();
void cleanDnaClicked();
void optimizeDnaClicked();
void startClicked();
void settingsClicked();
void githubClicked();
void focusClicked();
void redrawClicked();
void autofocusClicked();
private:
Ui::Widget *ui;
QMenuBar *menuBar;
QAction* startStopAction, *openAction, *cleanAction, *optimizeAction;
static QImage pic;
QImage generated;
bool running;
static QVector<Poly> polys;
static unsigned height, width;
quint64 fitness;
int generation;
static QTimer autofocusTimer;
};
#endif // WIDGET_H