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