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 <iostream>
|
---|
27 | #include <GL/gl.h>
|
---|
28 |
|
---|
29 | #include <string>
|
---|
30 | #include "fits.h"
|
---|
31 |
|
---|
32 | using namespace std;
|
---|
33 |
|
---|
34 | #define NUM_STORED_EVENTS 5
|
---|
35 | #define MAX_NUM_PIXELS 1600
|
---|
36 | #define ACTUAL_NUM_PIXELS 1440
|
---|
37 |
|
---|
38 | ///structure for storing edges of hexagons (for blurry display)
|
---|
39 | struct edge
|
---|
40 | {
|
---|
41 | int first;
|
---|
42 | int second;
|
---|
43 | };
|
---|
44 |
|
---|
45 | ///structure for storing neighbors of pixels. For camera position calculation and blurry display
|
---|
46 | struct PixelsNeighbors
|
---|
47 | {
|
---|
48 | //neighbors. clockwise, starting from top
|
---|
49 | int neighbors[6];
|
---|
50 | PixelsNeighbors()
|
---|
51 | {
|
---|
52 | for (int i=0;i<6;i++)
|
---|
53 | neighbors[i] = -1;
|
---|
54 | }
|
---|
55 | int& operator[](int index){return neighbors[index];}
|
---|
56 | };
|
---|
57 |
|
---|
58 | /*************************************************
|
---|
59 | * Class Raw Data Viewer. FACT raw data diplayer
|
---|
60 | *************************************************/
|
---|
61 | class RawDataViewer : public QGLWidget
|
---|
62 | {
|
---|
63 | Q_OBJECT
|
---|
64 |
|
---|
65 | friend class UIConnector;
|
---|
66 | public:
|
---|
67 | RawDataViewer(QWidget *parent = 0);
|
---|
68 | ~RawDataViewer();
|
---|
69 | void openFile(string& filename);
|
---|
70 |
|
---|
71 | public Q_SLOTS:
|
---|
72 | void plusEvent();
|
---|
73 | void minusEvent();
|
---|
74 | void setEventStep(int step);
|
---|
75 | void nextSlice();
|
---|
76 |
|
---|
77 | Q_SIGNALS:
|
---|
78 | void signalCurrentEvent(int event);
|
---|
79 | void signalCurrentSlice(int slice);
|
---|
80 | void newFileLoaded();
|
---|
81 |
|
---|
82 | protected:
|
---|
83 | void initializeGL();
|
---|
84 | void resizeGL(int width, int height);
|
---|
85 | void paintGL();
|
---|
86 | void mousePressEvent(QMouseEvent *event);
|
---|
87 | void mouseMoveEvent(QMouseEvent *event);
|
---|
88 | void mouseDoubleClickEvent(QMouseEvent *event);
|
---|
89 |
|
---|
90 | private:
|
---|
91 | void drawCamera(bool alsoWire);
|
---|
92 | void drawPixelCurve();
|
---|
93 | void drawPatches();
|
---|
94 | int PixelAtPosition(const QPoint &pos);
|
---|
95 | void updateNeighbors(int currentPixel);
|
---|
96 | void skipPixels(int start, int howMany);
|
---|
97 | void calculatePixelsCoords();
|
---|
98 | void drawHexagon(int index, bool solid);
|
---|
99 | void setCorrectSlice(QMouseEvent* event);
|
---|
100 | void eventStepping(bool plus);
|
---|
101 | void buildVerticesList();
|
---|
102 | void buildPatchesIndices();
|
---|
103 | void calcBlurColor(int pixel, int vertex);
|
---|
104 | void drawBlurryHexagon(int index);
|
---|
105 | float hexRadius;
|
---|
106 | float hexTolerance;
|
---|
107 | float viewSize;
|
---|
108 | int whichSlice;
|
---|
109 | int selectedPixel;
|
---|
110 | float pixelSize;
|
---|
111 | float shownSizex;
|
---|
112 | float shownSizey;
|
---|
113 | bool drawPatch;
|
---|
114 | bool drawImpulse;
|
---|
115 | bool drawBlur;
|
---|
116 | //allocate the maximum size for one event
|
---|
117 | int16_t *eventData;
|
---|
118 | uint32_t boardTime[NBOARDS];
|
---|
119 | int16_t startPix[NPIX];
|
---|
120 | int16_t startTM[NTMARK];
|
---|
121 | uint32_t pcTime;
|
---|
122 | uint32_t softTrig;
|
---|
123 | uint16_t triggerType;
|
---|
124 | int nRows;
|
---|
125 | int rowNum;
|
---|
126 | int eventNum;
|
---|
127 | int nRoi;
|
---|
128 | int runNumber;
|
---|
129 | int nTM;
|
---|
130 | int runType;
|
---|
131 | int firstDataTime;
|
---|
132 | int lastDataTime;
|
---|
133 | int eventStep;
|
---|
134 |
|
---|
135 | int hardwareMapping[1440];
|
---|
136 | int patches[160][9];
|
---|
137 | GLfloat patchesColor[160][3];
|
---|
138 | vector<edge> patchesIndices[160];
|
---|
139 | fits* inputFile;
|
---|
140 |
|
---|
141 | QPoint lastPos;
|
---|
142 |
|
---|
143 | GLfloat pixelsCoords[MAX_NUM_PIXELS][3];
|
---|
144 | PixelsNeighbors neighbors[MAX_NUM_PIXELS];
|
---|
145 | GLfloat pixelsColor[ACTUAL_NUM_PIXELS][3];
|
---|
146 | GLfloat verticesList[ACTUAL_NUM_PIXELS*6][2];
|
---|
147 | int verticesIndices[ACTUAL_NUM_PIXELS][6];
|
---|
148 | int numVertices;
|
---|
149 | };
|
---|
150 | /*************************************************
|
---|
151 | * Class UIConnector. used to connect the interface to the raw data displayer
|
---|
152 | *************************************************/
|
---|
153 | class UIConnector : public QObject
|
---|
154 | {
|
---|
155 | Q_OBJECT
|
---|
156 | public:
|
---|
157 | UIConnector(QWidget *parent = 0);
|
---|
158 | void setViewer(RawDataViewer* v);
|
---|
159 |
|
---|
160 | public Q_SLOTS:
|
---|
161 | void loadNewFileClicked();
|
---|
162 | void fileSelected(QString file);
|
---|
163 | void drawPatchesCheckChange(int state);
|
---|
164 | void drawImpulseCheckChange(int state);
|
---|
165 | void drawBlurCheckChange(int state);
|
---|
166 | void newFileLoaded();
|
---|
167 | void playPauseClicked();
|
---|
168 | void slicesPerSecondChanged(double value);
|
---|
169 | void nextSlicePlease();
|
---|
170 | void currentSliceHasChanged(int slice);
|
---|
171 | void currentEventHasChanged(int event);
|
---|
172 | void rangeChanged0(double value);
|
---|
173 | void rangeChanged1(double value);
|
---|
174 | void rangeChanged2(double value);
|
---|
175 | void rangeChanged3(double value);
|
---|
176 | void rangeChanged4(double value);
|
---|
177 | void redChanged0(double value);
|
---|
178 | void redChanged1(double value);
|
---|
179 | void redChanged2(double value);
|
---|
180 | void redChanged3(double value);
|
---|
181 | void redChanged4(double value);
|
---|
182 | void greenChanged0(double value);
|
---|
183 | void greenChanged1(double value);
|
---|
184 | void greenChanged2(double value);
|
---|
185 | void greenChanged3(double value);
|
---|
186 | void greenChanged4(double value);
|
---|
187 | void blueChanged0(double value);
|
---|
188 | void blueChanged1(double value);
|
---|
189 | void blueChanged2(double value);
|
---|
190 | void blueChanged3(double value);
|
---|
191 | void blueChanged4(double value);
|
---|
192 |
|
---|
193 | Q_SIGNALS:
|
---|
194 | void updateCurrentSliceDisplay(QString);
|
---|
195 | void updateCurrentEventDisplay(QString);
|
---|
196 | void updateCurrentPCTime(QString);
|
---|
197 | void updateCurrentSoftTrigger(QString);
|
---|
198 | void updateCurrentTriggerType(QString);
|
---|
199 |
|
---|
200 |
|
---|
201 | private:
|
---|
202 | RawDataViewer* viewer;
|
---|
203 | QTimer timer;
|
---|
204 | string currentFile;
|
---|
205 | public:
|
---|
206 | QListWidget *boardsTimeList;
|
---|
207 | QListWidget* startPixelsList;
|
---|
208 | QListWidget* startTimeMarksList;
|
---|
209 | QLabel* fileLoadedLabel;
|
---|
210 | QLabel* runNumberLabel;
|
---|
211 | QLabel* numberOfSlicesLabel;
|
---|
212 | QLabel* numberOfTimeMarksLabel;
|
---|
213 | QLabel* runTypeLabel;
|
---|
214 | QLabel* firstTimeLabel;
|
---|
215 | QLabel* lastTimeLabel;
|
---|
216 |
|
---|
217 | };
|
---|
218 |
|
---|
219 | #endif /* QTGL_H_ */
|
---|