1 | /*
|
---|
2 | * QtGl.h
|
---|
3 | *
|
---|
4 | * Created on: Jul 20, 2011
|
---|
5 | * Author: lyard
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef QTGL_H_
|
---|
9 | #define QTGL_H_
|
---|
10 |
|
---|
11 | #define NBOARDS 40 // max. number of boards
|
---|
12 | #define NPIX 1440 // max. number of pixels
|
---|
13 | #define NTMARK 160 // max. number of timeMarker signals
|
---|
14 |
|
---|
15 | //#define LOAD_RAW
|
---|
16 |
|
---|
17 | #include <QtCore/QObject>
|
---|
18 | #include <QtCore/QTimer>
|
---|
19 | #include <QtGui/QLabel>
|
---|
20 | #include <QtGui/QListWidget>
|
---|
21 | #include <QtGui/QMainWindow>
|
---|
22 | #include <QtOpenGL/QGLWidget>
|
---|
23 | #include <QtGui/QMouseEvent>
|
---|
24 | #include <QtGui/QColorDialog>
|
---|
25 | #include <QtGui/QApplication>
|
---|
26 | #include <QtGui/QSpinBox>
|
---|
27 | #include <QtGui/QDoubleSpinBox>
|
---|
28 | #include <QtGui/QRadioButton>
|
---|
29 | #include <QtGui/QCheckBox>
|
---|
30 | #include <iostream>
|
---|
31 | #include <GL/gl.h>
|
---|
32 |
|
---|
33 | #include <qwt-qt4/qwt_plot.h>
|
---|
34 | //#include "qwt_plot_histogram.h"
|
---|
35 | #include <qwt-qt4/qwt_plot_curve.h>
|
---|
36 |
|
---|
37 | #include <qwt-qt4/qwt_plot_zoomer.h>
|
---|
38 |
|
---|
39 | #include <valarray>
|
---|
40 |
|
---|
41 | #include <string>
|
---|
42 | #include "externals/fits.h"
|
---|
43 |
|
---|
44 | using namespace std;
|
---|
45 |
|
---|
46 | #define NUM_STORED_EVENTS 5
|
---|
47 | #define MAX_NUM_PIXELS 1600
|
---|
48 | #define ACTUAL_NUM_PIXELS 1440
|
---|
49 |
|
---|
50 | ///structure for storing edges of hexagons (for blurry display)
|
---|
51 | struct edge
|
---|
52 | {
|
---|
53 | int first;
|
---|
54 | int second;
|
---|
55 | };
|
---|
56 |
|
---|
57 | ///structure for storing neighbors of pixels. For camera position calculation and blurry display
|
---|
58 | struct PixelsNeighbors
|
---|
59 | {
|
---|
60 | //neighbors. clockwise, starting from top
|
---|
61 | int neighbors[6];
|
---|
62 | PixelsNeighbors()
|
---|
63 | {
|
---|
64 | for (int i=0;i<6;i++)
|
---|
65 | neighbors[i] = -1;
|
---|
66 | }
|
---|
67 | int& operator[](int index){return neighbors[index];}
|
---|
68 | };
|
---|
69 |
|
---|
70 | /*************************************************
|
---|
71 | * Class Raw Data Viewer. FACT raw data diplayer
|
---|
72 | *************************************************/
|
---|
73 | class RawDataViewer : public QGLWidget
|
---|
74 | {
|
---|
75 | Q_OBJECT
|
---|
76 |
|
---|
77 | friend class UIConnector;
|
---|
78 | public:
|
---|
79 | RawDataViewer(QWidget *parent = 0);
|
---|
80 | ~RawDataViewer();
|
---|
81 | void openFile(string& file);
|
---|
82 | void openCalibFile(string& file);
|
---|
83 |
|
---|
84 | public Q_SLOTS:
|
---|
85 | void plusEvent();
|
---|
86 | void minusEvent();
|
---|
87 | void setEventStep(int step);
|
---|
88 | void nextSlice();
|
---|
89 | void previousSlice();
|
---|
90 |
|
---|
91 | Q_SIGNALS:
|
---|
92 | void signalCurrentEvent(int event);
|
---|
93 | void signalCurrentSlice(int slice);
|
---|
94 | void newFileLoaded();
|
---|
95 | void signalCurrentPixel(int pixel);
|
---|
96 |
|
---|
97 | protected:
|
---|
98 | void initializeGL();
|
---|
99 | void resizeGL(int width, int height);
|
---|
100 | void paintGL();
|
---|
101 | void mousePressEvent(QMouseEvent *event);
|
---|
102 | void mouseMoveEvent(QMouseEvent *event);
|
---|
103 | void mouseDoubleClickEvent(QMouseEvent *event);
|
---|
104 | void drawCamera(bool alsoWire);
|
---|
105 | void drawPatches();
|
---|
106 | int PixelAtPosition(const QPoint &pos);
|
---|
107 | void drawHexagon(int index, bool solid);
|
---|
108 | int selectedPixel;
|
---|
109 | float *eventData;
|
---|
110 | int16_t* rawEventData;
|
---|
111 |
|
---|
112 | private:
|
---|
113 | void drawPixelCurve();
|
---|
114 | void updateNeighbors(int currentPixel);
|
---|
115 | void skipPixels(int start, int howMany);
|
---|
116 | void calculatePixelsCoords();
|
---|
117 | void setCorrectSlice(QMouseEvent* event);
|
---|
118 | void eventStepping(bool plus);
|
---|
119 | void buildVerticesList();
|
---|
120 | void buildPatchesIndices();
|
---|
121 | void calcBlurColor(int pixel, int vertex);
|
---|
122 | void drawBlurryHexagon(int index);
|
---|
123 | float hexRadius;
|
---|
124 | float hexTolerance;
|
---|
125 | float viewSize;
|
---|
126 | int whichSlice;
|
---|
127 | float pixelSize;
|
---|
128 | float shownSizex;
|
---|
129 | float shownSizey;
|
---|
130 | bool drawPatch;
|
---|
131 | bool drawImpulse;
|
---|
132 | bool drawBlur;
|
---|
133 | bool loopCurrentEvent;
|
---|
134 | //allocate the maximum size for one event
|
---|
135 | uint32_t boardTime[NBOARDS];
|
---|
136 | int16_t startPix[NPIX];
|
---|
137 | int16_t startTM[NTMARK];
|
---|
138 | uint32_t pcTime;
|
---|
139 | uint32_t softTrig;
|
---|
140 | uint16_t triggerType;
|
---|
141 | int nRows;
|
---|
142 | int rowNum;
|
---|
143 | int eventNum;
|
---|
144 | int nRoi;
|
---|
145 | int nRoiTM;
|
---|
146 | int runNumber;
|
---|
147 | int nTM;
|
---|
148 | int runType;
|
---|
149 | int firstDataTime;
|
---|
150 | int lastDataTime;
|
---|
151 | int revision;
|
---|
152 | int builderVersion;
|
---|
153 | int nBoards;
|
---|
154 | int nPixels;
|
---|
155 | string timeSystem;
|
---|
156 | string creationDate;
|
---|
157 | int nightInt;
|
---|
158 | string camera;
|
---|
159 | string daq;
|
---|
160 | float adcCount;
|
---|
161 | int nbOk;
|
---|
162 | int nbRej;
|
---|
163 | int nbBad;
|
---|
164 |
|
---|
165 | int eventStep;
|
---|
166 |
|
---|
167 | int hardwareMapping[1440];
|
---|
168 | int softwareMapping[1440];
|
---|
169 | int patches[160][9];
|
---|
170 | GLfloat patchesColor[160][3];
|
---|
171 | vector<edge> patchesIndices[160];
|
---|
172 | fits* inputFile;
|
---|
173 | fits* calibInputFile;
|
---|
174 | float baseLineMean[1440*1024];
|
---|
175 | float gainMean[1440*1024];
|
---|
176 | float triggerOffsetMean[1440*1024];
|
---|
177 | bool calibrationLoaded;
|
---|
178 | bool drawCalibrationLoaded;
|
---|
179 |
|
---|
180 | QPoint lastPos;
|
---|
181 |
|
---|
182 | GLfloat pixelsCoords[MAX_NUM_PIXELS][3];
|
---|
183 | PixelsNeighbors neighbors[MAX_NUM_PIXELS];
|
---|
184 | GLfloat pixelsColor[ACTUAL_NUM_PIXELS][3];
|
---|
185 | GLfloat verticesList[ACTUAL_NUM_PIXELS*6][2];
|
---|
186 | int verticesIndices[ACTUAL_NUM_PIXELS][6];
|
---|
187 | int numVertices;
|
---|
188 | };
|
---|
189 |
|
---|
190 | class Camera : public RawDataViewer
|
---|
191 | {
|
---|
192 | Q_OBJECT
|
---|
193 |
|
---|
194 | typedef pair<double, double> Position;
|
---|
195 | typedef vector<Position> Positions;
|
---|
196 |
|
---|
197 | Positions fGeom;
|
---|
198 |
|
---|
199 | valarray<double> fData;
|
---|
200 | vector<bool> fBold;
|
---|
201 | vector<bool> fEnable;
|
---|
202 |
|
---|
203 | int fWhite;
|
---|
204 |
|
---|
205 | int64_t fMin;
|
---|
206 | int64_t fMax;
|
---|
207 |
|
---|
208 | public:
|
---|
209 | Camera(QWidget *pparent = 0);
|
---|
210 | void Reset();
|
---|
211 | void SetBold(int idx);
|
---|
212 | void SetWhite(int idx);
|
---|
213 | void SetEnable(int idx, bool b);
|
---|
214 | void Toggle(int idx);
|
---|
215 | double GetData(int idx);
|
---|
216 | void SetMin(int64_t min);
|
---|
217 | void SetMax(int64_t max);
|
---|
218 | const char *GetName();
|
---|
219 |
|
---|
220 | void Paint();
|
---|
221 |
|
---|
222 | int GetIdx(float px, float py);
|
---|
223 | char *GetObjectInfo(int px, int py);
|
---|
224 |
|
---|
225 | void SetData(const valarray<double> &ddata);
|
---|
226 |
|
---|
227 | };
|
---|
228 | /*************************************************
|
---|
229 | * Class UIConnector. used to connect the interface to the raw data displayer
|
---|
230 | *************************************************/
|
---|
231 | class UIConnector : public QObject
|
---|
232 | {
|
---|
233 | Q_OBJECT
|
---|
234 | public:
|
---|
235 | UIConnector(QWidget *parent = 0);
|
---|
236 | void setViewer(RawDataViewer* v);
|
---|
237 |
|
---|
238 | public Q_SLOTS:
|
---|
239 | void loadNewFileClicked();
|
---|
240 | void loadNewCalibFileClicked();
|
---|
241 | void fileSelected(QString file);
|
---|
242 | void calibFileSelected(QString file);
|
---|
243 | void drawPatchesCheckChange(int state);
|
---|
244 | void drawImpulseCheckChange(int state);
|
---|
245 | void drawBlurCheckChange(int state);
|
---|
246 | void loopEventCheckChange(int state);
|
---|
247 | void newFileLoaded();
|
---|
248 | void playPauseClicked();
|
---|
249 | void slicesPerSecondChanged(double value);
|
---|
250 | void nextSlicePlease();
|
---|
251 | void currentSliceHasChanged(int slice);
|
---|
252 | void currentEventHasChanged(int event);
|
---|
253 | void rangeChanged0(double value);
|
---|
254 | void rangeChanged1(double value);
|
---|
255 | void rangeChanged2(double value);
|
---|
256 | void rangeChanged3(double value);
|
---|
257 | void rangeChanged4(double value);
|
---|
258 | void redChanged0(double value);
|
---|
259 | void redChanged1(double value);
|
---|
260 | void redChanged2(double value);
|
---|
261 | void redChanged3(double value);
|
---|
262 | void redChanged4(double value);
|
---|
263 | void greenChanged0(double value);
|
---|
264 | void greenChanged1(double value);
|
---|
265 | void greenChanged2(double value);
|
---|
266 | void greenChanged3(double value);
|
---|
267 | void greenChanged4(double value);
|
---|
268 | void blueChanged0(double value);
|
---|
269 | void blueChanged1(double value);
|
---|
270 | void blueChanged2(double value);
|
---|
271 | void blueChanged3(double value);
|
---|
272 | void blueChanged4(double value);
|
---|
273 | void pixelChanged(int pixel);
|
---|
274 | void hwIDChanged(int hwid);
|
---|
275 | void swIDChanged(int swid);
|
---|
276 | void crateIDChanged(int cid);
|
---|
277 | void boardIDChanged(int bid);
|
---|
278 | void patchIDChanged(int pid);
|
---|
279 | void autoScalePressed();
|
---|
280 | void entireCameraChanged(bool state);
|
---|
281 | void currentPixelChanged(bool state);
|
---|
282 | void slicesPlusPlus();
|
---|
283 | void slicesMinusMinus();
|
---|
284 | void drawCalibratedDataChanged(int state);
|
---|
285 |
|
---|
286 | Q_SIGNALS:
|
---|
287 | void updateCurrentSliceDisplay(QString);
|
---|
288 | void updateCurrentEventDisplay(QString);
|
---|
289 | void updateCurrentPCTime(QString);
|
---|
290 | void updateCurrentSoftTrigger(QString);
|
---|
291 | void updateCurrentTriggerType(QString);
|
---|
292 | void updateCurrentPixelSliceValue(QString);
|
---|
293 |
|
---|
294 |
|
---|
295 | private:
|
---|
296 | RawDataViewer* viewer;
|
---|
297 | QTimer timer;
|
---|
298 | string currentFile;
|
---|
299 | string currentCalibFile;
|
---|
300 | int crateID;
|
---|
301 | int boardID;
|
---|
302 | int patchID;
|
---|
303 | int hwID;
|
---|
304 | int swID;
|
---|
305 | bool rescaleWholeCamera;
|
---|
306 | QRectF scaleBoundingRectangle(QRectF rectangle, float scale);
|
---|
307 | public:
|
---|
308 | QListWidget *boardsTimeList;
|
---|
309 | QListWidget* startPixelsList;
|
---|
310 | QListWidget* startTimeMarksList;
|
---|
311 | // QLabel* fileLoadedLabel;
|
---|
312 | // QLabel* runNumberLabel;
|
---|
313 | // QLabel* numberOfSlicesLabel;
|
---|
314 | // QLabel* numberOfTimeMarksLabel;
|
---|
315 | // QLabel* runTypeLabel;
|
---|
316 | // QLabel* firstTimeLabel;
|
---|
317 | // QLabel* lastTimeLabel;
|
---|
318 | QLabel* currentPixelValue;
|
---|
319 | QLabel* extraInfoLabel;
|
---|
320 |
|
---|
321 | QwtPlot* boardsTimeHisto;
|
---|
322 | QwtPlot* startCellHisto;
|
---|
323 | QwtPlot* startTimeMarkHisto;
|
---|
324 | QwtPlot* pixelValueCurve;
|
---|
325 | QwtPlotCurve boardsTimeHistoItem;
|
---|
326 | QwtPlotCurve startCellHistoItem;
|
---|
327 | QwtPlotCurve startTimeMarkHistoItem;
|
---|
328 | QwtPlotCurve pixelValueCurveItem;
|
---|
329 | QwtPlotZoomer* curveZoom;
|
---|
330 | QwtPlotZoomer* boardsTimeHistoZoom;
|
---|
331 | QwtPlotZoomer* startCellHistoZoom;
|
---|
332 | QwtPlotZoomer* startTimeMarkHistoZoom;
|
---|
333 |
|
---|
334 | QwtPlot* triggerDelayHisto;
|
---|
335 | QwtPlotCurve triggerDelayHistoItem;
|
---|
336 | QwtPlotZoomer* triggerDelayHistoZoom;
|
---|
337 | QListWidget* triggerDelayList;
|
---|
338 |
|
---|
339 | QSpinBox* HwIDBox;
|
---|
340 | QSpinBox* SwIDBox;
|
---|
341 | QSpinBox* crateIDBox;
|
---|
342 | QSpinBox* boardIDBox;
|
---|
343 | QSpinBox* patchIDBox;
|
---|
344 |
|
---|
345 | QRadioButton* currentPixelScale;
|
---|
346 | QRadioButton* entireCameraScale;
|
---|
347 |
|
---|
348 | QDoubleSpinBox* range0;
|
---|
349 | QDoubleSpinBox* range1;
|
---|
350 | QDoubleSpinBox* range2;
|
---|
351 | QDoubleSpinBox* range3;
|
---|
352 | QDoubleSpinBox* range4;
|
---|
353 |
|
---|
354 | QCheckBox* drawCalibrationCheckBox;
|
---|
355 |
|
---|
356 | void initHistograms();
|
---|
357 |
|
---|
358 | };
|
---|
359 |
|
---|
360 | #endif /* QTGL_H_ */
|
---|