source: trunk/FACT++/gui/BasicGlCamera.cc@ 11902

Last change on this file since 11902 was 11901, checked in by lyard, 13 years ago
many changes...
File size: 34.2 KB
Line 
1#include "BasicGlCamera.h"
2#include <math.h>
3#include <fstream>
4#include <iostream>
5#include <string>
6#include <sstream>
7#include "src/tools.h"
8
9//Coordinates of an hexagon of radius 1 and center 0
10GLfloat hexcoords[6][2] = {{-1./sqrt(3.), 1},
11 { 1./sqrt(3.), 1},
12 { 2./sqrt(3.), 0},
13 { 1./sqrt(3.), -1},
14 {-1./sqrt(3.), -1},
15 {-2./sqrt(3.), 0}};
16
17
18
19 BasicGlCamera::BasicGlCamera(QWidget* cParent) : QGLWidget(cParent)
20 {
21 setFormat(QGLFormat(QGL::DoubleBuffer));// | QGL::DepthBuffer));
22 fWhite = -1;
23 fWhitePatch = -1;
24 fMin = -1;
25 fMax = -1;
26 logScale = false;
27 cameraRotation = 0;
28 unitsText = "";
29 titleText = "";
30 dataText = "";
31 pixelContourColour[0] = 0.1f;
32 pixelContourColour[1] = 0.1f;
33 pixelContourColour[2] = 0.1f;
34 patchesCoulour[0] = 0.1f;
35 patchesCoulour[1] = 0.1f;
36 patchesCoulour[2] = 0.1f;
37 highlightedPatchesCoulour[0] = 0.6f;
38 highlightedPatchesCoulour[1] = 0.6f;
39 highlightedPatchesCoulour[2] = 0.6f;
40 highlightedPixelsCoulour[0] = 0.8f;
41 highlightedPixelsCoulour[1] = 0.8f;
42 highlightedPixelsCoulour[2] = 0.8f;
43
44 regularPalettePlease(true);
45
46
47 hexRadius = 0.015f;
48 hexTolerance = hexRadius/100.0f;
49 viewSize = 1.0f;
50 calculatePixelsCoords();
51
52 ifstream fin2("MasterList-v3.txt");
53 if (!fin2.is_open())
54 {
55 cout << "Error: file \"MasterList-v3\" missing. aborting." << endl;
56 exit(-1);
57 }
58 int l = 0;
59 string buf;
60 while (getline(fin2, buf, '\n'))
61 {
62 buf = Tools::Trim(buf);
63 if (buf[0]=='#')
64 continue;
65
66 unsigned int softid, hardid, dummy;
67
68 stringstream str(buf);
69
70 str >> softid;
71 str >> dummy;
72 str >> hardid;
73
74 if (softid>=1440)
75 continue;
76
77 hardwareMapping[softid] = hardid;
78 softwareMapping[hardid] = softid;
79
80 l++;
81 }
82// GLfloat tempPixelsCoords[MAX_NUM_PIXELS][3];
83// for (int i=0;i<1440;i++)
84// for (int j=0;j<3;j++)
85// tempPixelsCoords[hardwareMapping[i]][j] = pixelsCoords[i][j];
86// for (int i=0;i<1440;i++)
87// for (int j=0;j<3;j++)
88// pixelsCoords[i][j] = tempPixelsCoords[i][j];
89 buildVerticesList();
90 ifstream fin1("Trigger-Patches.txt");
91 if (!fin1.is_open())
92 {
93 cout << "Error: file \"Trigger-Patches.txt\" missing. Aborting." << endl;
94 exit(-1);
95 }
96 l=0;
97 while (getline(fin1, buf, '\n'))
98 {
99 buf = Tools::Trim(buf);
100 if (buf[0]=='#')
101 continue;
102
103 stringstream str(buf);
104 for (int i=0; i<9; i++)
105 {
106 unsigned int n;
107 str >> n;
108
109 if (n>=1440)
110 continue;
111
112 patches[l][i] = hardwareMapping[n];
113 }
114 l++;
115 }
116
117 //now construct the correspondance between pixels and patches
118 for (int i=0;i<NTMARK;i++)
119 for (int j=0;j<9;j++)
120 pixelsPatch[softwareMapping[patches[i][j]]] = i;
121
122 for (int i=0;i<1440;i++)
123 updateNeighbors(i);
124
125 buildPatchesIndices();
126
127 ss[0] = 0; ss[1] = 0.25f; ss[2] = 0.5f; ss[3] = 0.75f; ss[4] = 1.0f;
128 rr[0] = 0.15; rr[1] = 0; rr[2] = 0; rr[3] = 1.0f; rr[4] = 0.85f;
129 gg[0] = 0.15; gg[1] = 0; gg[2] = 1; gg[3] = 0; gg[4] = 0.85f;
130 bb[0] = 0.15; bb[1] = 1; bb[2] = 0; bb[3] = 0; bb[4] = 0.85f;
131
132 fPixelStride = 1;
133 fcSlice = 0;
134 fData.resize(1440);
135 for (int i=0;i<ACTUAL_NUM_PIXELS+2;i++)
136 fData[i] = (double)i;///1.44;//(double)(i)/(double)(ACTUAL_NUM_PIXELS);
137
138
139 setFont(QFont("Arial", 8));
140 int buttonShift=0;
141 scaleLabel = new QLabel("Scale", this);
142// buttonShift += scaleLabel->height();
143
144 linearButton = new QRadioButton("Linear", this);
145 linearButton->move(scaleLabel->width(), buttonShift);
146 buttonShift += linearButton->height();
147
148 logButton = new QRadioButton("Log", this);
149 logButton->move(scaleLabel->width(), buttonShift);
150 buttonShift += logButton->height()*1.1f;
151
152 colorPaletteLabel = new QLabel("Colour\nPalette", this);
153 colorPaletteLabel->move(0, buttonShift);
154 // buttonShift += colorPaletteLabel->height();
155
156 regularPaletteButton = new QRadioButton("Regular", this);
157 regularPaletteButton->move(colorPaletteLabel->width(), buttonShift);
158 buttonShift += regularPaletteButton->height();
159
160 prettyPaletteButton = new QRadioButton("Pretty", this);
161 prettyPaletteButton->move(colorPaletteLabel->width(), buttonShift);
162 buttonShift += prettyPaletteButton->height();
163
164 greyScalePaletteButton = new QRadioButton("Grey Scale", this);
165 greyScalePaletteButton->move(colorPaletteLabel->width(), buttonShift);
166 buttonShift += greyScalePaletteButton->height();
167
168 glowingPaletteButton = new QRadioButton("Glowing", this);
169 glowingPaletteButton->move(colorPaletteLabel->width(), buttonShift);
170 buttonShift += glowingPaletteButton->height()*1.1f;
171
172 rotationLabel = new QLabel("Camera\nRotation", this);
173 rotationLabel->move(0, buttonShift);
174 // buttonShift += rotationLabel->height();
175
176 unsigned short utf16Array;
177 utf16Array = 0x00b0;
178 QString degreeSymbol(QString::fromUtf16(&utf16Array, 1));
179 QString zerostr("0" + degreeSymbol);
180 zeroRotationButton = new QRadioButton(zerostr, this);
181 zeroRotationButton->move(rotationLabel->width(), buttonShift);
182 buttonShift += zeroRotationButton->height();
183 QString minus90str("-90" + degreeSymbol);
184 minus90RotationButton = new QRadioButton(minus90str, this);
185 minus90RotationButton->move(rotationLabel->width(), buttonShift);
186 buttonShift += minus90RotationButton->height();
187 QString plus90str("+90"+degreeSymbol);
188 plus90Rotationbutton = new QRadioButton(plus90str, this);
189 plus90Rotationbutton->move(rotationLabel->width(), buttonShift);
190
191
192 scaleGroup = new QButtonGroup(this);
193 colorGroup = new QButtonGroup(this);
194 rotationGroup = new QButtonGroup(this);
195 scaleGroup->addButton(linearButton);
196 scaleGroup->addButton(logButton);
197 colorGroup->addButton(regularPaletteButton);
198 colorGroup->addButton(prettyPaletteButton);
199 colorGroup->addButton(greyScalePaletteButton);
200 colorGroup->addButton(glowingPaletteButton);
201 rotationGroup->addButton(zeroRotationButton);
202 rotationGroup->addButton(minus90RotationButton);
203 rotationGroup->addButton(plus90Rotationbutton);
204
205 linearButton->setChecked(true);
206 regularPaletteButton->setChecked(true);
207 zeroRotationButton->setChecked(true);
208
209// linearButton->palette.setColor();
210
211 linearButton->setAutoFillBackground(true);
212 logButton->setAutoFillBackground(true);
213 regularPaletteButton->setAutoFillBackground(true);
214 prettyPaletteButton->setAutoFillBackground(true);
215 greyScalePaletteButton->setAutoFillBackground(true);
216 glowingPaletteButton->setAutoFillBackground(true);
217 zeroRotationButton->setAutoFillBackground(true);
218 minus90RotationButton->setAutoFillBackground(true);
219 plus90Rotationbutton->setAutoFillBackground(true);
220 scaleLabel->setAutoFillBackground(true);
221 colorPaletteLabel->setAutoFillBackground(true);
222 rotationLabel->setAutoFillBackground(true);
223
224 linearButton->hide();
225 logButton->hide();
226 regularPaletteButton->hide();
227 prettyPaletteButton->hide();
228 greyScalePaletteButton->hide();
229 glowingPaletteButton->hide();
230 zeroRotationButton->hide();
231 minus90RotationButton->hide();
232 plus90Rotationbutton->hide();
233 scaleLabel->hide();
234 colorPaletteLabel->hide();
235 rotationLabel->hide();
236
237 connect(linearButton, SIGNAL(toggled(bool)),
238 this, SLOT(linearScalePlease(bool)));
239 connect(logButton, SIGNAL(toggled(bool)),
240 this, SLOT(logScalePlease(bool)));
241 connect(regularPaletteButton, SIGNAL(toggled(bool)),
242 this, SLOT(regularPalettePlease(bool)));
243 connect(prettyPaletteButton, SIGNAL(toggled(bool)),
244 this, SLOT(prettyPalettePlease(bool)));
245 connect(greyScalePaletteButton, SIGNAL(toggled(bool)),
246 this, SLOT(greyScalePalettePlease(bool)));
247 connect(glowingPaletteButton, SIGNAL(toggled(bool)),
248 this, SLOT(glowingPalettePlease(bool)));
249 connect(zeroRotationButton, SIGNAL(toggled(bool)),
250 this, SLOT(zeroRotationPlease(bool)));
251 connect(minus90RotationButton, SIGNAL(toggled(bool)),
252 this, SLOT(plus90RotationPlease(bool)));
253 connect(plus90Rotationbutton, SIGNAL(toggled(bool)),
254 this, SLOT(minus90RotationPlease(bool)));
255
256
257
258 }
259 BasicGlCamera::~BasicGlCamera()
260 {
261 }
262 void BasicGlCamera::setUnits(const string& units)
263 {
264 unitsText = units;
265 pixelColorUpToDate = false;
266 if (isVisible())
267 updateGL();
268 }
269 void BasicGlCamera::setTitle(const string& title)
270 {
271 titleText = title;
272 pixelColorUpToDate = false;
273 if (isVisible())
274 updateGL();
275 }
276 void BasicGlCamera::SetWhite(int idx)
277 {
278 fWhite = idx;
279 fWhitePatch = pixelsPatch[fWhite];
280 if (isVisible())
281 updateGL();
282// CalculatePatchColor();
283 }
284 void BasicGlCamera::SetMin(int64_t min)
285 {
286// cout << "min: " << min << endl;
287 fMin = min;
288 pixelColorUpToDate = false;
289 if (isVisible())
290 updateGL();
291 }
292 void BasicGlCamera::SetMax(int64_t max)
293 {
294// cout << "max: " << max << endl;
295 fMax = max;
296 pixelColorUpToDate = false;
297 if (isVisible())
298 updateGL();
299 }
300 void BasicGlCamera::linearScalePlease(bool checked)
301 {
302 if (!checked) return;
303 logScale = false;
304 pixelColorUpToDate = false;
305 emit colorPaletteHasChanged();
306 if (isVisible())
307 updateGL();
308 }
309 void BasicGlCamera::UpdateText()
310 {
311 ostringstream str;
312 float min, max, mean, rms, median;
313 min = max = fData[0];
314 mean = 0;
315 rms = 0;
316 median = 0;
317 multiset<double> medianSet;
318 for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
319 {
320 if (fData[i] < min)
321 min = fData[i];
322 if (fData[i] > max)
323 max = fData[i];
324 mean += fData[i];
325 rms += fData[i]*fData[i];
326 medianSet.insert(fData[i]);
327 }
328 mean /= ACTUAL_NUM_PIXELS;
329 rms /= ACTUAL_NUM_PIXELS;
330 rms = sqrt(rms);
331// cout << "Size of the set: " << medianSet.size() << endl;
332 multiset<double>::iterator it = medianSet.begin();
333 for (int i=0;i<(ACTUAL_NUM_PIXELS/2)-1;i++)
334 it++;
335 median = *it;
336 it++;
337 median += *it;
338 median /= 2;
339
340 str << "Min: " << min << " Max: " << max << " Mean: " << mean << " RMS: " << rms << " Median: " << median;
341 str << " Units: " << unitsText;
342 dataText = str.str();
343 }
344 void BasicGlCamera::DrawCameraText()
345 {
346 glPushMatrix();
347 glLoadIdentity();
348// cout << width() << " " << height() << endl;
349 int textSize = (int)(height()*14/600);
350 setFont(QFont("Times", textSize));
351 qglColor(QColor(255,223,127));
352 float shiftx = 0.01f;//0.55f;
353 float shifty = 0.01f;//0.65f;
354 renderText(-shownSizex/2.f + shiftx, -shownSizey/2.f + shifty, 0.f, QString(dataText.c_str()));
355
356
357 int textLength = titleText.size();
358 renderText(-shownSizex/2.f + shiftx, shownSizey/2.f - textSize*pixelSize - shifty, 0.f, QString(titleText.c_str()));
359
360 glPopMatrix();
361 }
362 void BasicGlCamera::DrawScale()
363 {
364 glPushMatrix();
365 glLoadIdentity();
366 glPushAttrib(GL_POLYGON_BIT);
367 glShadeModel(GL_SMOOTH);
368 glBegin(GL_QUADS);
369 float oneX = shownSizex/2.f - shownSizex/50.f;
370 float twoX = shownSizex/2.f;
371 float oneY = -shownSizey/2.f;
372 float twoY = -shownSizey/4.f;
373 float threeY = 0;
374 float fourY = shownSizey/4.f;
375 float fiveY = shownSizey/2.f;
376 glColor3f(rr[0], gg[0], bb[0]);
377 glVertex2f(oneX, oneY);
378 glVertex2f(twoX, oneY);
379 glColor3f(rr[1], gg[1], bb[1]);
380 glVertex2f(twoX, twoY);
381 glVertex2f(oneX, twoY);
382
383 glVertex2f(oneX, twoY);
384 glVertex2f(twoX, twoY);
385 glColor3f(rr[2], gg[2], bb[2]);
386 glVertex2f(twoX, threeY);
387 glVertex2f(oneX, threeY);
388
389 glVertex2f(oneX, threeY);
390 glVertex2f(twoX, threeY);
391 glColor3f(rr[3], gg[3], bb[3]);
392 glVertex2f(twoX, fourY);
393 glVertex2f(oneX, fourY);
394
395 glVertex2f(oneX, fourY);
396 glVertex2f(twoX, fourY);
397 glColor3f(rr[4], gg[4], bb[4]);
398 glVertex2f(twoX, fiveY);
399 glVertex2f(oneX, fiveY);
400 float zeroX = oneX - shownSizex/50.f;
401 float zeroY = fiveY - shownSizey/50.f;
402 glColor3fv(tooHighValueCoulour);
403 glVertex2f(zeroX, fiveY);
404 glVertex2f(oneX, fiveY);
405 glVertex2f(oneX, zeroY);
406 glVertex2f(zeroX, zeroY);
407 glColor3fv(tooLowValueCoulour);
408 glVertex2f(zeroX, -fiveY);
409 glVertex2f(oneX, -fiveY);
410 glVertex2f(oneX, -zeroY);
411 glVertex2f(zeroX, -zeroY);
412 glEnd();
413 //draw linear/log tick marks
414 glColor3f(0.f,0.f,0.f);
415 glBegin(GL_LINES);
416 float value;
417 for (int i=1;i<10;i++)
418 {
419 if (logScale)
420 value = log10(i);
421 else
422 value = (float)(i)/10.f;
423 float y = -shownSizey/2.f + value*shownSizey;
424 glVertex2f(oneX, y);
425 glVertex2f(twoX, y);
426 }
427 glEnd();
428 glPopAttrib();
429 glPopMatrix();
430 }
431 void BasicGlCamera::logScalePlease(bool checked)
432 {
433 if (!checked) return;
434 logScale = true;
435 pixelColorUpToDate = false;
436 emit colorPaletteHasChanged();
437 if (isVisible())
438 updateGL();
439 }
440 void BasicGlCamera::regularPalettePlease(bool checked)
441 {
442 if (!checked) return;
443 ss[0] = 0; ss[1] = 0.25f; ss[2] = 0.5f; ss[3] = 0.75f; ss[4] = 1.0f;
444 rr[0] = 0.15; rr[1] = 0; rr[2] = 0; rr[3] = 1.0f; rr[4] = 0.85f;
445 gg[0] = 0.15; gg[1] = 0; gg[2] = 1; gg[3] = 0; gg[4] = 0.85f;
446 bb[0] = 0.15; bb[1] = 1; bb[2] = 0; bb[3] = 0; bb[4] = 0.85f;
447 tooHighValueCoulour[0] = 1.f;
448 tooHighValueCoulour[1] = 1.f;
449 tooHighValueCoulour[2] = 0.f;
450 tooLowValueCoulour[0] = 0.f;
451 tooLowValueCoulour[1] = 1.f;
452 tooLowValueCoulour[2] = 1.f;
453 pixelColorUpToDate = false;
454
455 emit colorPaletteHasChanged();
456
457 if (isVisible())
458 updateGL();
459 }
460 void BasicGlCamera::prettyPalettePlease(bool checked)
461 {
462 if (!checked) return;
463 ss[0] = 0.f; ss[1] = 0.25f; ss[2] = 0.5f; ss[3] = 0.75f; ss[4] = 1.0f;
464 rr[0] = 0.f; rr[1] = 0.35f; rr[2] = 0.85f; rr[3] = 1.0f; rr[4] = 1.f;
465 gg[0] = 0.f; gg[1] = 0.10f; gg[2] = 0.20f; gg[3] = 0.73f; gg[4] = 1.f;
466 bb[0] = 0.f; bb[1] = 0.03f; bb[2] = 0.06f; bb[3] = 0.00f; bb[4] = 1.f;
467 tooHighValueCoulour[0] = 0.f;
468 tooHighValueCoulour[1] = 1.f;
469 tooHighValueCoulour[2] = 0.f;
470 tooLowValueCoulour[0] = 0.f;
471 tooLowValueCoulour[1] = 0.f;
472 tooLowValueCoulour[2] = 1.f;
473 pixelColorUpToDate = false;
474
475 emit colorPaletteHasChanged();
476
477 if (isVisible())
478 updateGL();
479 }
480 void BasicGlCamera::greyScalePalettePlease(bool checked)
481 {
482 if (!checked) return;
483 ss[0] = 0; ss[1] = 0.25f; ss[2] = 0.5f; ss[3] = 0.75f; ss[4] = 1.0f;
484 rr[0] = 0; rr[1] = 0.25f; rr[2] = 0.5f; rr[3] = 0.75f; rr[4] = 1.0f;
485 gg[0] = 0; gg[1] = 0.25f; gg[2] = 0.5f; gg[3] = 0.75f; gg[4] = 1.0f;
486 bb[0] = 0; bb[1] = 0.25f; bb[2] = 0.5f; bb[3] = 0.75f; bb[4] = 1.0f;
487 tooHighValueCoulour[0] = 0.f;
488 tooHighValueCoulour[1] = 1.f;
489 tooHighValueCoulour[2] = 0.f;
490 tooLowValueCoulour[0] = 0.f;
491 tooLowValueCoulour[1] = 0.f;
492 tooLowValueCoulour[2] = 1.f;
493 pixelColorUpToDate = false;
494
495 emit colorPaletteHasChanged();
496
497 if (isVisible())
498 updateGL();
499 }
500 void BasicGlCamera::glowingPalettePlease(bool checked)
501 {
502 if (!checked) return;
503 ss[0] = 0; ss[1] = 0.25f; ss[2] = 0.5f; ss[3] = 0.75f; ss[4] = 1.0f;
504 rr[0] = 0.15; rr[1] = 0.5; rr[2] = 1.f; rr[3] = 0.0f; rr[4] = 1.f;
505 gg[0] = 0.15; gg[1] = 0.5; gg[2] = 1.f; gg[3] = 0.5f; gg[4] = 0.5f;
506 bb[0] = 0.15; bb[1] = 0.5; bb[2] = 1; bb[3] = 1.f; bb[4] = 0.f;
507 tooHighValueCoulour[0] = 1.f;
508 tooHighValueCoulour[1] = 0.f;
509 tooHighValueCoulour[2] = 0.f;
510 tooLowValueCoulour[0] = 0.f;
511 tooLowValueCoulour[1] = 1.f;
512 tooLowValueCoulour[2] = 0.f;
513 pixelColorUpToDate = false;
514
515 emit colorPaletteHasChanged();
516
517 if (isVisible())
518 updateGL();
519 }
520 void BasicGlCamera::zeroRotationPlease(bool checked)
521 {
522 if (!checked) return;
523 cameraRotation = 0;
524 pixelColorUpToDate = false;
525 if (isVisible())
526 updateGL();
527 }
528 void BasicGlCamera::plus90RotationPlease(bool checked)
529 {
530 if (!checked) return;
531 cameraRotation = 90;
532 pixelColorUpToDate = false;
533 if (isVisible())
534 updateGL();
535 }
536 void BasicGlCamera::minus90RotationPlease(bool checked)
537 {
538 if (!checked) return;
539 cameraRotation = -90;
540 pixelColorUpToDate = false;
541 if (isVisible())
542 updateGL();
543 }
544
545 void BasicGlCamera::initializeGL()
546 {
547 qglClearColor(QColor(25,25,38));
548 glShadeModel(GL_FLAT);
549 glDisable(GL_DEPTH_TEST);
550 glDisable(GL_CULL_FACE);
551
552 glEnable (GL_LINE_SMOOTH);
553 glEnable (GL_BLEND);
554 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
555 glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
556
557 }
558 void BasicGlCamera::resizeGL(int cWidth, int cHeight)
559 {
560 glViewport(0, 0, cWidth, cHeight);
561 glMatrixMode(GL_PROJECTION);
562 glLoadIdentity();
563 GLfloat windowRatio = (float)cWidth/(float)cHeight;
564 if (windowRatio < 1)
565 {
566 windowRatio = 1.0f/windowRatio;
567 gluOrtho2D(-viewSize, viewSize, -viewSize*windowRatio, viewSize*windowRatio);
568 pixelSize = 2*viewSize/(float)cWidth;
569 shownSizex = 2*viewSize;
570 shownSizey = 2*viewSize*windowRatio;
571 }
572 else
573 {
574 gluOrtho2D(-viewSize*windowRatio, viewSize*windowRatio, -viewSize, viewSize);
575 pixelSize = 2*viewSize/(float)cHeight;
576 shownSizex = 2*viewSize*windowRatio;
577 shownSizey = 2*viewSize;
578 }
579 glMatrixMode(GL_MODELVIEW);
580 }
581 void BasicGlCamera::paintGL()
582 {
583 glClear(GL_COLOR_BUFFER_BIT);
584 glLoadIdentity();
585
586 glTranslatef(0,-0.44,0);
587 glScalef(1.5, 1.5, 1.5);
588
589 drawCamera(true);
590
591 drawPatches();
592 }
593 void BasicGlCamera::toggleInterfaceDisplay()
594 {
595 if (linearButton->isVisible())
596 {
597 linearButton->hide();
598 logButton->hide();
599 regularPaletteButton->hide();
600 prettyPaletteButton->hide();
601 greyScalePaletteButton->hide();
602 glowingPaletteButton->hide();
603 zeroRotationButton->hide();
604 minus90RotationButton->hide();
605 plus90Rotationbutton->hide();
606 scaleLabel->hide();
607 colorPaletteLabel->hide();
608 rotationLabel->hide();
609 }
610 else
611 {
612 linearButton->show();
613 logButton->show();
614 regularPaletteButton->show();
615 prettyPaletteButton->show();
616 greyScalePaletteButton->show();
617 glowingPaletteButton->show();
618 zeroRotationButton->show();
619 minus90RotationButton->show();
620 plus90Rotationbutton->show();
621 scaleLabel->show();
622 colorPaletteLabel->show();
623 rotationLabel->show();
624 }
625 }
626
627 void BasicGlCamera::mousePressEvent(QMouseEvent *cEvent)
628 {
629
630 }
631 void BasicGlCamera::mouseMoveEvent(QMouseEvent *cEvent)
632 {
633
634 }
635 void BasicGlCamera::mouseDoubleClickEvent(QMouseEvent *cEvent)
636 {
637
638 }
639 void BasicGlCamera::drawCamera(bool alsoWire)
640 {
641 cout << "Super PaintGL" << endl;
642 glColor3f(0.5,0.5,0.5);
643 glLineWidth(1.0);
644 float color;
645
646 for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
647 {
648 color = float(fData[i*fPixelStride+fcSlice]);// + ]eventData[nRoi*i + whichSlice]+(VALUES_SPAN/2))/(float)(VALUES_SPAN-1);
649 int index = 0;
650 while (ss[index] < color)
651 index++;
652 index--;
653 float weight0 = (color-ss[index]) / (ss[index+1]-ss[index]);
654 float weight1 = 1.0f-weight0;
655 pixelsColor[i][0] = weight1*rr[index] + weight0*rr[index+1];
656 pixelsColor[i][1] = weight1*gg[index] + weight0*gg[index+1];
657 pixelsColor[i][2] = weight1*bb[index] + weight0*bb[index+1];
658 }
659
660 for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
661 {
662 // if (i == 690 ||
663 // i == 70)
664 // continue;
665 glColor3fv(pixelsColor[i]);
666 glLoadName(i);
667
668 drawHexagon(i,true);
669
670 }
671 if (!alsoWire)
672 return;
673 glColor3f(0.0f,0.0f,0.0f);
674 for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
675 {
676// if (i == 690 ||
677// i == 70)
678// continue;
679 drawHexagon(i, false);
680 }
681 }
682 void BasicGlCamera::drawPatches()
683 {
684 glLineWidth(2.0f);
685 float backupRadius = hexRadius;
686 hexRadius *= 0.95;
687 glColor3f(0.5f, 0.5f, 0.3f);
688 glBegin(GL_LINES);
689 for (int i=0;i<NTMARK;i++)
690 {
691 for (unsigned int j=0;j<patchesIndices[i].size();j++)
692 {
693 glVertex2fv(verticesList[patchesIndices[i][j].first]);
694 glVertex2fv(verticesList[patchesIndices[i][j].second]);
695 }
696 }
697 glEnd();
698 hexRadius = backupRadius;
699 }
700 int BasicGlCamera::PixelAtPosition(const QPoint &cPos)
701 {
702 const int MaxSize = 512;
703 GLuint buffer[MaxSize];
704 GLint viewport[4];
705
706 makeCurrent();
707
708 glGetIntegerv(GL_VIEWPORT, viewport);
709 glSelectBuffer(MaxSize, buffer);
710 glRenderMode(GL_SELECT);
711
712 glInitNames();
713 glPushName(0);
714
715 glMatrixMode(GL_PROJECTION);
716 glPushMatrix();
717 glLoadIdentity();
718 GLfloat windowRatio = GLfloat(width()) / GLfloat(height());
719 gluPickMatrix(GLdouble(cPos.x()), GLdouble(viewport[3] - cPos.y()),
720 1.0, 1.0, viewport);
721
722 if (windowRatio < 1)
723 {
724 windowRatio = 1.0f/windowRatio;
725 gluOrtho2D(-viewSize, viewSize, -viewSize*windowRatio, viewSize*windowRatio);
726 }
727 else
728 {
729 gluOrtho2D(-viewSize*windowRatio, viewSize*windowRatio, -viewSize, viewSize);
730 }
731
732 glMatrixMode(GL_MODELVIEW);
733 drawCamera(false);
734 glMatrixMode(GL_PROJECTION);
735 glPopMatrix();
736
737 //for some reason that I cannot understand, the push/pop matrix doesn't do the trick here... bizarre
738 //ok, so re-do the resizeGL thing.
739 resizeGL(width(), height());
740
741 if (!glRenderMode(GL_RENDER))
742 return -1;
743
744 return buffer[3];
745 }
746 void BasicGlCamera::drawHexagon(int index, bool solid)
747 {
748 if (solid)
749 glBegin(GL_POLYGON);
750 else
751 glBegin(GL_LINE_LOOP);
752
753 glVertex2fv(verticesList[verticesIndices[index][0]]);
754 glVertex2fv(verticesList[verticesIndices[index][1]]);
755 glVertex2fv(verticesList[verticesIndices[index][2]]);
756 glVertex2fv(verticesList[verticesIndices[index][3]]);
757 glVertex2fv(verticesList[verticesIndices[index][4]]);
758 glVertex2fv(verticesList[verticesIndices[index][5]]);
759 if (solid)
760 glVertex2fv(verticesList[verticesIndices[index][0]]);
761
762 glEnd();
763 }
764
765 void BasicGlCamera::updateNeighbors(int currentPixel)
766 {
767 float squaredDistance = 0;
768 for (int i=0;i<currentPixel;i++)
769 {
770 squaredDistance = (pixelsCoords[i][0] - pixelsCoords[currentPixel][0])*
771 (pixelsCoords[i][0] - pixelsCoords[currentPixel][0]) +
772 (pixelsCoords[i][1] - pixelsCoords[currentPixel][1])*
773 (pixelsCoords[i][1] - pixelsCoords[currentPixel][1]);
774 if (squaredDistance < 4*hexRadius*hexRadius*(1.0f+hexTolerance))//neighbor !
775 {//ok, but which one ?
776 if (fabs(pixelsCoords[i][0] - pixelsCoords[currentPixel][0]) < hexTolerance &&
777 pixelsCoords[i][1] < pixelsCoords[currentPixel][1]){//top
778 neighbors[i][0] = currentPixel;
779 neighbors[currentPixel][3] = i;
780 continue;}
781 if (fabs(pixelsCoords[i][0] - pixelsCoords[currentPixel][0]) < hexTolerance &&
782 pixelsCoords[i][1] > pixelsCoords[currentPixel][1]){//bottom
783 neighbors[i][3] = currentPixel;
784 neighbors[currentPixel][0] = i;
785 continue;}
786 if (pixelsCoords[i][0] > pixelsCoords[currentPixel][0] &&
787 pixelsCoords[i][1] > pixelsCoords[currentPixel][1]){//top right
788 neighbors[i][4] = currentPixel;
789 neighbors[currentPixel][1] = i;
790 continue;}
791 if (pixelsCoords[i][0] > pixelsCoords[currentPixel][0] &&
792 pixelsCoords[i][1] < pixelsCoords[currentPixel][1]){//bottom right
793 neighbors[i][5] = currentPixel;
794 neighbors[currentPixel][2] = i;
795 continue;}
796 if (pixelsCoords[i][0] < pixelsCoords[currentPixel][0] &&
797 pixelsCoords[i][1] > pixelsCoords[currentPixel][1]){//top left
798 neighbors[i][2] = currentPixel;
799 neighbors[currentPixel][5] = i;
800 continue;}
801 if (pixelsCoords[i][0] < pixelsCoords[currentPixel][0] &&
802 pixelsCoords[i][1] < pixelsCoords[currentPixel][1]){//bottom left
803 neighbors[i][1] = currentPixel;
804 neighbors[currentPixel][4] = i;
805 continue;}
806 }
807 }
808 }
809 void BasicGlCamera::skipPixels(int start, int howMany)
810 {
811 for (int i=start;i<MAX_NUM_PIXELS-howMany;i++)
812 {
813 pixelsCoords[i][0] = pixelsCoords[i+howMany][0];
814 pixelsCoords[i][1] = pixelsCoords[i+howMany][1];
815 }
816 }
817 void BasicGlCamera::calculatePixelsCoords()
818 {
819 pixelsCoords[0][0] = 0;
820 pixelsCoords[0][1] = 0.3;
821 pixelsCoords[0][2] = 0;
822 pixelsCoords[1][0] = 0;
823 pixelsCoords[1][1] = 0.3+2*hexRadius;
824 pixelsCoords[1][2] = 0;
825 neighbors[0][0] = 1;
826 neighbors[1][3] = 0;
827 //from which side of the previous hexagon are we coming from ?
828 int fromSide = 3;
829 //to which side are we heading to ?
830 int toSide = 0;
831 for (int i=2;i<MAX_NUM_PIXELS;i++)
832 {
833 // cout << "i " << i << endl;
834 toSide = fromSide-1;
835 if (toSide < 0)
836 toSide =5;
837 while (neighbors[i-1][toSide] >= 0)
838 {
839 toSide--;
840 if (toSide < 0)
841 toSide = 5;
842 }
843 fromSide = toSide + 3;
844 if (fromSide > 5)
845 fromSide -= 6;
846 //ok. now we now in which direction we're heading
847 pixelsCoords[i][0] = pixelsCoords[i-1][0];
848 pixelsCoords[i][1] = pixelsCoords[i-1][1];
849 pixelsCoords[i][2] = pixelsCoords[i-1][2];
850 switch (toSide)
851 {
852 case 0:
853 pixelsCoords[i][1] += 2*hexRadius;
854 break;
855 case 1:
856 pixelsCoords[i][0] += (2*hexRadius)*sin(M_PI/3.0);
857 pixelsCoords[i][1] += (2*hexRadius)*cos(M_PI/3.0);
858 break;
859 case 2:
860 pixelsCoords[i][0] += (2*hexRadius)*sin(M_PI/3.0);
861 pixelsCoords[i][1] -= (2*hexRadius)*cos(M_PI/3.0);
862 break;
863 case 3:
864 pixelsCoords[i][1] -= 2*hexRadius;
865 break;
866 case 4:
867 pixelsCoords[i][0] -= (2*hexRadius)*sin(M_PI/3.0);
868 pixelsCoords[i][1] -= (2*hexRadius)*cos(M_PI/3.0);
869 break;
870 case 5:
871 pixelsCoords[i][0] -= (2*hexRadius)*sin(M_PI/3.0);
872 pixelsCoords[i][1] += (2*hexRadius)*cos(M_PI/3.0);
873 break;
874 };
875
876 updateNeighbors(i);
877 }
878 //Ok. So now we've circled around all the way to MAX_NUM_PIXELS
879 //do the required shifts so that it matches the fact camera up to ACTUAL_NUM_PIXELS pixels
880 skipPixels(1200, 1);
881 skipPixels(1218, 3);
882 skipPixels(1236, 1);
883 skipPixels(1256, 1);
884 skipPixels(1274, 3);
885 skipPixels(1292, 3);
886 skipPixels(1309, 6);
887 skipPixels(1323, 7);
888 skipPixels(1337, 6);
889 skipPixels(1354, 6);
890 skipPixels(1368, 7);
891 skipPixels(1382, 9);
892 skipPixels(1394, 12);
893 skipPixels(1402, 15);
894 skipPixels(1410, 12);
895 skipPixels(1422, 12);
896 skipPixels(1430, 15);
897 }
898 void BasicGlCamera::buildVerticesList()
899 {
900 numVertices = 0;
901 GLfloat cVertex[2];
902 for (int i=0;i<NPIX;i++)
903 {
904 for (int j=0;j<6;j++)
905 {
906 for (int k=0;k<2;k++)
907 cVertex[k] = hexcoords[j][k]*hexRadius + pixelsCoords[i][k];
908 bool found = false;
909 for (int k=0;k<numVertices;k++)
910 {
911 if ((cVertex[0] - verticesList[k][0])*
912 (cVertex[0] - verticesList[k][0]) +
913 (cVertex[1] - verticesList[k][1])*
914 (cVertex[1] - verticesList[k][1]) < hexTolerance*hexTolerance)
915 {
916 found = true;
917 break;
918 }
919 }
920 if (!found)
921 {
922 for (int k=0;k<2;k++)
923 verticesList[numVertices][k] = cVertex[k];
924 numVertices++;
925 }
926 }
927 }
928 for (int i=0;i<NPIX;i++)
929 {
930 for (int j=0;j<6;j++)
931 {
932 for (int k=0;k<2;k++)
933 cVertex[k] = hexcoords[j][k]*hexRadius + pixelsCoords[i][k];
934 for (int k=0;k<numVertices;k++)
935 {
936 if ((cVertex[0] - verticesList[k][0])*
937 (cVertex[0] - verticesList[k][0]) +
938 (cVertex[1] - verticesList[k][1])*
939 (cVertex[1] - verticesList[k][1]) < hexTolerance*hexTolerance)
940 {
941 verticesIndices[i][j] = k;
942 break;
943 }
944 }
945 }
946 }
947 }
948 void BasicGlCamera::buildPatchesIndices()
949 {
950 vector<edge>::iterator it;
951 bool erased = false;
952// patchesIndices.resize(NTMARK);
953 for (int i=0;i<NTMARK;i++)//for all patches
954 {
955 patchesIndices[i].clear();
956 for (int j=0;j<9;j++)//for all cells of the current patch
957 {
958 if (softwareMapping[patches[i][j]] >= ACTUAL_NUM_PIXELS)
959 continue;
960 for (int k=0;k<6;k++)//for all sides of the current cell
961 {
962 int first = k-1;
963 int second = k;
964 if (first < 0)
965 first = 5;
966 erased = false;
967 for (it=(patchesIndices[i]).begin(); it != (patchesIndices[i]).end(); it++)//check if this side is here already or not
968 {
969 if (((*it).first == verticesIndices[softwareMapping[patches[i][j]]][first] &&
970 (*it).second == verticesIndices[softwareMapping[patches[i][j]]][second]) ||
971 ((*it).first == verticesIndices[softwareMapping[patches[i][j]]][second] &&
972 (*it).second == verticesIndices[softwareMapping[patches[i][j]]][first]))
973 {
974 patchesIndices[i].erase(it);
975 erased = true;
976 break;
977 }
978 }
979 if (!erased)
980 {
981 edge temp;
982 temp.first = verticesIndices[softwareMapping[patches[i][j]]][first];
983 temp.second = verticesIndices[softwareMapping[patches[i][j]]][second];
984 patchesIndices[i].push_back(temp);
985 }
986 }
987 }
988 }
989// for (int i=0;i<NTMARK;i++)
990// {
991// cout << ".....................patch " << i << " size: " << patchesIndices[i].size() << endl;
992// for (unsigned int j=0;j<patchesIndices[i].size();j++)
993// {
994// if (patchesIndices[i][j].first < 0 || patchesIndices[i][j].first > 3013)
995// cout << patchesIndices[i][j].first << " and " << patchesIndices[i][j].second << " and " << j << endl;
996// }
997// }
998 }
999
Note: See TracBrowser for help on using the repository browser.