1 | #include "QCameraWidget.h"
|
---|
2 | #include <sstream>
|
---|
3 | #include <iostream>
|
---|
4 |
|
---|
5 | QCameraWidget::QCameraWidget(QWidget *pparent) : BasicGlCamera(pparent)
|
---|
6 | {
|
---|
7 | fBold.resize(1440);
|
---|
8 | fEnable.resize(1440);
|
---|
9 | fBold.assign(1440, false);
|
---|
10 | fEnable.assign(1440, true);
|
---|
11 | lastFace = -1;
|
---|
12 |
|
---|
13 | CalculatePixelsColor();
|
---|
14 |
|
---|
15 | }
|
---|
16 |
|
---|
17 | void QCameraWidget::paintGL()
|
---|
18 | {
|
---|
19 | glClear(GL_COLOR_BUFFER_BIT);
|
---|
20 | glLoadIdentity();
|
---|
21 |
|
---|
22 | glTranslatef(0,-0.44,0);
|
---|
23 | glRotatef(cameraRotation, 0,0,-1);
|
---|
24 | if (cameraRotation == 90)
|
---|
25 | {
|
---|
26 | glTranslatef(-0.45,-0.45,0);
|
---|
27 | // cout << "correction" << endl;
|
---|
28 | }
|
---|
29 | if (cameraRotation == -90)
|
---|
30 | {
|
---|
31 | glTranslatef(0.45,-0.45,0);
|
---|
32 | }
|
---|
33 | glScalef(1.5, 1.5, 1.5);
|
---|
34 | drawCamera(true);
|
---|
35 |
|
---|
36 | glLineWidth(1.0f);
|
---|
37 | glColor3fv(highlightedPixelsCoulour);
|
---|
38 | for (vector<int>::iterator it = highlightedPixels.begin(); it!= highlightedPixels.end(); it++)
|
---|
39 | {
|
---|
40 | drawHexagon(*it, false);
|
---|
41 | }
|
---|
42 | drawPatches();
|
---|
43 |
|
---|
44 | glLineWidth(1.0f);
|
---|
45 |
|
---|
46 | //glColor3f(1.f - pixelsColor[fWhite][0],1.f - pixelsColor[fWhite][1],1.f - pixelsColor[fWhite][2]);
|
---|
47 | if (fWhite != -1)
|
---|
48 | {
|
---|
49 | glColor3f(1.f, 0.f, 0.f);
|
---|
50 | drawHexagon(fWhite, false);
|
---|
51 | }
|
---|
52 | DrawCameraText();
|
---|
53 |
|
---|
54 | DrawScale();
|
---|
55 |
|
---|
56 | // if (linearButton->isVisible())
|
---|
57 | // repaintInterface();
|
---|
58 | }
|
---|
59 | void QCameraWidget::drawCamera(bool alsoWire)
|
---|
60 | {
|
---|
61 | if (!pixelColorUpToDate)
|
---|
62 | CalculatePixelsColor();
|
---|
63 | glLineWidth(1.0);
|
---|
64 | for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
|
---|
65 | {
|
---|
66 | glColor3fv(pixelsColor[i]);
|
---|
67 | glLoadName(i);
|
---|
68 | drawHexagon(i,true);
|
---|
69 | }
|
---|
70 | if (!alsoWire)
|
---|
71 | return;
|
---|
72 | glColor3fv(pixelContourColour);//0.0f,0.0f,0.0f);
|
---|
73 | for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
|
---|
74 | {
|
---|
75 | drawHexagon(i, false);
|
---|
76 | }
|
---|
77 | }
|
---|
78 | void QCameraWidget::drawPatches()
|
---|
79 | {
|
---|
80 | glLineWidth(2.0f);
|
---|
81 | glColor3fv(patchesCoulour);
|
---|
82 | glBegin(GL_LINES);
|
---|
83 | for (int i=0;i<NTMARK;i++)
|
---|
84 | {
|
---|
85 | for (unsigned int j=0;j<patchesIndices[i].size();j++)
|
---|
86 | {
|
---|
87 | glVertex2fv(verticesList[patchesIndices[i][j].first]);
|
---|
88 | glVertex2fv(verticesList[patchesIndices[i][j].second]);
|
---|
89 | }
|
---|
90 | }
|
---|
91 | glEnd();
|
---|
92 |
|
---|
93 | glColor3fv(highlightedPatchesCoulour);
|
---|
94 | glBegin(GL_LINES);
|
---|
95 | for (vector<int>::iterator it=highlightedPatches.begin(); it!= highlightedPatches.end(); it++)
|
---|
96 | {
|
---|
97 | for (unsigned int j=0;j<patchesIndices[*it].size();j++)
|
---|
98 | {
|
---|
99 | glVertex2fv(verticesList[patchesIndices[*it][j].first]);
|
---|
100 | glVertex2fv(verticesList[patchesIndices[*it][j].second]);
|
---|
101 | }
|
---|
102 | }
|
---|
103 | glEnd();
|
---|
104 | if (fWhitePatch != -1)
|
---|
105 | {
|
---|
106 | glTranslatef(0,0,0.01);
|
---|
107 | glColor3f(1.f, 0.5f, 0.f);//patchColour);//[0],patchColour[1],patchColour[2]);//0.5f, 0.5f, 0.3f);
|
---|
108 | glBegin(GL_LINES);
|
---|
109 | for (unsigned int j=0;j<patchesIndices[fWhitePatch].size();j++)
|
---|
110 | {
|
---|
111 | glVertex2fv(verticesList[patchesIndices[fWhitePatch][j].first]);
|
---|
112 | glVertex2fv(verticesList[patchesIndices[fWhitePatch][j].second]);
|
---|
113 | }
|
---|
114 | glEnd();
|
---|
115 | }
|
---|
116 |
|
---|
117 | }
|
---|
118 | void QCameraWidget::Reset()
|
---|
119 | {
|
---|
120 | fBold.assign(1440, false);
|
---|
121 | }
|
---|
122 |
|
---|
123 | void QCameraWidget::mousePressEvent(QMouseEvent *cEvent)
|
---|
124 | {
|
---|
125 | if (cEvent->pos().x() > width()-(width()/50.f))
|
---|
126 | {
|
---|
127 | toggleInterfaceDisplay();
|
---|
128 | return;
|
---|
129 | }
|
---|
130 | int face = PixelAtPosition(cEvent->pos());
|
---|
131 | if (face != -1) {
|
---|
132 | fWhite = face;
|
---|
133 | fWhitePatch = pixelsPatch[fWhite];
|
---|
134 | // CalculatePatchColor();
|
---|
135 | emit signalCurrentPixel(face);
|
---|
136 | }
|
---|
137 | else
|
---|
138 | {
|
---|
139 | fWhite = -1;
|
---|
140 | fWhitePatch = -1;
|
---|
141 | }
|
---|
142 | updateGL();
|
---|
143 | }
|
---|
144 | void QCameraWidget::mouseMoveEvent(QMouseEvent* cEvent)
|
---|
145 | {
|
---|
146 | int face = PixelAtPosition(cEvent->pos());
|
---|
147 | if (face != -1 && lastFace != face) {
|
---|
148 | emit signalPixelMoveOver(face);
|
---|
149 | }
|
---|
150 | lastFace = face;
|
---|
151 | }
|
---|
152 | void QCameraWidget::mouseDoubleClickEvent(QMouseEvent* cEvent)
|
---|
153 | {
|
---|
154 | int face = PixelAtPosition(cEvent->pos());
|
---|
155 | if (face != -1) {
|
---|
156 | // cout << "Event !" << endl;
|
---|
157 | fWhite = face;
|
---|
158 | fWhitePatch = pixelsPatch[fWhite];
|
---|
159 | highlightPixel(face);
|
---|
160 | highlightPatch(fWhitePatch);
|
---|
161 | // CalculatePatchColor();
|
---|
162 | emit signalPixelDoubleClick(face);
|
---|
163 | }
|
---|
164 | else
|
---|
165 | {
|
---|
166 | fWhite = -1;
|
---|
167 | fWhitePatch = -1;
|
---|
168 | clearHighlightedPixels();
|
---|
169 | clearHighlightedPatches();
|
---|
170 | }
|
---|
171 | updateGL();
|
---|
172 |
|
---|
173 | }
|
---|
174 |
|
---|
175 | void QCameraWidget::SetEnable(int idx, bool b)
|
---|
176 | {
|
---|
177 | fEnable[idx] = b;
|
---|
178 | }
|
---|
179 |
|
---|
180 | double QCameraWidget::GetData(int idx)
|
---|
181 | {
|
---|
182 | return fData[idx];
|
---|
183 | }
|
---|
184 | const char* QCameraWidget::GetName()
|
---|
185 | {
|
---|
186 | return "QCameraWidget";
|
---|
187 | }
|
---|
188 | char *QCameraWidget::GetObjectInfo(int px, int py)
|
---|
189 | {
|
---|
190 |
|
---|
191 | static stringstream stream;
|
---|
192 | static string str;
|
---|
193 | const int pixel = this->PixelAtPosition(QPoint(px, py));
|
---|
194 | if (pixel >= 0)
|
---|
195 | {
|
---|
196 | stream << "Pixel=" << pixel << " Data=" << fData[pixel] << '\0';
|
---|
197 | }
|
---|
198 | str = stream.str();
|
---|
199 | return const_cast<char*>(str.c_str());
|
---|
200 | }
|
---|
201 | void QCameraWidget::CalculatePixelsColor()
|
---|
202 | {
|
---|
203 | double dmin = fData[0];
|
---|
204 | double dmax = fData[0];
|
---|
205 | if (fMin < 0 || fMax < 0)
|
---|
206 | {
|
---|
207 | for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
|
---|
208 | {
|
---|
209 | if (!fEnable[i]) continue;
|
---|
210 | if (fData[i] > dmax) dmax = fData[i];
|
---|
211 | if (fData[i] < dmin) dmin = fData[i];
|
---|
212 | }
|
---|
213 | }
|
---|
214 | if (fMin >= 0) dmin = fMin;
|
---|
215 | if (fMax >= 0) dmax = fMax;
|
---|
216 | // cout << "min: " << dmin << " max: " << dmax << " fMin: " << fMin << " fMax: " << fMax << endl;
|
---|
217 | float color;
|
---|
218 | for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
|
---|
219 | {
|
---|
220 | if (!fEnable[i])
|
---|
221 | {
|
---|
222 | // cout << "not enabled !" << i << endl;
|
---|
223 | pixelsColor[i][0] = 0.1f;
|
---|
224 | pixelsColor[i][1] = 0.1f;
|
---|
225 | pixelsColor[i][2] = 0.15f;
|
---|
226 | continue;
|
---|
227 | }
|
---|
228 | if (fData[i] < dmin)
|
---|
229 | {
|
---|
230 | pixelsColor[i][0] = tooLowValueCoulour[0];
|
---|
231 | pixelsColor[i][1] = tooLowValueCoulour[1];
|
---|
232 | pixelsColor[i][2] = tooLowValueCoulour[2];
|
---|
233 | continue;
|
---|
234 | }
|
---|
235 | if (fData[i] > dmax)
|
---|
236 | {
|
---|
237 | pixelsColor[i][0] = tooHighValueCoulour[0];
|
---|
238 | pixelsColor[i][1] = tooHighValueCoulour[1];
|
---|
239 | pixelsColor[i][2] = tooHighValueCoulour[2];
|
---|
240 | continue;
|
---|
241 | }
|
---|
242 | color = float((fData[i]-dmin)/(dmax-dmin));
|
---|
243 | if (logScale)
|
---|
244 | {
|
---|
245 | color *= 9;
|
---|
246 | color += 1;
|
---|
247 | color = log10(color);
|
---|
248 | }
|
---|
249 |
|
---|
250 | int index = 0;
|
---|
251 | while (ss[index] < color && index < 4)
|
---|
252 | index++;
|
---|
253 | index--;
|
---|
254 | if (index < 0) index = 0;
|
---|
255 | float weight0 = (color-ss[index]) / (ss[index+1]-ss[index]);
|
---|
256 | if (weight0 > 1.0f) weight0 = 1.0f;
|
---|
257 | if (weight0 < 0.0f) weight0 = 0.0f;
|
---|
258 | float weight1 = 1.0f-weight0;
|
---|
259 | pixelsColor[i][0] = weight1*rr[index] + weight0*rr[index+1];
|
---|
260 | pixelsColor[i][1] = weight1*gg[index] + weight0*gg[index+1];
|
---|
261 | pixelsColor[i][2] = weight1*bb[index] + weight0*bb[index+1];
|
---|
262 | }
|
---|
263 | CalculatePatchColor();
|
---|
264 | UpdateText();
|
---|
265 | pixelColorUpToDate = true;
|
---|
266 | }
|
---|
267 | void QCameraWidget::CalculatePatchColor()
|
---|
268 | {
|
---|
269 | return;
|
---|
270 | //calculate the patch contour color. let's use the anti-colour of the pixels
|
---|
271 | GLfloat averagePatchColour[3] = {0.0f,0.0f,0.0f};
|
---|
272 | for (int i=0;i<9;i++)
|
---|
273 | for (int j=0;j<3;j++)
|
---|
274 | averagePatchColour[j] += pixelsColor[softwareMapping[patches[fWhitePatch][i]]][j];
|
---|
275 | for (int j=0;j<3;j++)
|
---|
276 | averagePatchColour[j] /= 9;
|
---|
277 | for (int j=0;j<3;j++)
|
---|
278 | patchColour[j] = 1.0f - averagePatchColour[j];
|
---|
279 | }
|
---|
280 | void QCameraWidget::SetData(const valarray<double> &ddata)
|
---|
281 | {
|
---|
282 | // fData = ddata;
|
---|
283 | for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
|
---|
284 | fData[i] = ddata[i];
|
---|
285 | pixelColorUpToDate = false;
|
---|
286 | if (isVisible() && autoRefresh)
|
---|
287 | updateGL();
|
---|
288 | }
|
---|
289 |
|
---|
290 |
|
---|
291 | void QCameraWidget::highlightPixel(int idx, bool highlight)
|
---|
292 | {
|
---|
293 | if (idx < 0 || idx > ACTUAL_NUM_PIXELS)
|
---|
294 | {
|
---|
295 | cout << "Error: requested pixel highlight out of bounds" << endl;
|
---|
296 | return;
|
---|
297 | }
|
---|
298 |
|
---|
299 | const vector<int>::iterator v = ::find(highlightedPixels.begin(), highlightedPixels.end(), idx);
|
---|
300 | if (highlight)
|
---|
301 | {
|
---|
302 | if (v==highlightedPixels.end())
|
---|
303 | highlightedPixels.push_back(idx);
|
---|
304 | }
|
---|
305 | else
|
---|
306 | {
|
---|
307 | if (v!=highlightedPixels.end())
|
---|
308 | highlightedPixels.erase(v);
|
---|
309 | }
|
---|
310 |
|
---|
311 | if (isVisible() && autoRefresh)
|
---|
312 | updateGL();
|
---|
313 | }
|
---|
314 | void QCameraWidget::highlightPatch(int idx, bool highlight)
|
---|
315 | {
|
---|
316 | if (idx < 0 || idx > NTMARK)
|
---|
317 | {
|
---|
318 | cout << "Error: requested patch highlight out of bounds" << endl;
|
---|
319 | return;
|
---|
320 | }
|
---|
321 |
|
---|
322 | const vector<int>::iterator v = ::find(highlightedPatches.begin(), highlightedPatches.end(), idx);
|
---|
323 | if (highlight)
|
---|
324 | {
|
---|
325 | if (v==highlightedPatches.end())
|
---|
326 | highlightedPatches.push_back(idx);
|
---|
327 | }
|
---|
328 | else
|
---|
329 | {
|
---|
330 | if (v!=highlightedPatches.end())
|
---|
331 | highlightedPatches.erase(v);
|
---|
332 | }
|
---|
333 |
|
---|
334 | if (isVisible() && autoRefresh)
|
---|
335 | updateGL();
|
---|
336 |
|
---|
337 | }
|
---|
338 | void QCameraWidget::clearHighlightedPatches()
|
---|
339 | {
|
---|
340 | highlightedPatches.clear();
|
---|
341 | if (isVisible() && autoRefresh)
|
---|
342 | updateGL();
|
---|
343 | }
|
---|
344 | void QCameraWidget::clearHighlightedPixels()
|
---|
345 | {
|
---|
346 | highlightedPixels.clear();
|
---|
347 | if (isVisible() && autoRefresh)
|
---|
348 | updateGL();
|
---|
349 | }
|
---|
350 |
|
---|
351 |
|
---|
352 |
|
---|
353 |
|
---|