-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimagegen.h
120 lines (99 loc) · 4.85 KB
/
imagegen.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
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
#ifndef IMAGEGEN_H
#define IMAGEGEN_H
#include <QObject>
#include <QPoint>
#include <QRect>
#include <QList>
#include <QPainter>
#include <QGraphicsView>
#include "datatypes.h"
#include "colourmap.h"
void ImageDataDealloc(void * info);
/** ****************************************************************************
* @brief The ImageGen class
*/
class ImageGen : public QObject
{
Q_OBJECT
public:
// PROGRAM SETTINGS
static constexpr qreal templateOversizeFactor = 1.2; // The amount of extra length that the templates are calculated for (to prevent repeated recalculations)
static constexpr int trigTableLen = 10000;
private:
MainWindow * mainWindow = nullptr;
bool pendingQuickImage; // True if a quick image is pending to be generated
bool pendingPreviewImage; // True if a preview image is pending to be generated
bool hideEmitters = true; // When true, the emitters are not drawn on the preview window
double sinTable[trigTableLen]; // Pre-calculated sin values. Indices 0 to trigTableLen correspond to 0 to 2pi rad
double cosTable[trigTableLen]; // Pre-calculated cos values. Indices 0 to trigTableLen correspond to 0 to 2pi rad
inline double sinQuick(double rad) {return sinTable[modPos((int)(rad*(double)trigTableLen/(2.*PI)),trigTableLen)];}
inline double cosQuick(double rad) {return cosTable[modPos((int)(rad*(double)trigTableLen/(2.*PI)),trigTableLen)];}
public:
Settings s; // Contains entire setup
// The block below must be kept in sync
GenSettings genPreview;
GenSettings genQuick;
QRectF areaSim; // The rectangle of the image view area (simulation coordinates)
// For the final rendered image:
qint32 outHeightPix = 1080; // The output will be rendered to this many pixels high
bool saveWithTransparency = false; // If true, when an image with a mask is saved, it will be saved with transparency. If false, then the background colour will be rendered into the image
QImage imgPreview;
QImage imgQuick;
qint32 testVal = 1;
ColourMap colourMap;
public:
ImageGen();
void SetMainWindow(MainWindow * mainWindowIn) {mainWindow = mainWindowIn;}
void NewPreviewImageNeeded();
void NewQuickImageNeeded();
void NewImageNeeded();
int GenerateImage(QImage &imageOut, GenSettings &genSet);
EmArrangement *GetActiveArrangement();
int InitViewAreas();
int GetEmitterList(QVector<EmitterF> &emitters);
static void DebugEmitterLocs(const QVector<EmitterI>& emittersImg);
static void DebugEmitterLocs(const QVector<EmitterF> &emittersF);
static EmArrangement DefaultArrangement();
void setTargetImgPoints(qint32 imgPoints, GenSettings &genSet) const;
void setDistOffsetF(qreal in) {s.distOffsetF = in;}
qreal getDistOffsetF() const {return s.distOffsetF;}
bool EmittersHidden();
void SaveImage(); // Saves to a file
void AddArrangement(EmArrangement emArrangementIn); // Adds the given emitter arrangement
void ResetSettings();
signals:
void NewImageReady(QImage & image, qreal imgPerSimUnitOut, QColor backgroundClr); // A new image is ready
void EmitterArngmtChanged(); // Emitted when the emitter locations change
void GenerateImageSignal(); // Just used to queue up GenerateImageSlot
void OverlayTextSignal(QString text);
public slots:
void EmitterCountDecrease();
void EmitterCountIncrease();
void WavelengthDecrease();
void WavelengthIncrease();
void HideEmitters(bool hide) {
hideEmitters = hide;
emit EmitterArngmtChanged();
}
bool GetHideEmitters() { return hideEmitters; }
private slots:
void GenerateImageSlot();
private:
static void CalcDistArr(double simUnitPerIndex, Double2D_C &arr);
static void CalcAmpArr(double distOffset, const Double2D_C &distArr, Double2D_C &Arr);
static void CalcPhasorArr(TemplatePhasor& templatePhasor,
const Double2D_C & templateDist, const Double2D_C & templateAmp);
static QRgb ColourAngleToQrgb(int32_t angle, uint8_t alpha = 255);
void AddPhasorArr(double imgPerSimUnit, double wavelength, EmitterI e, const Double2D_C & templateDist,
const Double2D_C & templateAmp, Complex2D_C & phasorArr);
static void AddPhasorArr(const EmitterI& e, const Double2D_C &templateDist, const Double2D_C &templateAmp, const Complex2D_C &templatePhasor, Complex2D_C &phasorArr);
static int EmitterArrangementToLocs(const EmArrangement &arngmt, QVector<QPointF> &emLocsOut);
void CalcDistTemplate(QRect templateRect, GenSettings &genSet);
void CalcAmpTemplate(qreal distOffset, GenSettings &genSet);
void CalcPhasorTemplate(QRect templateRect, GenSettings &genSet);
void PreCalcTrigTables();
int GenerateImageWaves(QImage &imageOut, GenSettings &genSet);
int GenerateImageFourBar(QImage &imageOut, GenSettings &genSet);
};
extern ImageGen imageGen;
#endif // IMAGEGEN_H