-
Notifications
You must be signed in to change notification settings - Fork 0
/
FilmWidget.h
252 lines (214 loc) · 7.63 KB
/
FilmWidget.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
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
244
245
246
247
248
249
250
251
252
/* ***************************************************************************
* FilmWidget.h: defines a widget to display and analyze xrd patterns
* author: Joe Petrus
* date: June 10th 2010
* ***************************************************************************/
#ifndef FilmWidget_H
#define FilmWidget_H
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* Headers, definitions, etc.
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
/* Qt related headers */
#include <QMainWindow>
#include <QLabel>
#include <QPrinter>
#include <QMouseEvent>
#include <QPen>
#include <QtGui>
#include <QRect>
#include <QDesktopWidget>
#include <QMatrix>
#include <QRgb>
#include <QVarLengthArray>
/* Standard c++ headers */
#include <iostream>
#include <cmath>
#include <fstream>
#include <ctime>
/* Qwt related headers */
#ifdef __APPLE__
#include "/usr/local/qwt-5.2.2/include/qwt.h"
#include "/usr/local/qwt-5.2.2/include/qwt_plot.h"
#include "/usr/local/qwt-5.2.2/include/qwt_plot_zoomer.h"
#include "/usr/local/qwt-5.2.2/include/qwt_plot_picker.h"
#include "/usr/local/qwt-5.2.2/include/qwt_painter.h"
#include "/usr/local/qwt-5.2.2/include/qwt_plot_canvas.h"
#include "/usr/local/qwt-5.2.2/include/qwt_plot_marker.h"
#include "/usr/local/qwt-5.2.2/include/qwt_plot_curve.h"
#include "/usr/local/qwt-5.2.2/include/qwt_scale_widget.h"
#include "/usr/local/qwt-5.2.2/include/qwt_legend.h"
#include "/usr/local/qwt-5.2.2/include/qwt_scale_draw.h"
#include "/usr/local/qwt-5.2.2/include/qwt_math.h"
#else
#include "c:\qwt-5.2.0/include/qwt.h"
#include "c:\qwt-5.2.0/include/qwt_plot.h"
#include "c:\qwt-5.2.0/include/qwt_plot_zoomer.h"
#include "c:\qwt-5.2.0/include/qwt_plot_picker.h"
#include "c:\qwt-5.2.0/include/qwt_painter.h"
#include "c:\qwt-5.2.0/include/qwt_plot_canvas.h"
#include "c:\qwt-5.2.0/include/qwt_plot_marker.h"
#include "c:\qwt-5.2.0/include/qwt_plot_curve.h"
#include "c:\qwt-5.2.0/include/qwt_scale_widget.h"
#include "c:\qwt-5.2.0/include/qwt_legend.h"
#include "c:\qwt-5.2.0/include/qwt_scale_draw.h"
#include "c:\qwt-5.2.0/include/qwt_math.h"
#endif
/* Program headers */
#include "LogWidget.h"
#include "AppConfig.h"
#include "TwoThetaWindow.h"
using namespace std;
/* Definitions */
#define pow2(x) pow(x,2.0)
#define UPPER_REGION 0
#define LOWER_REGION 1
#define ZERO_DEGREES 0
#define ONEEIGHTY_DEGREES 1
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* Structures
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
struct Geometry
{
QPoint zeroDegreeCenter;
QPoint zeroDegreeGuess;
QPoint oneEightyDegreeCenter;
QPoint oneEightyDegreeGuess;
double phi;
double alpha;
double radius;
double sharpness;
bool integrated;
QPoint *activeCenter;
Geometry() : zeroDegreeCenter(QPoint(0,0)), zeroDegreeGuess(QPoint(0,0)),
oneEightyDegreeCenter(QPoint(0,0)), oneEightyDegreeGuess(QPoint(0,0)),
phi(0.0), alpha(0.0), radius(0.0), sharpness(0.0), integrated(false),
activeCenter(&zeroDegreeCenter) {}
};
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* Main class definition
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
/* ***************************************************************************
* class: FilmWidget
* description: QWidget based on QLabel to display and manipulate xrd patterns.
* ***************************************************************************/
class FilmWidget : public QLabel
{
Q_OBJECT
public:
FilmWidget(QWidget *parent, QStatusBar *_sb, LogWidget *_log, AppConfig &_appConfig );
/* Film access methods */
void setFilm(QString);
QImage getFilm() { return *filmData; }
double getScaleFactor() { return scaleFactor; }
void setScaleFactor(double sf) { scaleFactor = sf; }
int getDPM() { return filmDPM; }
int getDPI() { return filmDPM*0.0254; }
double getRadius() { return currentGeometry.radius; }
void setRadius(double _R) { currentGeometry.radius = _R; }
void setDPM(int dpm) { filmDPM = dpm; }
void setData(QImage d) { filmData = new QImage(d); }
QMainWindow *getTwoThetaPlot() { return twoThetaWindow; }
void updateIntArea();
void updateGeometry();
QRect getIntArea() { return intArea; }
bool isIntegrated() { return currentGeometry.integrated; }
Geometry* getGeometry() { return ¤tGeometry; }
Geometry* getPreviousGeometry() { return &previousGeometry; }
QRect getQRectFromAngleRange(double start, double stop);
double* getAngleRangeFromQRect(QRect r);
/* Film analysis methods */
double integrate(double resolution = 0.025, int xo = 0, int yo = 0);
double integrateRegion(double res, int xo, int yo, QRect reg);
double integrateRegionDifference(double res, int xo, int yo, QRect regA, QRect regB);
QPoint optimizeCenterXSharpness(int location = ZERO_DEGREES);
QPoint optimizeCenterXSymmetry(int location = ZERO_DEGREES);
QPoint optimizeCenterYSharpness(int location = ZERO_DEGREES);
QPoint optimizeCenterYSymmetry(int location = ZERO_DEGREES);
double optimizeRadiusSharpness();
double optimizePhiSharpness();
double optimizeAlphaSharpness();
double optimizeRadiusSymmetry();
double optimizeRotationSymmetry();
double residual(int cgx, int cgy, QImage *data);
double regionIntensity(QRect r, QImage *d);
/* UI methods */
void showTwoThetaWindow() { twoThetaWindow->show(); }
void setAltDown(bool ad) { altDown = ad; }
void setMoveActive(bool ma) { moveActive = ma; }
void setResizeActive(bool ra) { resizeActive = ra; }
void setExcludeActive(bool ea) { excludeActive = ea; }
void setImage(QImage newImage);
QPoint rotatePoint(QPoint in, double a);
public slots:
void startCrop();
void startDeskew();
void invert();
void darken();
void lighten();
void rotate();
void rotate(double a);
void closeFilm();
/* IO methods */
void saveTIFF();
void saveUDF();
void saveCSV();
void getCurrentConfigValues();
void moveOptimizationRegion(QAction*);
void saveOptimizationRegion();
signals:
void geometryUpdated();
/* Protected members */
protected:
/* Widget events */
void mousePressEvent( QMouseEvent* );
void mouseReleaseEvent( QMouseEvent* );
void mouseMoveEvent( QMouseEvent* );
void paintEvent( QPaintEvent* );
//void keyPressEvent(QKeyEvent* );
//void keyReleaseEvent(QKeyEvent* );
/* Private members */
private:
AppConfig *appConfig;
/* Film variables */
QImage *filmData;
double filmDPM;
double lambda;
QString suggestedName;
/* UI elements */
double scaleFactor;
QStatusBar *sb;
LogWidget *log;
TwoThetaWindow *twoThetaWindow;
//TwoThetaPlot *twoThetaWindow;
bool altDown;
bool moveActive;
bool resizeActive;
bool excludeActive;
int mouseStartX;
int mouseStartY;
int cropPhase;
QPoint cropPoint1;
QPoint cropPoint2;
int deskewPhase;
QPoint deskewPoint1;
QPoint deskewPoint2;
/* Integration variables */
QRect intArea;
double **intData;
double intResolution;
/* Points and areas */
QPoint guessCenter0;
QPoint guessCenter180;
QPoint *guessCenter;
QRect optRegion0A;
QRect optRegion0B;
QRect optRegion180A;
QRect optRegion180B;
QRect optRegionSh;
QRect *optRegionA;
QRect *optRegionB;
QVector<QRect> excludeRegions;
Geometry currentGeometry;
Geometry previousGeometry;
};
#endif