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 <iostream>
|
---|
30 | #include <GL/gl.h>
|
---|
31 |
|
---|
32 | #include "qwt_plot.h"
|
---|
33 | //#include "qwt_plot_histogram.h"
|
---|
34 | #include "qwt_plot_curve.h"
|
---|
35 |
|
---|
36 | #include <qwt_plot_zoomer.h>
|
---|
37 |
|
---|
38 |
|
---|
39 | //#define __MARS__
|
---|
40 | //#include "MFits.h"
|
---|
41 | #include <string>
|
---|
42 | #include "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& filename);
|
---|
82 |
|
---|
83 | public Q_SLOTS:
|
---|
84 | void plusEvent();
|
---|
85 | void minusEvent();
|
---|
86 | void setEventStep(int step);
|
---|
87 | void nextSlice();
|
---|
88 | void previousSlice();
|
---|
89 |
|
---|
90 | Q_SIGNALS:
|
---|
91 | void signalCurrentEvent(int event);
|
---|
92 | void signalCurrentSlice(int slice);
|
---|
93 | void newFileLoaded();
|
---|
94 | void signalCurrentPixel(int pixel);
|
---|
95 |
|
---|
96 | protected:
|
---|
97 | void initializeGL();
|
---|
98 | void resizeGL(int width, int height);
|
---|
99 | void paintGL();
|
---|
100 | void mousePressEvent(QMouseEvent *event);
|
---|
101 | void mouseMoveEvent(QMouseEvent *event);
|
---|
102 | void mouseDoubleClickEvent(QMouseEvent *event);
|
---|
103 |
|
---|
104 | private:
|
---|
105 | void drawCamera(bool alsoWire);
|
---|
106 | void drawPixelCurve();
|
---|
107 | void drawPatches();
|
---|
108 | int PixelAtPosition(const QPoint &pos);
|
---|
109 | void updateNeighbors(int currentPixel);
|
---|
110 | void skipPixels(int start, int howMany);
|
---|
111 | void calculatePixelsCoords();
|
---|
112 | void drawHexagon(int index, bool solid);
|
---|
113 | void setCorrectSlice(QMouseEvent* event);
|
---|
114 | void eventStepping(bool plus);
|
---|
115 | void buildVerticesList();
|
---|
116 | void buildPatchesIndices();
|
---|
117 | void calcBlurColor(int pixel, int vertex);
|
---|
118 | void drawBlurryHexagon(int index);
|
---|
119 | float hexRadius;
|
---|
120 | float hexTolerance;
|
---|
121 | float viewSize;
|
---|
122 | int whichSlice;
|
---|
123 | int selectedPixel;
|
---|
124 | float pixelSize;
|
---|
125 | float shownSizex;
|
---|
126 | float shownSizey;
|
---|
127 | bool drawPatch;
|
---|
128 | bool drawImpulse;
|
---|
129 | bool drawBlur;
|
---|
130 | bool loopCurrentEvent;
|
---|
131 | //allocate the maximum size for one event
|
---|
132 | int16_t *eventData;
|
---|
133 | uint32_t boardTime[NBOARDS];
|
---|
134 | int16_t startPix[NPIX];
|
---|
135 | int16_t startTM[NTMARK];
|
---|
136 | uint32_t pcTime;
|
---|
137 | uint32_t softTrig;
|
---|
138 | uint16_t triggerType;
|
---|
139 | int nRows;
|
---|
140 | int rowNum;
|
---|
141 | int eventNum;
|
---|
142 | int nRoi;
|
---|
143 | int nRoiTM;
|
---|
144 | int runNumber;
|
---|
145 | int nTM;
|
---|
146 | int runType;
|
---|
147 | int firstDataTime;
|
---|
148 | int lastDataTime;
|
---|
149 | int revision;
|
---|
150 | int builderVersion;
|
---|
151 | int nBoards;
|
---|
152 | int nPixels;
|
---|
153 | string timeSystem;
|
---|
154 | string creationDate;
|
---|
155 | int nightInt;
|
---|
156 | string camera;
|
---|
157 | string daq;
|
---|
158 | float adcCount;
|
---|
159 | int nbOk;
|
---|
160 | int nbRej;
|
---|
161 | int nbBad;
|
---|
162 |
|
---|
163 | int eventStep;
|
---|
164 |
|
---|
165 | int hardwareMapping[1440];
|
---|
166 | int softwareMapping[1440];
|
---|
167 | int patches[160][9];
|
---|
168 | GLfloat patchesColor[160][3];
|
---|
169 | vector<edge> patchesIndices[160];
|
---|
170 | fits* inputFile;
|
---|
171 |
|
---|
172 | QPoint lastPos;
|
---|
173 |
|
---|
174 | GLfloat pixelsCoords[MAX_NUM_PIXELS][3];
|
---|
175 | PixelsNeighbors neighbors[MAX_NUM_PIXELS];
|
---|
176 | GLfloat pixelsColor[ACTUAL_NUM_PIXELS][3];
|
---|
177 | GLfloat verticesList[ACTUAL_NUM_PIXELS*6][2];
|
---|
178 | int verticesIndices[ACTUAL_NUM_PIXELS][6];
|
---|
179 | int numVertices;
|
---|
180 | };
|
---|
181 | /*************************************************
|
---|
182 | * Class UIConnector. used to connect the interface to the raw data displayer
|
---|
183 | *************************************************/
|
---|
184 | class UIConnector : public QObject
|
---|
185 | {
|
---|
186 | Q_OBJECT
|
---|
187 | public:
|
---|
188 | UIConnector(QWidget *parent = 0);
|
---|
189 | void setViewer(RawDataViewer* v);
|
---|
190 |
|
---|
191 | public Q_SLOTS:
|
---|
192 | void loadNewFileClicked();
|
---|
193 | void fileSelected(QString file);
|
---|
194 | void drawPatchesCheckChange(int state);
|
---|
195 | void drawImpulseCheckChange(int state);
|
---|
196 | void drawBlurCheckChange(int state);
|
---|
197 | void loopEventCheckChange(int state);
|
---|
198 | void newFileLoaded();
|
---|
199 | void playPauseClicked();
|
---|
200 | void slicesPerSecondChanged(double value);
|
---|
201 | void nextSlicePlease();
|
---|
202 | void currentSliceHasChanged(int slice);
|
---|
203 | void currentEventHasChanged(int event);
|
---|
204 | void rangeChanged0(double value);
|
---|
205 | void rangeChanged1(double value);
|
---|
206 | void rangeChanged2(double value);
|
---|
207 | void rangeChanged3(double value);
|
---|
208 | void rangeChanged4(double value);
|
---|
209 | void redChanged0(double value);
|
---|
210 | void redChanged1(double value);
|
---|
211 | void redChanged2(double value);
|
---|
212 | void redChanged3(double value);
|
---|
213 | void redChanged4(double value);
|
---|
214 | void greenChanged0(double value);
|
---|
215 | void greenChanged1(double value);
|
---|
216 | void greenChanged2(double value);
|
---|
217 | void greenChanged3(double value);
|
---|
218 | void greenChanged4(double value);
|
---|
219 | void blueChanged0(double value);
|
---|
220 | void blueChanged1(double value);
|
---|
221 | void blueChanged2(double value);
|
---|
222 | void blueChanged3(double value);
|
---|
223 | void blueChanged4(double value);
|
---|
224 | void pixelChanged(int pixel);
|
---|
225 | void hwIDChanged(int hwid);
|
---|
226 | void swIDChanged(int swid);
|
---|
227 | void crateIDChanged(int cid);
|
---|
228 | void boardIDChanged(int bid);
|
---|
229 | void patchIDChanged(int pid);
|
---|
230 | void autoScalePressed();
|
---|
231 | void entireCameraChanged(bool state);
|
---|
232 | void currentPixelChanged(bool state);
|
---|
233 | void slicesPlusPlus();
|
---|
234 | void slicesMinusMinus();
|
---|
235 |
|
---|
236 | Q_SIGNALS:
|
---|
237 | void updateCurrentSliceDisplay(QString);
|
---|
238 | void updateCurrentEventDisplay(QString);
|
---|
239 | void updateCurrentPCTime(QString);
|
---|
240 | void updateCurrentSoftTrigger(QString);
|
---|
241 | void updateCurrentTriggerType(QString);
|
---|
242 | void updateCurrentPixelSliceValue(QString);
|
---|
243 |
|
---|
244 |
|
---|
245 | private:
|
---|
246 | RawDataViewer* viewer;
|
---|
247 | QTimer timer;
|
---|
248 | string currentFile;
|
---|
249 | int crateID;
|
---|
250 | int boardID;
|
---|
251 | int patchID;
|
---|
252 | int hwID;
|
---|
253 | int swID;
|
---|
254 | bool rescaleWholeCamera;
|
---|
255 | public:
|
---|
256 | QListWidget *boardsTimeList;
|
---|
257 | QListWidget* startPixelsList;
|
---|
258 | QListWidget* startTimeMarksList;
|
---|
259 | // QLabel* fileLoadedLabel;
|
---|
260 | // QLabel* runNumberLabel;
|
---|
261 | // QLabel* numberOfSlicesLabel;
|
---|
262 | // QLabel* numberOfTimeMarksLabel;
|
---|
263 | // QLabel* runTypeLabel;
|
---|
264 | // QLabel* firstTimeLabel;
|
---|
265 | // QLabel* lastTimeLabel;
|
---|
266 | QLabel* currentPixelValue;
|
---|
267 | QLabel* extraInfoLabel;
|
---|
268 |
|
---|
269 | QwtPlot* boardsTimeHisto;
|
---|
270 | QwtPlot* startCellHisto;
|
---|
271 | QwtPlot* startTimeMarkHisto;
|
---|
272 | QwtPlot* pixelValueCurve;
|
---|
273 | QwtPlotCurve boardsTimeHistoItem;
|
---|
274 | QwtPlotCurve startCellHistoItem;
|
---|
275 | QwtPlotCurve startTimeMarkHistoItem;
|
---|
276 | QwtPlotCurve pixelValueCurveItem;
|
---|
277 | QwtPlotZoomer* curveZoom;
|
---|
278 | QwtPlotZoomer* boardsTimeHistoZoom;
|
---|
279 | QwtPlotZoomer* startCellHistoZoom;
|
---|
280 | QwtPlotZoomer* startTimeMarkHistoZoom;
|
---|
281 |
|
---|
282 | QwtPlot* triggerDelayHisto;
|
---|
283 | QwtPlotCurve triggerDelayHistoItem;
|
---|
284 | QwtPlotZoomer* triggerDelayHistoZoom;
|
---|
285 | QListWidget* triggerDelayList;
|
---|
286 |
|
---|
287 | QSpinBox* HwIDBox;
|
---|
288 | QSpinBox* SwIDBox;
|
---|
289 | QSpinBox* crateIDBox;
|
---|
290 | QSpinBox* boardIDBox;
|
---|
291 | QSpinBox* patchIDBox;
|
---|
292 |
|
---|
293 | QRadioButton* currentPixelScale;
|
---|
294 | QRadioButton* entireCameraScale;
|
---|
295 |
|
---|
296 | QDoubleSpinBox* range0;
|
---|
297 | QDoubleSpinBox* range1;
|
---|
298 | QDoubleSpinBox* range2;
|
---|
299 | QDoubleSpinBox* range3;
|
---|
300 | QDoubleSpinBox* range4;
|
---|
301 |
|
---|
302 | void initHistograms();
|
---|
303 |
|
---|
304 | };
|
---|
305 |
|
---|
306 | #endif /* QTGL_H_ */
|
---|