-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAlgorithmBase.h
More file actions
69 lines (55 loc) · 1.69 KB
/
AlgorithmBase.h
File metadata and controls
69 lines (55 loc) · 1.69 KB
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
#ifndef ALGORITHMBASE_H
#define ALGORITHMBASE_H
#include <QThread>
#include <QTimer>
#include <QImage>
#include <random>
/**
* This aim of this class is to move the processing of the image onto a
* different thread, while also making it easy to switch between multiple
* different algorithms.
*
* This class should entirely be interacted with using "Qt::QueuedConnection"s
*/
class AlgorithmBase : public QThread {
Q_OBJECT
public:
explicit AlgorithmBase(QObject *parent = nullptr);
virtual ~AlgorithmBase();
void SetTargetImage(const QImage& target);
void SetRgbImage(const QImage& rgb);
/**
* @return A user visible string that uniquely identifies this algorithm.
*/
virtual QString GetName() = 0;
/**
* @return A user visible string that gives a brief explanation as to what
* this algorithm does
*/
virtual QString GetDescription() = 0;
signals:
void onIterationsChanged(qulonglong iterations);
void onImprovementsChanged(qulonglong improvements);
void onUpdated(QImage allRgb);
public slots:
void onStartRequested();
void onStopRequested();
void onGetUpdateRequested();
protected:
QImage target_;
QImage allRgb_;
qulonglong iterations_;
qulonglong improvements_;
int RandomNumber(int min, int max) const;
int ColourDifference(QRgb a, QRgb b) const;
private:
inline static std::mt19937 entropy_ = std::mt19937();
QTimer iterateTimer_;
/**
* @brief Iterate Should do some work towards "solving" the allRGB image.
* iterations and improvements should be updated if necessary, and their
* signals emitted;
*/
virtual void Iterate() = 0;
};
#endif // ALGORITHMBASE_H