source: trunk/FACT++/gui/Q3DCameraWidget.cc@ 13489

Last change on this file since 13489 was 12016, checked in by lyard, 13 years ago
added the temperature viewer
File size: 27.4 KB
Line 
1/*
2 * Q3DCameraWidget.cc
3 *
4 * Created on: Aug 26, 2011
5 * Author: lyard
6 */
7#include "Q3DCameraWidget.h"
8#include <math.h>
9#include <sstream>
10
11 Q3DCameraWidget::Q3DCameraWidget(QWidget* pparent) : BasicGlCamera(pparent),
12 timer(),
13 currentLoc(),
14 steps(0),
15 totalSteps(50),
16 currentView(4),
17 nextView(currentView),
18 cameraViews(0),
19 isPicking(false),
20 initFinished(false)
21 {
22 setFormat(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer));
23 rotX = rotY = 0;
24 timer.setInterval(40.0);//0.04 second interval
25 QObject::connect(&timer, SIGNAL(timeout()),
26 this, SLOT(timedUpdate()));
27 QObject::connect(this, SIGNAL(dataHasChanged()),
28 this, SLOT(timedUpdate()));
29 spheresColors.resize(28);
30 spheresRadius.resize(28);
31 spheresLocation.resize(28);
32 PixelMap mypMap;
33 if (!mypMap.Read("FACTmapV5.txt"))
34 {
35 cerr << "ERROR - Problems reading FACTmapV5.txt" << endl;
36 exit(-1);
37 }
38 ifstream fin1("Trigger-Patches.txt");
39 if (!fin1.is_open())
40 {
41 cout << "Error: file \"Trigger-Patches\" missing. aborting." << endl;
42 exit(-1);
43 }
44 string buf;
45 vector<int> patchHW(1440);
46 int l = 0;
47 while (getline(fin1, buf, '\n'))
48 {
49 buf = Tools::Trim(buf);
50 if (buf[0]=='#')
51 continue;
52
53 stringstream str(buf);
54 for (int i=0; i<9; i++)
55 {
56 unsigned int n;
57 str >> n;
58
59 if (n>=patchHW.size())
60 continue;
61
62 patchHW[n] = l;
63 }
64 l++;
65 }
66 if (l!=160)
67 cerr << "WARNING - Problems reading Trigger-Patches.txt" << endl;
68
69 assignPixelMap(mypMap);
70 assignTriggerPatchesMap(patchHW);
71 setTitle("Temperatures");
72
73
74 for (auto it=spheresColors.begin(), jt = spheresRadius.begin(); it != spheresColors.end(); it++, jt++)
75 {
76 (*it)[0] = 0.5f;
77 (*it)[1] = 0.5f;
78 (*it)[2] = 0.5f;
79 (*jt) = 0.1f;
80 }
81 float xx = 0.5;
82 float yx = 0.5;
83 float z = 0.2;
84 float zplus = 0.25;
85 //crate
86 for (int i=0;i<28;i+=4)
87 {
88 xx = 0.5*cos((float)(i)*M_PI/4);
89 yx = 0.5*sin((float)(i)*M_PI/4);
90 spheresLocation[i][0] = xx;
91 spheresLocation[i][1] = yx;
92 spheresLocation[i][2] = z;
93
94 xx = 0.5*cos((float)(i+1)*M_PI/4);
95 yx = 0.5*sin((float)(i+1)*M_PI/4);
96 spheresLocation[i+1][0] = xx;
97 spheresLocation[i+1][1] = yx;
98 spheresLocation[i+1][2] = z + zplus/4;
99
100 xx = 0.5*cos((float)(i+2)*M_PI/4);
101 yx = 0.5*sin((float)(i+2)*M_PI/4);
102 spheresLocation[i+2][0] = xx;
103 spheresLocation[i+2][1] = yx;
104 spheresLocation[i+2][2] = z + 2*zplus/4;
105
106 xx = 0.5*cos((float)(i+3)*M_PI/4);
107 yx = 0.5*sin((float)(i+3)*M_PI/4);
108 spheresLocation[i+3][0] = xx;
109 spheresLocation[i+3][1] = yx;
110 spheresLocation[i+3][2] = z + 3*zplus/4;
111 z += zplus;
112 }
113
114
115 cameraViews.push_back(cameraLocation(45,45, 0.6,-0.3,0));//0
116 cameraViews.push_back(cameraLocation(75,0, 0,-0.65,0));//1
117 cameraViews.push_back(cameraLocation(45,-45, -0.6,-0.3,0));//2
118 cameraViews.push_back(cameraLocation(0,75, 0.8,0,0));//3
119 cameraViews.push_back(cameraLocation(0,0, 0,0,1));//4
120 cameraViews.push_back(cameraLocation(0,-75, -0.8,0,0));//5
121 cameraViews.push_back(cameraLocation(-45,45, 0.6,0.5,0));//6
122 cameraViews.push_back(cameraLocation(-75,0, 0,1,0.2));//7
123 cameraViews.push_back(cameraLocation(-45,-45, -0.6,0.5,0));//8
124
125 tempPatches.resize(31);
126 tempPatches[0].push_back(16);
127 tempPatches[0].push_back(24);
128 tempPatches[0].push_back(32);
129 tempPatches[0].push_back(36);
130
131 tempPatches[1].push_back(49);
132 tempPatches[1].push_back(48);
133 tempPatches[1].push_back(52);
134
135 tempPatches[2].push_back(4);
136 tempPatches[2].push_back(5);
137 tempPatches[2].push_back(8);
138 tempPatches[2].push_back(9);
139
140 tempPatches[3].push_back(17);
141 tempPatches[3].push_back(19);
142 tempPatches[3].push_back(18);
143 tempPatches[3].push_back(26);
144 tempPatches[3].push_back(25);
145
146 tempPatches[4].push_back(37);
147 tempPatches[4].push_back(38);
148 tempPatches[4].push_back(50);
149 tempPatches[4].push_back(51);
150 tempPatches[4].push_back(33);
151 tempPatches[4].push_back(34);
152
153 tempPatches[5].push_back(65);
154 tempPatches[5].push_back(62);
155 tempPatches[5].push_back(61);
156 tempPatches[5].push_back(54);
157 tempPatches[5].push_back(53);
158
159 tempPatches[6].push_back(69);
160 tempPatches[6].push_back(68);
161 tempPatches[6].push_back(64);
162 tempPatches[6].push_back(60);
163
164 tempPatches[7].push_back(2);
165 tempPatches[7].push_back(6);
166 tempPatches[7].push_back(7);
167 tempPatches[7].push_back(12);
168 tempPatches[7].push_back(13);
169 tempPatches[7].push_back(0);
170
171 tempPatches[8].push_back(10);
172 tempPatches[8].push_back(11);
173 tempPatches[8].push_back(20);
174 tempPatches[8].push_back(21);
175
176 tempPatches[9].push_back(30);
177 tempPatches[9].push_back(35);
178 tempPatches[9].push_back(39);
179 tempPatches[9].push_back(27);
180 tempPatches[9].push_back(28);
181
182 tempPatches[10].push_back(40);
183 tempPatches[10].push_back(44);
184 tempPatches[10].push_back(45);
185 tempPatches[10].push_back(55);
186 tempPatches[10].push_back(57);
187
188 tempPatches[11].push_back(56);
189 tempPatches[11].push_back(63);
190 tempPatches[11].push_back(66);
191 tempPatches[11].push_back(67);
192 tempPatches[11].push_back(71);
193
194 tempPatches[12].push_back(72);
195 tempPatches[12].push_back(78);
196 tempPatches[12].push_back(76);
197 tempPatches[12].push_back(70);
198 tempPatches[12].push_back(77);
199
200 tempPatches[13].push_back(159);
201 tempPatches[13].push_back(1);
202 tempPatches[13].push_back(155);
203 tempPatches[13].push_back(3);
204 tempPatches[13].push_back(153);
205 tempPatches[13].push_back(14);
206
207 tempPatches[14].push_back(23);
208 tempPatches[14].push_back(15);
209 tempPatches[14].push_back(139);
210 tempPatches[14].push_back(22);
211 tempPatches[14].push_back(127);
212 tempPatches[14].push_back(29);
213
214 tempPatches[15].push_back(111);
215 tempPatches[15].push_back(42);
216 tempPatches[15].push_back(123);
217 tempPatches[15].push_back(31);
218 tempPatches[15].push_back(43);
219 tempPatches[15].push_back(41);
220
221 tempPatches[16].push_back(103);
222 tempPatches[16].push_back(58);
223 tempPatches[16].push_back(102);
224 tempPatches[16].push_back(59);
225 tempPatches[16].push_back(47);
226 tempPatches[16].push_back(46);
227
228 tempPatches[17].push_back(95);
229 tempPatches[17].push_back(73);
230 tempPatches[17].push_back(75);
231 tempPatches[17].push_back(74);
232 tempPatches[17].push_back(81);
233 tempPatches[17].push_back(79);
234
235 tempPatches[18].push_back(93);
236 tempPatches[18].push_back(91);
237 tempPatches[18].push_back(94);
238 tempPatches[18].push_back(100);
239 tempPatches[18].push_back(101);
240
241 tempPatches[19].push_back(108);
242 tempPatches[19].push_back(109);
243 tempPatches[19].push_back(110);
244 tempPatches[19].push_back(115);
245 tempPatches[19].push_back(121);
246
247 tempPatches[20].push_back(124);
248 tempPatches[20].push_back(137);
249 tempPatches[20].push_back(126);
250 tempPatches[20].push_back(125);
251 tempPatches[20].push_back(122);
252
253 tempPatches[21].push_back(152);
254 tempPatches[21].push_back(147);
255 tempPatches[21].push_back(138);
256 tempPatches[21].push_back(143);
257 tempPatches[21].push_back(136);
258
259 tempPatches[22].push_back(156);
260 tempPatches[22].push_back(158);
261 tempPatches[22].push_back(154);
262 tempPatches[22].push_back(157);
263 tempPatches[22].push_back(151);
264
265 tempPatches[23].push_back(87);
266 tempPatches[23].push_back(80);
267 tempPatches[23].push_back(92);
268 tempPatches[23].push_back(82);
269 tempPatches[23].push_back(83);
270
271 tempPatches[24].push_back(144);
272 tempPatches[24].push_back(148);
273 tempPatches[24].push_back(150);
274 tempPatches[24].push_back(149);
275
276 tempPatches[25].push_back(145);
277 tempPatches[25].push_back(146);
278 tempPatches[25].push_back(141);
279 tempPatches[25].push_back(142);
280 tempPatches[25].push_back(134);
281 tempPatches[25].push_back(135);
282
283 tempPatches[26].push_back(113);
284 tempPatches[26].push_back(114);
285 tempPatches[26].push_back(119);
286 tempPatches[26].push_back(120);
287 tempPatches[26].push_back(130);
288 tempPatches[26].push_back(131);
289
290 tempPatches[27].push_back(88);
291 tempPatches[27].push_back(90);
292 tempPatches[27].push_back(98);
293 tempPatches[27].push_back(99);
294 tempPatches[27].push_back(106);
295 tempPatches[27].push_back(107);
296
297 tempPatches[28].push_back(89);
298 tempPatches[28].push_back(85);
299 tempPatches[28].push_back(86);
300 tempPatches[28].push_back(84);
301
302 tempPatches[29].push_back(140);
303 tempPatches[29].push_back(132);
304 tempPatches[29].push_back(133);
305 tempPatches[29].push_back(128);
306 tempPatches[29].push_back(129);
307 tempPatches[29].push_back(116);
308 tempPatches[29].push_back(118);
309
310 tempPatches[30].push_back(97);
311 tempPatches[30].push_back(96);
312 tempPatches[30].push_back(104);
313 tempPatches[30].push_back(105);
314 tempPatches[30].push_back(112);
315 tempPatches[30].push_back(117);
316
317
318
319 for (int i=0;i<NTMARK;i++)
320 {
321 float color[3];
322 if (i<NTMARK/3)
323 {
324 color[0] = (float)(i)/((float)(NTMARK)/3.f);
325 color[1] = 0;
326 color[2] = 0;
327 }
328 if (i >= NTMARK/3 && i<2*NTMARK/3)
329 {
330 color[0] = 1;
331 color[1] = (float)(i-NTMARK/3)/((float)(NTMARK)/3.f);
332 color[2] = 0;
333 }
334 if (i>=2*NTMARK/3)
335 {
336 color[0] = 0;
337 color[1] = 1;
338 color[2] = (float)(i-2*NTMARK/3)/((float)(NTMARK)/3.f);
339 }
340 color[0] /= 2;
341 color[1] /= 2;
342 color[2] /= 2;
343 setPatchColor(i, color);
344 }
345
346 currentView = 4;
347 nextView = currentView;
348 currentLoc = cameraViews[currentView];
349 steps = 0;
350 totalSteps = 50;
351
352 fMin = 0.f;
353 fMax = 50.f;
354 }
355 Q3DCameraWidget::~Q3DCameraWidget()
356 {
357
358 }
359 void Q3DCameraWidget::timedUpdate()
360 {
361 updateGL();
362 }
363 void Q3DCameraWidget::updateData(float* dataa)
364 {
365 memcpy(&fscTemps[0], dataa, 60*sizeof(float));
366
367 if (tempPatches.size() != 31 || !initFinished)
368 return;
369
370 for (int i=0;i<59;i++)
371 {
372// cout << i << " " << fscTemps[i] << endl;
373 float ratio = (fscTemps[i+1] - fMin)/(fMax - fMin);
374 // cout << fscTemps[i+1] << " " << i << endl;
375 float color[3];
376 if (ratio > ss[4])
377 {
378 color[0] = tooHighValueCoulour[0];
379 color[1] = tooHighValueCoulour[1];
380 color[2] = tooHighValueCoulour[2];
381 }
382 else
383 {
384 if (ratio < ss[0])
385 {
386 color[0] = tooLowValueCoulour[0];
387 color[1] = tooLowValueCoulour[1];
388 color[2] = tooLowValueCoulour[2];
389 }
390 else
391 {
392 // cout << "Calculating the actual value" << endl;
393 int index = 0;
394 while (index < 5 && ss[index] < ratio)
395 index ++;
396 index--;
397 float ratio2 = (ratio - ss[index])/(ss[index+1] - ss[index]);
398 float ratio3 = 1.f - ratio2;
399 color[0] = rr[index]*ratio3 + rr[index+1]*ratio2;
400 color[1] = gg[index]*ratio3 + gg[index+1]*ratio2;
401 color[2] = bb[index]*ratio3 + bb[index+1]*ratio2;
402 }
403 }
404 if (i < 31)
405 for (unsigned int j=0;j<tempPatches[i].size(); j++)
406 setPatchColor(tempPatches[i][j], color);
407 else
408 {
409 int ii = i-31;
410 for (;ii<28;ii++)
411 {
412 spheresRadius[ii] = 0.05*ratio + 0.01;
413 spheresColors[ii][0] = color[0];
414 spheresColors[ii][1] = color[1];
415 spheresColors[ii][2] = color[2];
416 }
417
418 }
419 }
420
421
422 if (!initFinished)
423 return;
424 UpdateText();
425 emit dataHasChanged();
426 // timer.start();
427 // updateGL();
428
429 }
430 void Q3DCameraWidget::mousePressEvent(QMouseEvent* cEvent)
431 {
432 if (cEvent->pos().x() > width()-(width()/50.f))
433 {
434 toggleInterfaceDisplay();
435 return;
436 }
437 int face = PixelAtPosition(cEvent->pos());
438 if (face != -1) {
439 fWhite = face;
440 if (face < 1440)
441 fWhitePatch = pixelsPatch[fWhite];
442 else
443 fWhitePatch = -1;
444// cout << "Patch Value: " << fWhitePatch << " fWhite: " << fWhite << endl;
445
446 emit signalCurrentPixel(face);
447 }
448 else
449 {
450 fWhite = -1;
451 fWhitePatch = -1;
452 }
453 UpdateText();
454 updateGL();
455 }
456 void Q3DCameraWidget::mouseDoubleClickEvent(QMouseEvent *cEvent)
457 {
458 int face = PixelAtPosition(cEvent->pos());
459 if (face != -1 && face < 1440) {
460 highlightPatches.push_back(pixelsPatch[face]);
461 updateGL();
462 return;
463// fWhitePatch = pixelsPatch[fWhite];
464 }
465 int dir = 0;
466 int xx = cEvent->pos().x();
467 int yx = cEvent->pos().y();
468 if (xx > width()/3) dir++;
469 if (xx > 2*width()/3) dir++;
470 if (yx > height()/3) dir+=3;
471 if (yx > 2*height()/3) dir+=3;
472
473 if (steps)
474 return;
475
476 nextView = dir;
477
478 if (nextView == currentView)
479 return;
480 steps = totalSteps;
481 timer.start();
482 }
483 int Q3DCameraWidget::PixelAtPosition(const QPoint &cPos)
484 {
485 const int MaxSize = 512;
486 GLuint buffer[MaxSize];
487 GLint viewport[4];
488
489 makeCurrent();
490
491 glGetIntegerv(GL_VIEWPORT, viewport);
492 glSelectBuffer(MaxSize, buffer);
493 glRenderMode(GL_SELECT);
494
495 glInitNames();
496 glPushName(0);
497
498 glMatrixMode(GL_PROJECTION);
499 glPushMatrix();
500 glLoadIdentity();
501//cout << "Viewport: " << viewport[0] << " " << viewport[1] << " " << viewport[2] << " " << viewport[3] << endl;
502 gluPickMatrix(cPos.x(), viewport[3] - cPos.y(), 1, 1, viewport);
503
504 GLfloat windowRatio = (float)viewport[2]/(float)viewport[3];
505 gluPerspective(40.f, windowRatio, 1, 10);
506
507 glMatrixMode(GL_MODELVIEW);
508 isPicking = true;
509 paintGL();
510 isPicking = false;
511 glMatrixMode(GL_PROJECTION);
512 glPopMatrix();
513
514 //for some reason that I cannot understand, the push/pop matrix doesn't do the trick here... bizarre
515 //ok, so re-do the resizeGL thing.
516 resizeGL(width(), height());
517
518 int hits = glRenderMode(GL_RENDER);
519 if (!hits)
520 return -1;
521// else
522 // cout << "There are " << hits << " hits..." << endl;
523// for (int i=0;i<MaxSize;i++)
524// cout << buffer[i] << " ";
525 // cout << endl;
526
527 if (buffer[3] < 1440+28)
528 return buffer[3];
529 else
530 return -1;
531 }
532 void Q3DCameraWidget::paintGL()
533 {
534 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
535 glLoadIdentity();
536
537 glTranslatef(0,-0.315, -3);
538// glScalef(1.5, 1.5, 1.5);
539
540 float speed = 0.5f + 0.5f*cos(M_PI*((float)steps/(float)(totalSteps)));
541
542
543 if (currentView != nextView)
544 {
545 float targetRotX = cameraViews[nextView].rotX;
546 float targetRotY = cameraViews[nextView].rotY;
547 if (fabs(targetRotX - 315) < 0.01f && cameraViews[currentView].rotX == 0)
548 targetRotX -= 360;
549 if (fabs(targetRotX) < 0.01f && cameraViews[currentView].rotX == 315)
550 targetRotX += 360;
551
552 if (fabs(targetRotY - 315) < 0.01f && cameraViews[currentView].rotY == 0)
553 targetRotY -= 360;
554 if (fabs(targetRotY) < 0.01f && cameraViews[currentView].rotY == 315)
555 targetRotY += 360;
556 currentLoc.rotX = cameraViews[currentView].rotX + speed*(targetRotX - cameraViews[currentView].rotX);
557 currentLoc.rotY = cameraViews[currentView].rotY + speed*(targetRotY - cameraViews[currentView].rotY);
558 for (int i=0;i<3;i++)
559 currentLoc.position[i] = cameraViews[currentView].position[i] + speed*(cameraViews[nextView].position[i] - cameraViews[currentView].position[i]);
560 steps--;
561 if (!steps)//fabs(currentLoc.rotX - cameraViews[nextView].rotX) <0.01)
562 {
563 currentLoc = cameraViews[nextView];
564 // currentLoc.rotX = cameraViews[nextView].rotX;
565 // currentLoc.rotY = cameraViews[nextView].rotY;
566 // for (int i=0;i<3;i++)
567 // currentLoc.position[i] = cameraViews[nextView].position[i];
568 currentView = nextView;
569 timer.stop();
570 }
571 }
572 else
573 {
574 timer.stop();
575 }
576 glTranslatef(currentLoc.position[0], currentLoc.position[1], currentLoc.position[2]);
577 glRotatef(currentLoc.rotX, 1,0,0);
578 glRotatef(currentLoc.rotY, 0,1,0);
579
580 glTranslatef(0,0.315,0);
581 glRotatef(cameraRotation, 0,0,1);
582 glTranslatef(0,-0.315,0);
583 // rotY +=0.1;
584 // glRotatef(rotY, 0,1,0);
585 // glRotatef(rotX, 1,0,0);
586// glRotatef(90, 1,0,0);
587 drawCamera(true);
588 glTranslatef(0,0,0.01);
589 drawPatches();
590 if (fWhite != -1 && fWhite < 1440)
591 {
592 glTranslatef(0,0,0.01);
593 glColor3f(1.f, 0.f, 0.f);
594 drawHexagon(fWhite, false);
595 glTranslatef(0,0,-0.01);
596 }
597 glTranslatef(0,0,0.01);
598 glColor3f(1.0f, 0.5f, 0.0f);
599 glBegin(GL_LINES);
600 for (auto it=highlightPatches.begin(); it!=highlightPatches.end(); it++)
601 {
602 for (unsigned int j=0;j<patchesIndices[*it].size();j++)
603 {
604 glVertex2fv(verticesList[patchesIndices[*it][j].first]);
605 glVertex2fv(verticesList[patchesIndices[*it][j].second]);
606 }
607 }
608 glEnd();
609
610 glEnable(GL_LIGHTING);
611 glEnable(GL_LIGHT0);
612 glTranslatef(0,0.315, 0);
613 glRotatef(180,1,0,0);
614 drawSpheres();
615 drawCameraBody();
616 if (fWhite < 1500 && fWhite >= 1440)
617 {
618 // cout << "Drawing wireframe sphere " << fWhite << endl;
619 glPushMatrix();
620 GLfloat red[4] = {0, 0, 0, 1};
621 red[0] = 1.f - spheresColors[fWhite-1440][0];
622 red[1] = 1.f - spheresColors[fWhite-1440][1];
623 red[2] = 1.f - spheresColors[fWhite-1440][2];
624 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red);
625 glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
626 // glColor3fv(spheresColors[i].data);
627 glTranslatef(spheresLocation[fWhite-1440][0], spheresLocation[fWhite-1440][1], spheresLocation[fWhite-1440][2]);
628 gluSphere(gluNewQuadric(), 0.11f, 15, 15);
629 glPopMatrix();
630 glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
631 }
632
633
634 glDisable(GL_LIGHTING);
635
636 if (isPicking)
637 return;
638
639 BasicGlCamera::resizeGL(width(), height());
640 glDisable(GL_DEPTH_TEST);
641 DrawCameraText();
642 DrawScale();
643 glEnable(GL_DEPTH_TEST);
644 resizeGL(width(), height());
645
646 initFinished = true;
647
648 }
649 void Q3DCameraWidget::UpdateText()
650 {
651 if (fWhitePatch != -1)
652 {
653 ostringstream str;
654 str << "Patch " << fWhitePatch << " Temperature: ";
655 int patchIndice = -1;
656 unsigned int i=0;
657 for (auto it = tempPatches.begin(); it != tempPatches.end(); it++)
658 {
659 for (auto jt = it->begin(); jt != it->end(); jt++)
660 if (*jt == fWhitePatch)
661 {
662 patchIndice = i;
663 break;
664 }
665 if (patchIndice != -1)
666 break;
667 i++;
668 }
669 if (i==tempPatches.size())
670 {
671 dataText = "Error, patch couldn't be found in patch list";
672 }
673 else
674 {
675 str << fscTemps[i+1] << " degrees";
676 dataText = str.str();
677 }
678 return;
679 }
680 if (fWhite >= 1440 && fWhite < 1500)
681 {
682 ostringstream str;
683 int whi = fWhite - 1440;
684 switch (whi)
685 {
686 case 0:
687 case 1:
688 case 2:
689 case 3:
690 case 4:
691 case 5:
692 case 6:
693 case 7:
694 str << "Crate sensor #" << whi;
695 break;
696 case 8:
697 case 9:
698 case 10:
699 case 11:
700 case 12:
701 case 13:
702 case 14:
703 case 15:
704 str << "Power supply (crate) #" << whi-8;
705 break;
706 case 16:
707 case 17:
708 case 18:
709 case 19:
710 str << "Power supply (Aux) #" << whi - 16;
711 break;
712 case 20:
713 case 21:
714 case 22:
715 case 23:
716 str << "Back panel #" << whi - 20;
717 break;
718 case 24:
719 case 25:
720 case 26:
721 case 27:
722 str << "Switch box #" << whi - 24;
723 break;
724 default:
725 str << "Something went wrong " << whi;
726 }
727 str << ": " << fscTemps[whi+32] << " degrees";
728 dataText = str.str();
729 return;
730 }
731
732 dataText = "";
733 }
734 void Q3DCameraWidget::drawSpheres()
735 {
736// GLUquadric* quad = gluNewQuadric();
737 for (int i=0;i<28;i++)
738 {
739 glPushMatrix();
740 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, spheresColors[i].data);
741 glLoadName(i + 1440);
742 // glColor3fv(spheresColors[i].data);
743 glTranslatef(spheresLocation[i][0], spheresLocation[i][1], spheresLocation[i][2]);
744 gluSphere(gluNewQuadric(), 0.1f, 10, 10);//spheresRadius[i], 10, 10);
745 glPopMatrix();
746 }
747 glLoadName(1500);
748 glPushAttrib(GL_LIGHTING_BIT);
749 glDisable(GL_LIGHTING);
750 glColor3f(0.6,0.6,0.6);
751 glBegin(GL_LINE_LOOP);
752 for (int i=0;i<4;i++)
753 glVertex3fv(spheresLocation[i].data);
754 glEnd();
755 glBegin(GL_LINE_LOOP);
756 for (int i=4;i<8;i++)
757 glVertex3fv(spheresLocation[i].data);
758 glEnd();
759 glBegin(GL_LINE_LOOP);
760 for (int i=8;i<12;i++)
761 glVertex3fv(spheresLocation[i].data);
762 glEnd();
763 glBegin(GL_LINE_LOOP);
764 for (int i=12;i<16;i++)
765 glVertex3fv(spheresLocation[i].data);
766 glEnd();
767 glBegin(GL_LINE_LOOP);
768 for (int i=16;i<18;i++)
769 glVertex3fv(spheresLocation[i].data);
770 glEnd();
771 glBegin(GL_LINE_LOOP);
772 for (int i=18;i<20;i++)
773 glVertex3fv(spheresLocation[i].data);
774 glEnd();
775 glBegin(GL_LINE_LOOP);
776 for (int i=20;i<24;i++)
777 glVertex3fv(spheresLocation[i].data);
778 glEnd();
779 glBegin(GL_LINE_LOOP);
780 for (int i=24;i<26;i++)
781 glVertex3fv(spheresLocation[i].data);
782 glEnd();
783 glBegin(GL_LINE_LOOP);
784 for (int i=26;i<28;i++)
785 glVertex3fv(spheresLocation[i].data);
786 glEnd();
787
788 glPopAttrib();
789 }
790
791 void Q3DCameraWidget::drawCameraBody()
792 {
793 glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
794
795 GLfloat color[4] = {0.4f, 0.5f, 0.5f, 1.f};
796 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
797 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 1.0f);
798 gluCylinder( gluNewQuadric(),
799 0.62,
800 0.62,
801 1.83,
802 30,
803 2 );
804 glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
805
806
807
808 }
809 void Q3DCameraWidget::drawCamera(bool alsoWire)
810 {
811 glColor3f(0.5,0.5,0.5);
812 glLineWidth(1.0);
813 for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
814 {
815 glColor3fv(pixelsColor[i]);
816 glLoadName(i);
817 drawHexagon(i,true);
818 }
819 if (!alsoWire)
820 return;
821 glTranslatef(0,0,0.01);
822 glColor3f(0.0f,0.0f,0.0f);
823 for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
824 {
825 drawHexagon(i, false);
826 }
827// glLoadName(1440);
828 }
829 void Q3DCameraWidget::initializeGL()
830 {
831 qglClearColor(QColor(25,25,38));
832
833 glShadeModel(GL_SMOOTH);
834 glEnable(GL_DEPTH_TEST);
835 glDepthFunc(GL_LESS);
836 glDisable(GL_CULL_FACE);
837// glCullFace(GL_FRONT);
838
839 glEnable(GL_LINE_SMOOTH);
840 glEnable(GL_BLEND);
841 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
842 glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
843 }
844 void Q3DCameraWidget::resizeGL(int cWidth, int cHeight)
845 {
846 glViewport(0,0,cWidth, cHeight);
847 glMatrixMode(GL_PROJECTION);
848 glLoadIdentity();
849 GLfloat windowRatio = (float)cWidth/(float)cHeight;
850 if (windowRatio < 1)
851 {
852// windowRatio = 1.0f/windowRatio;
853 gluPerspective(40.f, windowRatio, 1, 10);
854// gluOrtho2D(-viewSize, viewSize, -viewSize*windowRatio, viewSize*windowRatio);
855 pixelSize = 2*viewSize/(float)cWidth;
856 shownSizex = 2*viewSize;
857 shownSizey = 2*viewSize*windowRatio;
858 }
859 else
860 {
861 gluPerspective(40.f, windowRatio, 1, 10);
862// gluOrtho2D(-viewSize*windowRatio, viewSize*windowRatio, -viewSize, viewSize);
863 pixelSize = 2*viewSize/(float)cHeight;
864 shownSizex = 2*viewSize*windowRatio;
865 shownSizey = 2*viewSize;
866 }
867 glMatrixMode(GL_MODELVIEW);
868 }
Note: See TracBrowser for help on using the repository browser.