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