| 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 |
|
|---|
| 258 |
|
|---|
| 259 | }
|
|---|
| 260 | BasicGlCamera::~BasicGlCamera()
|
|---|
| 261 | {
|
|---|
| 262 | }
|
|---|
| 263 | void BasicGlCamera::setPatchColor(int id, float color[3])
|
|---|
| 264 | {
|
|---|
| 265 | for (int i=0;i<9;i++)
|
|---|
| 266 | for (int j=0;j<3;j++)
|
|---|
| 267 | pixelsColor[softwareMapping[patches[id][i]]][j] = color[j];
|
|---|
| 268 | }
|
|---|
| 269 | void BasicGlCamera::setUnits(const string& units)
|
|---|
| 270 | {
|
|---|
| 271 | unitsText = units;
|
|---|
| 272 | pixelColorUpToDate = false;
|
|---|
| 273 | if (isVisible() && autoRefresh)
|
|---|
| 274 | updateGL();
|
|---|
| 275 | }
|
|---|
| 276 | void BasicGlCamera::setTitle(const string& title)
|
|---|
| 277 | {
|
|---|
| 278 | titleText = title;
|
|---|
| 279 | pixelColorUpToDate = false;
|
|---|
| 280 | if (isVisible() && autoRefresh)
|
|---|
| 281 | updateGL();
|
|---|
| 282 | }
|
|---|
| 283 | void BasicGlCamera::SetWhite(int idx)
|
|---|
| 284 | {
|
|---|
| 285 | fWhite = idx;
|
|---|
| 286 | fWhitePatch = pixelsPatch[fWhite];
|
|---|
| 287 | if (isVisible() && autoRefresh)
|
|---|
| 288 | updateGL();
|
|---|
| 289 | // CalculatePatchColor();
|
|---|
| 290 | }
|
|---|
| 291 | void BasicGlCamera::SetMin(int64_t min)
|
|---|
| 292 | {
|
|---|
| 293 | // cout << "min: " << min << endl;
|
|---|
| 294 | fMin = min;
|
|---|
| 295 | pixelColorUpToDate = false;
|
|---|
| 296 | if (isVisible() && autoRefresh)
|
|---|
| 297 | updateGL();
|
|---|
| 298 | }
|
|---|
| 299 | void BasicGlCamera::SetMax(int64_t max)
|
|---|
| 300 | {
|
|---|
| 301 | // cout << "max: " << max << endl;
|
|---|
| 302 | fMax = max;
|
|---|
| 303 | pixelColorUpToDate = false;
|
|---|
| 304 | if (isVisible() && autoRefresh)
|
|---|
| 305 | updateGL();
|
|---|
| 306 | }
|
|---|
| 307 | void BasicGlCamera::linearScalePlease(bool checked)
|
|---|
| 308 | {
|
|---|
| 309 | if (!checked) return;
|
|---|
| 310 | logScale = false;
|
|---|
| 311 | pixelColorUpToDate = false;
|
|---|
| 312 | emit colorPaletteHasChanged();
|
|---|
| 313 | if (isVisible() && autoRefresh)
|
|---|
| 314 | updateGL();
|
|---|
| 315 | }
|
|---|
| 316 | void BasicGlCamera::UpdateText()
|
|---|
| 317 | {
|
|---|
| 318 | ostringstream str;
|
|---|
| 319 | float min, max, mean, rms, median;
|
|---|
| 320 | min = max = fData[0];
|
|---|
| 321 | mean = 0;
|
|---|
| 322 | rms = 0;
|
|---|
| 323 | median = 0;
|
|---|
| 324 | multiset<double> medianSet;
|
|---|
| 325 | for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
|
|---|
| 326 | {
|
|---|
| 327 | if (fData[i] < min)
|
|---|
| 328 | min = fData[i];
|
|---|
| 329 | if (fData[i] > max)
|
|---|
| 330 | max = fData[i];
|
|---|
| 331 | mean += fData[i];
|
|---|
| 332 | rms += fData[i]*fData[i];
|
|---|
| 333 | medianSet.insert(fData[i]);
|
|---|
| 334 | }
|
|---|
| 335 | mean /= ACTUAL_NUM_PIXELS;
|
|---|
| 336 | rms /= ACTUAL_NUM_PIXELS;
|
|---|
| 337 | rms = sqrt(rms);
|
|---|
| 338 | // cout << "Size of the set: " << medianSet.size() << endl;
|
|---|
| 339 | multiset<double>::iterator it = medianSet.begin();
|
|---|
| 340 | for (int i=0;i<(ACTUAL_NUM_PIXELS/2)-1;i++)
|
|---|
| 341 | it++;
|
|---|
| 342 | median = *it;
|
|---|
| 343 | it++;
|
|---|
| 344 | median += *it;
|
|---|
| 345 | median /= 2;
|
|---|
| 346 |
|
|---|
| 347 | str << "Min: " << min << " Max: " << max << " Mean: " << mean << " RMS: " << rms << " Median: " << median;
|
|---|
| 348 | str << " Units: " << unitsText;
|
|---|
| 349 | dataText = str.str();
|
|---|
| 350 | }
|
|---|
| 351 | void BasicGlCamera::DrawCameraText()
|
|---|
| 352 | {
|
|---|
| 353 | glPushMatrix();
|
|---|
| 354 | glLoadIdentity();
|
|---|
| 355 | // cout << width() << " " << height() << endl;
|
|---|
| 356 | int textSize = (int)(height()*14/600);
|
|---|
| 357 | setFont(QFont("Times", textSize));
|
|---|
| 358 | qglColor(QColor(255,223,127));
|
|---|
| 359 | float shiftx = 0.01f;//0.55f;
|
|---|
| 360 | float shifty = 0.01f;//0.65f;
|
|---|
| 361 | renderText(-shownSizex/2.f + shiftx, -shownSizey/2.f + shifty, 0.f, QString(dataText.c_str()));
|
|---|
| 362 |
|
|---|
| 363 |
|
|---|
| 364 | // int textLength = titleText.size();
|
|---|
| 365 | renderText(-shownSizex/2.f + shiftx, shownSizey/2.f - textSize*pixelSize - shifty, 0.f, QString(titleText.c_str()));
|
|---|
| 366 |
|
|---|
| 367 | glPopMatrix();
|
|---|
| 368 |
|
|---|
| 369 | textSize = (int)(600*14/600);
|
|---|
| 370 | setFont(QFont("Times", textSize));
|
|---|
| 371 | }
|
|---|
| 372 | void BasicGlCamera::DrawScale()
|
|---|
| 373 | {
|
|---|
| 374 | glPushMatrix();
|
|---|
| 375 | glLoadIdentity();
|
|---|
| 376 | glPushAttrib(GL_POLYGON_BIT);
|
|---|
| 377 | glShadeModel(GL_SMOOTH);
|
|---|
| 378 | glBegin(GL_QUADS);
|
|---|
| 379 | float oneX = shownSizex/2.f - shownSizex/50.f;
|
|---|
| 380 | float twoX = shownSizex/2.f;
|
|---|
| 381 | float oneY = -shownSizey/2.f;
|
|---|
| 382 | float twoY = -shownSizey/4.f;
|
|---|
| 383 | float threeY = 0;
|
|---|
| 384 | float fourY = shownSizey/4.f;
|
|---|
| 385 | float fiveY = shownSizey/2.f;
|
|---|
| 386 | glColor3f(rr[0], gg[0], bb[0]);
|
|---|
| 387 | glVertex2f(oneX, oneY);
|
|---|
| 388 | glVertex2f(twoX, oneY);
|
|---|
| 389 | glColor3f(rr[1], gg[1], bb[1]);
|
|---|
| 390 | glVertex2f(twoX, twoY);
|
|---|
| 391 | glVertex2f(oneX, twoY);
|
|---|
| 392 |
|
|---|
| 393 | glVertex2f(oneX, twoY);
|
|---|
| 394 | glVertex2f(twoX, twoY);
|
|---|
| 395 | glColor3f(rr[2], gg[2], bb[2]);
|
|---|
| 396 | glVertex2f(twoX, threeY);
|
|---|
| 397 | glVertex2f(oneX, threeY);
|
|---|
| 398 |
|
|---|
| 399 | glVertex2f(oneX, threeY);
|
|---|
| 400 | glVertex2f(twoX, threeY);
|
|---|
| 401 | glColor3f(rr[3], gg[3], bb[3]);
|
|---|
| 402 | glVertex2f(twoX, fourY);
|
|---|
| 403 | glVertex2f(oneX, fourY);
|
|---|
| 404 |
|
|---|
| 405 | glVertex2f(oneX, fourY);
|
|---|
| 406 | glVertex2f(twoX, fourY);
|
|---|
| 407 | glColor3f(rr[4], gg[4], bb[4]);
|
|---|
| 408 | glVertex2f(twoX, fiveY);
|
|---|
| 409 | glVertex2f(oneX, fiveY);
|
|---|
| 410 | float zeroX = oneX - shownSizex/50.f;
|
|---|
| 411 | float zeroY = fiveY - shownSizey/50.f;
|
|---|
| 412 | glColor3fv(tooHighValueCoulour);
|
|---|
| 413 | glVertex2f(zeroX, fiveY);
|
|---|
| 414 | glVertex2f(oneX, fiveY);
|
|---|
| 415 | glVertex2f(oneX, zeroY);
|
|---|
| 416 | glVertex2f(zeroX, zeroY);
|
|---|
| 417 | glColor3fv(tooLowValueCoulour);
|
|---|
| 418 | glVertex2f(zeroX, -fiveY);
|
|---|
| 419 | glVertex2f(oneX, -fiveY);
|
|---|
| 420 | glVertex2f(oneX, -zeroY);
|
|---|
| 421 | glVertex2f(zeroX, -zeroY);
|
|---|
| 422 | glEnd();
|
|---|
| 423 | //draw linear/log tick marks
|
|---|
| 424 | glColor3f(0.f,0.f,0.f);
|
|---|
| 425 | glBegin(GL_LINES);
|
|---|
| 426 | float value;
|
|---|
| 427 | for (int i=1;i<10;i++)
|
|---|
| 428 | {
|
|---|
| 429 | if (logScale)
|
|---|
| 430 | value = log10(i);
|
|---|
| 431 | else
|
|---|
| 432 | value = (float)(i)/10.f;
|
|---|
| 433 | float yy = -shownSizey/2.f + value*shownSizey;
|
|---|
| 434 | glVertex2f(oneX, yy);
|
|---|
| 435 | glVertex2f(twoX, yy);
|
|---|
| 436 | }
|
|---|
| 437 | glEnd();
|
|---|
| 438 | glPopAttrib();
|
|---|
| 439 | glPopMatrix();
|
|---|
| 440 | }
|
|---|
| 441 | void BasicGlCamera::logScalePlease(bool checked)
|
|---|
| 442 | {
|
|---|
| 443 | if (!checked) return;
|
|---|
| 444 | logScale = true;
|
|---|
| 445 | pixelColorUpToDate = false;
|
|---|
| 446 | emit colorPaletteHasChanged();
|
|---|
| 447 | if (isVisible() && autoRefresh)
|
|---|
| 448 | updateGL();
|
|---|
| 449 | }
|
|---|
| 450 | void BasicGlCamera::regularPalettePlease(bool checked)
|
|---|
| 451 | {
|
|---|
| 452 | if (!checked) return;
|
|---|
| 453 | ss[0] = 0; ss[1] = 0.25f; ss[2] = 0.5f; ss[3] = 0.75f; ss[4] = 1.0f;
|
|---|
| 454 | rr[0] = 0.15; rr[1] = 0; rr[2] = 0; rr[3] = 1.0f; rr[4] = 0.85f;
|
|---|
| 455 | gg[0] = 0.15; gg[1] = 0; gg[2] = 1; gg[3] = 0; gg[4] = 0.85f;
|
|---|
| 456 | bb[0] = 0.15; bb[1] = 1; bb[2] = 0; bb[3] = 0; bb[4] = 0.85f;
|
|---|
| 457 | tooHighValueCoulour[0] = 1.f;
|
|---|
| 458 | tooHighValueCoulour[1] = 1.f;
|
|---|
| 459 | tooHighValueCoulour[2] = 0.f;
|
|---|
| 460 | tooLowValueCoulour[0] = 0.f;
|
|---|
| 461 | tooLowValueCoulour[1] = 1.f;
|
|---|
| 462 | tooLowValueCoulour[2] = 1.f;
|
|---|
| 463 | pixelColorUpToDate = false;
|
|---|
| 464 |
|
|---|
| 465 | emit colorPaletteHasChanged();
|
|---|
| 466 |
|
|---|
| 467 | if (isVisible() && autoRefresh)
|
|---|
| 468 | updateGL();
|
|---|
| 469 | }
|
|---|
| 470 | void BasicGlCamera::prettyPalettePlease(bool checked)
|
|---|
| 471 | {
|
|---|
| 472 | if (!checked) return;
|
|---|
| 473 | ss[0] = 0.f; ss[1] = 0.25f; ss[2] = 0.5f; ss[3] = 0.75f; ss[4] = 1.0f;
|
|---|
| 474 | rr[0] = 0.f; rr[1] = 0.35f; rr[2] = 0.85f; rr[3] = 1.0f; rr[4] = 1.f;
|
|---|
| 475 | gg[0] = 0.f; gg[1] = 0.10f; gg[2] = 0.20f; gg[3] = 0.73f; gg[4] = 1.f;
|
|---|
| 476 | bb[0] = 0.f; bb[1] = 0.03f; bb[2] = 0.06f; bb[3] = 0.00f; bb[4] = 1.f;
|
|---|
| 477 | tooHighValueCoulour[0] = 0.f;
|
|---|
| 478 | tooHighValueCoulour[1] = 1.f;
|
|---|
| 479 | tooHighValueCoulour[2] = 0.f;
|
|---|
| 480 | tooLowValueCoulour[0] = 0.f;
|
|---|
| 481 | tooLowValueCoulour[1] = 0.f;
|
|---|
| 482 | tooLowValueCoulour[2] = 1.f;
|
|---|
| 483 | pixelColorUpToDate = false;
|
|---|
| 484 |
|
|---|
| 485 | emit colorPaletteHasChanged();
|
|---|
| 486 |
|
|---|
| 487 | if (isVisible() && autoRefresh)
|
|---|
| 488 | updateGL();
|
|---|
| 489 | }
|
|---|
| 490 | void BasicGlCamera::greyScalePalettePlease(bool checked)
|
|---|
| 491 | {
|
|---|
| 492 | if (!checked) return;
|
|---|
| 493 | ss[0] = 0; ss[1] = 0.25f; ss[2] = 0.5f; ss[3] = 0.75f; ss[4] = 1.0f;
|
|---|
| 494 | rr[0] = 0; rr[1] = 0.25f; rr[2] = 0.5f; rr[3] = 0.75f; rr[4] = 1.0f;
|
|---|
| 495 | gg[0] = 0; gg[1] = 0.25f; gg[2] = 0.5f; gg[3] = 0.75f; gg[4] = 1.0f;
|
|---|
| 496 | bb[0] = 0; bb[1] = 0.25f; bb[2] = 0.5f; bb[3] = 0.75f; bb[4] = 1.0f;
|
|---|
| 497 | tooHighValueCoulour[0] = 0.f;
|
|---|
| 498 | tooHighValueCoulour[1] = 1.f;
|
|---|
| 499 | tooHighValueCoulour[2] = 0.f;
|
|---|
| 500 | tooLowValueCoulour[0] = 0.f;
|
|---|
| 501 | tooLowValueCoulour[1] = 0.f;
|
|---|
| 502 | tooLowValueCoulour[2] = 1.f;
|
|---|
| 503 | pixelColorUpToDate = false;
|
|---|
| 504 |
|
|---|
| 505 | emit colorPaletteHasChanged();
|
|---|
| 506 |
|
|---|
| 507 | if (isVisible() && autoRefresh)
|
|---|
| 508 | updateGL();
|
|---|
| 509 | }
|
|---|
| 510 | void BasicGlCamera::glowingPalettePlease(bool checked)
|
|---|
| 511 | {
|
|---|
| 512 | if (!checked) return;
|
|---|
| 513 | ss[0] = 0; ss[1] = 0.25f; ss[2] = 0.5f; ss[3] = 0.75f; ss[4] = 1.0f;
|
|---|
| 514 | rr[0] = 0.15; rr[1] = 0.5; rr[2] = 1.f; rr[3] = 0.0f; rr[4] = 1.f;
|
|---|
| 515 | gg[0] = 0.15; gg[1] = 0.5; gg[2] = 1.f; gg[3] = 0.5f; gg[4] = 0.5f;
|
|---|
| 516 | bb[0] = 0.15; bb[1] = 0.5; bb[2] = 1; bb[3] = 1.f; bb[4] = 0.f;
|
|---|
| 517 | tooHighValueCoulour[0] = 1.f;
|
|---|
| 518 | tooHighValueCoulour[1] = 0.f;
|
|---|
| 519 | tooHighValueCoulour[2] = 0.f;
|
|---|
| 520 | tooLowValueCoulour[0] = 0.f;
|
|---|
| 521 | tooLowValueCoulour[1] = 1.f;
|
|---|
| 522 | tooLowValueCoulour[2] = 0.f;
|
|---|
| 523 | pixelColorUpToDate = false;
|
|---|
| 524 |
|
|---|
| 525 | emit colorPaletteHasChanged();
|
|---|
| 526 |
|
|---|
| 527 | if (isVisible() && autoRefresh)
|
|---|
| 528 | updateGL();
|
|---|
| 529 | }
|
|---|
| 530 | void BasicGlCamera::SetAutoRefresh(bool on)
|
|---|
| 531 | {
|
|---|
| 532 | autoRefresh = on;
|
|---|
| 533 | if (isVisible() && autoRefresh)
|
|---|
| 534 | updateGL();
|
|---|
| 535 | }
|
|---|
| 536 | void BasicGlCamera::zeroRotationPlease(bool checked)
|
|---|
| 537 | {
|
|---|
| 538 | if (!checked) return;
|
|---|
| 539 | cameraRotation = 0;
|
|---|
| 540 | pixelColorUpToDate = false;
|
|---|
| 541 | if (isVisible() && autoRefresh)
|
|---|
| 542 | updateGL();
|
|---|
| 543 | }
|
|---|
| 544 | void BasicGlCamera::plus90RotationPlease(bool checked)
|
|---|
| 545 | {
|
|---|
| 546 | if (!checked) return;
|
|---|
| 547 | cameraRotation = 90;
|
|---|
| 548 | pixelColorUpToDate = false;
|
|---|
| 549 | if (isVisible() && autoRefresh)
|
|---|
| 550 | updateGL();
|
|---|
| 551 | }
|
|---|
| 552 | void BasicGlCamera::minus90RotationPlease(bool checked)
|
|---|
| 553 | {
|
|---|
| 554 | if (!checked) return;
|
|---|
| 555 | cameraRotation = -90;
|
|---|
| 556 | pixelColorUpToDate = false;
|
|---|
| 557 | if (isVisible() && autoRefresh)
|
|---|
| 558 | updateGL();
|
|---|
| 559 | }
|
|---|
| 560 |
|
|---|
| 561 | void BasicGlCamera::initializeGL()
|
|---|
| 562 | {
|
|---|
| 563 | qglClearColor(QColor(25,25,38));
|
|---|
| 564 | glShadeModel(GL_FLAT);
|
|---|
| 565 | glDisable(GL_DEPTH_TEST);
|
|---|
| 566 | glDisable(GL_CULL_FACE);
|
|---|
| 567 |
|
|---|
| 568 | glEnable (GL_LINE_SMOOTH);
|
|---|
| 569 | glEnable (GL_BLEND);
|
|---|
| 570 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|---|
| 571 | glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
|
|---|
| 572 |
|
|---|
| 573 | }
|
|---|
| 574 | void BasicGlCamera::resizeGL(int cWidth, int cHeight)
|
|---|
| 575 | {
|
|---|
| 576 | glViewport(0, 0, cWidth, cHeight);
|
|---|
| 577 | glMatrixMode(GL_PROJECTION);
|
|---|
| 578 | glLoadIdentity();
|
|---|
| 579 | GLfloat windowRatio = (float)cWidth/(float)cHeight;
|
|---|
| 580 | if (windowRatio < 1)
|
|---|
| 581 | {
|
|---|
| 582 | windowRatio = 1.0f/windowRatio;
|
|---|
| 583 | gluOrtho2D(-viewSize, viewSize, -viewSize*windowRatio, viewSize*windowRatio);
|
|---|
| 584 | pixelSize = 2*viewSize/(float)cWidth;
|
|---|
| 585 | shownSizex = 2*viewSize;
|
|---|
| 586 | shownSizey = 2*viewSize*windowRatio;
|
|---|
| 587 | }
|
|---|
| 588 | else
|
|---|
| 589 | {
|
|---|
| 590 | gluOrtho2D(-viewSize*windowRatio, viewSize*windowRatio, -viewSize, viewSize);
|
|---|
| 591 | pixelSize = 2*viewSize/(float)cHeight;
|
|---|
| 592 | shownSizex = 2*viewSize*windowRatio;
|
|---|
| 593 | shownSizey = 2*viewSize;
|
|---|
| 594 | }
|
|---|
| 595 | glMatrixMode(GL_MODELVIEW);
|
|---|
| 596 | }
|
|---|
| 597 | void BasicGlCamera::paintGL()
|
|---|
| 598 | {
|
|---|
| 599 | glClear(GL_COLOR_BUFFER_BIT);
|
|---|
| 600 | glLoadIdentity();
|
|---|
| 601 |
|
|---|
| 602 | glTranslatef(0,-0.44,0);
|
|---|
| 603 | glScalef(1.5, 1.5, 1.5);
|
|---|
| 604 |
|
|---|
| 605 | drawCamera(true);
|
|---|
| 606 |
|
|---|
| 607 | drawPatches();
|
|---|
| 608 | }
|
|---|
| 609 | void BasicGlCamera::toggleInterfaceDisplay()
|
|---|
| 610 | {
|
|---|
| 611 | if (linearButton->isVisible())
|
|---|
| 612 | {
|
|---|
| 613 | linearButton->hide();
|
|---|
| 614 | logButton->hide();
|
|---|
| 615 | regularPaletteButton->hide();
|
|---|
| 616 | prettyPaletteButton->hide();
|
|---|
| 617 | greyScalePaletteButton->hide();
|
|---|
| 618 | glowingPaletteButton->hide();
|
|---|
| 619 | zeroRotationButton->hide();
|
|---|
| 620 | minus90RotationButton->hide();
|
|---|
| 621 | plus90Rotationbutton->hide();
|
|---|
| 622 | scaleLabel->hide();
|
|---|
| 623 | colorPaletteLabel->hide();
|
|---|
| 624 | rotationLabel->hide();
|
|---|
| 625 | }
|
|---|
| 626 | else
|
|---|
| 627 | {
|
|---|
| 628 | linearButton->show();
|
|---|
| 629 | logButton->show();
|
|---|
| 630 | regularPaletteButton->show();
|
|---|
| 631 | prettyPaletteButton->show();
|
|---|
| 632 | greyScalePaletteButton->show();
|
|---|
| 633 | glowingPaletteButton->show();
|
|---|
| 634 | zeroRotationButton->show();
|
|---|
| 635 | minus90RotationButton->show();
|
|---|
| 636 | plus90Rotationbutton->show();
|
|---|
| 637 | scaleLabel->show();
|
|---|
| 638 | colorPaletteLabel->show();
|
|---|
| 639 | rotationLabel->show();
|
|---|
| 640 | }
|
|---|
| 641 | }
|
|---|
| 642 |
|
|---|
| 643 | void BasicGlCamera::mousePressEvent(QMouseEvent *)
|
|---|
| 644 | {
|
|---|
| 645 |
|
|---|
| 646 | }
|
|---|
| 647 | void BasicGlCamera::mouseMoveEvent(QMouseEvent *)
|
|---|
| 648 | {
|
|---|
| 649 |
|
|---|
| 650 | }
|
|---|
| 651 | void BasicGlCamera::mouseDoubleClickEvent(QMouseEvent *)
|
|---|
| 652 | {
|
|---|
| 653 |
|
|---|
| 654 | }
|
|---|
| 655 | void BasicGlCamera::drawCamera(bool alsoWire)
|
|---|
| 656 | {
|
|---|
| 657 | // cout << "Super PaintGL" << endl;
|
|---|
| 658 | glColor3f(0.5,0.5,0.5);
|
|---|
| 659 | glLineWidth(1.0);
|
|---|
| 660 | float color;
|
|---|
| 661 |
|
|---|
| 662 | for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
|
|---|
| 663 | {
|
|---|
| 664 | color = float(fData[i*fPixelStride+fcSlice]);// + ]eventData[nRoi*i + whichSlice]+(VALUES_SPAN/2))/(float)(VALUES_SPAN-1);
|
|---|
| 665 | int index = 0;
|
|---|
| 666 | while (ss[index] < color)
|
|---|
| 667 | index++;
|
|---|
| 668 | index--;
|
|---|
| 669 | float weight0 = (color-ss[index]) / (ss[index+1]-ss[index]);
|
|---|
| 670 | float weight1 = 1.0f-weight0;
|
|---|
| 671 | pixelsColor[i][0] = weight1*rr[index] + weight0*rr[index+1];
|
|---|
| 672 | pixelsColor[i][1] = weight1*gg[index] + weight0*gg[index+1];
|
|---|
| 673 | pixelsColor[i][2] = weight1*bb[index] + weight0*bb[index+1];
|
|---|
| 674 | }
|
|---|
| 675 |
|
|---|
| 676 | for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
|
|---|
| 677 | {
|
|---|
| 678 | // if (i == 690 ||
|
|---|
| 679 | // i == 70)
|
|---|
| 680 | // continue;
|
|---|
| 681 | glColor3fv(pixelsColor[i]);
|
|---|
| 682 | glLoadName(i);
|
|---|
| 683 |
|
|---|
| 684 | drawHexagon(i,true);
|
|---|
| 685 |
|
|---|
| 686 | }
|
|---|
| 687 | if (!alsoWire)
|
|---|
| 688 | return;
|
|---|
| 689 | glColor3f(0.0f,0.0f,0.0f);
|
|---|
| 690 | for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
|
|---|
| 691 | {
|
|---|
| 692 | // if (i == 690 ||
|
|---|
| 693 | // i == 70)
|
|---|
| 694 | // continue;
|
|---|
| 695 | drawHexagon(i, false);
|
|---|
| 696 | }
|
|---|
| 697 | }
|
|---|
| 698 | void BasicGlCamera::drawPatches()
|
|---|
| 699 | {
|
|---|
| 700 | glLineWidth(2.0f);
|
|---|
| 701 | float backupRadius = hexRadius;
|
|---|
| 702 | hexRadius *= 0.95;
|
|---|
| 703 | glColor3f(0.5f, 0.5f, 0.3f);
|
|---|
| 704 | glBegin(GL_LINES);
|
|---|
| 705 | for (int i=0;i<NTMARK;i++)
|
|---|
| 706 | {
|
|---|
| 707 | for (unsigned int j=0;j<patchesIndices[i].size();j++)
|
|---|
| 708 | {
|
|---|
| 709 | glVertex2fv(verticesList[patchesIndices[i][j].first]);
|
|---|
| 710 | glVertex2fv(verticesList[patchesIndices[i][j].second]);
|
|---|
| 711 | }
|
|---|
| 712 | }
|
|---|
| 713 | glEnd();
|
|---|
| 714 | hexRadius = backupRadius;
|
|---|
| 715 | }
|
|---|
| 716 | int BasicGlCamera::PixelAtPosition(const QPoint &cPos)
|
|---|
| 717 | {
|
|---|
| 718 | const int MaxSize = 512;
|
|---|
| 719 | GLuint buffer[MaxSize];
|
|---|
| 720 | GLint viewport[4];
|
|---|
| 721 |
|
|---|
| 722 | makeCurrent();
|
|---|
| 723 |
|
|---|
| 724 | glGetIntegerv(GL_VIEWPORT, viewport);
|
|---|
| 725 | glSelectBuffer(MaxSize, buffer);
|
|---|
| 726 | glRenderMode(GL_SELECT);
|
|---|
| 727 |
|
|---|
| 728 | glInitNames();
|
|---|
| 729 | glPushName(0);
|
|---|
| 730 |
|
|---|
| 731 | glMatrixMode(GL_PROJECTION);
|
|---|
| 732 | glPushMatrix();
|
|---|
| 733 | glLoadIdentity();
|
|---|
| 734 | GLfloat windowRatio = GLfloat(width()) / GLfloat(height());
|
|---|
| 735 | gluPickMatrix(GLdouble(cPos.x()), GLdouble(viewport[3] - cPos.y()),
|
|---|
| 736 | 1.0, 1.0, viewport);
|
|---|
| 737 |
|
|---|
| 738 | if (windowRatio < 1)
|
|---|
| 739 | {
|
|---|
| 740 | windowRatio = 1.0f/windowRatio;
|
|---|
| 741 | gluOrtho2D(-viewSize, viewSize, -viewSize*windowRatio, viewSize*windowRatio);
|
|---|
| 742 | }
|
|---|
| 743 | else
|
|---|
| 744 | {
|
|---|
| 745 | gluOrtho2D(-viewSize*windowRatio, viewSize*windowRatio, -viewSize, viewSize);
|
|---|
| 746 | }
|
|---|
| 747 |
|
|---|
| 748 | glMatrixMode(GL_MODELVIEW);
|
|---|
| 749 | drawCamera(false);
|
|---|
| 750 | glMatrixMode(GL_PROJECTION);
|
|---|
| 751 | glPopMatrix();
|
|---|
| 752 |
|
|---|
| 753 | //for some reason that I cannot understand, the push/pop matrix doesn't do the trick here... bizarre
|
|---|
| 754 | //ok, so re-do the resizeGL thing.
|
|---|
| 755 | resizeGL(width(), height());
|
|---|
| 756 |
|
|---|
| 757 | if (!glRenderMode(GL_RENDER))
|
|---|
| 758 | return -1;
|
|---|
| 759 |
|
|---|
| 760 | return buffer[3];
|
|---|
| 761 | }
|
|---|
| 762 | void BasicGlCamera::drawHexagon(int index, bool solid)
|
|---|
| 763 | {
|
|---|
| 764 | /* float minX, maxX, minY, maxY;
|
|---|
| 765 | minX = minY = 1e10;
|
|---|
| 766 | maxX = maxY = -1e10;
|
|---|
| 767 | for (int i=0;i<1438;i++)
|
|---|
| 768 | {
|
|---|
| 769 | for (int j=0;j<6;j++)
|
|---|
| 770 | {
|
|---|
| 771 | if (verticesList[verticesIndices[i][j]][0] > maxX)
|
|---|
| 772 | maxX = verticesList[verticesIndices[i][j]][0];
|
|---|
| 773 | if (verticesList[verticesIndices[i][j]][0] < minX)
|
|---|
| 774 | minX = verticesList[verticesIndices[i][j]][0];
|
|---|
| 775 | if (verticesList[verticesIndices[i][j]][1] > maxY)
|
|---|
| 776 | maxY = verticesList[verticesIndices[i][j]][1];
|
|---|
| 777 | if (verticesList[verticesIndices[i][j]][1] < minY)
|
|---|
| 778 | minY = verticesList[verticesIndices[i][j]][1];
|
|---|
| 779 | }
|
|---|
| 780 | }
|
|---|
| 781 | cout << "Min, Max X: " << minX << " " << maxX << endl;
|
|---|
| 782 | cout << "Min, Max Y: " << minY << " " << maxY << endl;
|
|---|
| 783 | exit(0);*/
|
|---|
| 784 | if (solid)
|
|---|
| 785 | glBegin(GL_POLYGON);
|
|---|
| 786 | else
|
|---|
| 787 | glBegin(GL_LINE_LOOP);
|
|---|
| 788 |
|
|---|
| 789 | glVertex2fv(verticesList[verticesIndices[index][0]]);
|
|---|
| 790 | glVertex2fv(verticesList[verticesIndices[index][1]]);
|
|---|
| 791 | glVertex2fv(verticesList[verticesIndices[index][2]]);
|
|---|
| 792 | glVertex2fv(verticesList[verticesIndices[index][3]]);
|
|---|
| 793 | glVertex2fv(verticesList[verticesIndices[index][4]]);
|
|---|
| 794 | glVertex2fv(verticesList[verticesIndices[index][5]]);
|
|---|
| 795 | if (solid)
|
|---|
| 796 | glVertex2fv(verticesList[verticesIndices[index][0]]);
|
|---|
| 797 |
|
|---|
| 798 | glEnd();
|
|---|
| 799 | }
|
|---|
| 800 |
|
|---|
| 801 | void BasicGlCamera::updateNeighbors(int currentPixel)
|
|---|
| 802 | {
|
|---|
| 803 | float squaredDistance = 0;
|
|---|
| 804 | for (int i=0;i<currentPixel;i++)
|
|---|
| 805 | {
|
|---|
| 806 | squaredDistance = (pixelsCoords[i][0] - pixelsCoords[currentPixel][0])*
|
|---|
| 807 | (pixelsCoords[i][0] - pixelsCoords[currentPixel][0]) +
|
|---|
| 808 | (pixelsCoords[i][1] - pixelsCoords[currentPixel][1])*
|
|---|
| 809 | (pixelsCoords[i][1] - pixelsCoords[currentPixel][1]);
|
|---|
| 810 | if (squaredDistance < 4*hexRadius*hexRadius*(1.0f+hexTolerance))//neighbor !
|
|---|
| 811 | {//ok, but which one ?
|
|---|
| 812 | if (fabs(pixelsCoords[i][0] - pixelsCoords[currentPixel][0]) < hexTolerance &&
|
|---|
| 813 | pixelsCoords[i][1] < pixelsCoords[currentPixel][1]){//top
|
|---|
| 814 | neighbors[i][0] = currentPixel;
|
|---|
| 815 | neighbors[currentPixel][3] = i;
|
|---|
| 816 | continue;}
|
|---|
| 817 | if (fabs(pixelsCoords[i][0] - pixelsCoords[currentPixel][0]) < hexTolerance &&
|
|---|
| 818 | pixelsCoords[i][1] > pixelsCoords[currentPixel][1]){//bottom
|
|---|
| 819 | neighbors[i][3] = currentPixel;
|
|---|
| 820 | neighbors[currentPixel][0] = i;
|
|---|
| 821 | continue;}
|
|---|
| 822 | if (pixelsCoords[i][0] > pixelsCoords[currentPixel][0] &&
|
|---|
| 823 | pixelsCoords[i][1] > pixelsCoords[currentPixel][1]){//top right
|
|---|
| 824 | neighbors[i][4] = currentPixel;
|
|---|
| 825 | neighbors[currentPixel][1] = i;
|
|---|
| 826 | continue;}
|
|---|
| 827 | if (pixelsCoords[i][0] > pixelsCoords[currentPixel][0] &&
|
|---|
| 828 | pixelsCoords[i][1] < pixelsCoords[currentPixel][1]){//bottom right
|
|---|
| 829 | neighbors[i][5] = currentPixel;
|
|---|
| 830 | neighbors[currentPixel][2] = i;
|
|---|
| 831 | continue;}
|
|---|
| 832 | if (pixelsCoords[i][0] < pixelsCoords[currentPixel][0] &&
|
|---|
| 833 | pixelsCoords[i][1] > pixelsCoords[currentPixel][1]){//top left
|
|---|
| 834 | neighbors[i][2] = currentPixel;
|
|---|
| 835 | neighbors[currentPixel][5] = i;
|
|---|
| 836 | continue;}
|
|---|
| 837 | if (pixelsCoords[i][0] < pixelsCoords[currentPixel][0] &&
|
|---|
| 838 | pixelsCoords[i][1] < pixelsCoords[currentPixel][1]){//bottom left
|
|---|
| 839 | neighbors[i][1] = currentPixel;
|
|---|
| 840 | neighbors[currentPixel][4] = i;
|
|---|
| 841 | continue;}
|
|---|
| 842 | }
|
|---|
| 843 | }
|
|---|
| 844 | }
|
|---|
| 845 | void BasicGlCamera::skipPixels(int start, int howMany)
|
|---|
| 846 | {
|
|---|
| 847 | for (int i=start;i<MAX_NUM_PIXELS-howMany;i++)
|
|---|
| 848 | {
|
|---|
| 849 | pixelsCoords[i][0] = pixelsCoords[i+howMany][0];
|
|---|
| 850 | pixelsCoords[i][1] = pixelsCoords[i+howMany][1];
|
|---|
| 851 | }
|
|---|
| 852 | }
|
|---|
| 853 | void BasicGlCamera::calculatePixelsCoords()
|
|---|
| 854 | {
|
|---|
| 855 | pixelsCoords[0][0] = 0;
|
|---|
| 856 | pixelsCoords[0][1] = 0.3;
|
|---|
| 857 | pixelsCoords[0][2] = 0;
|
|---|
| 858 | pixelsCoords[1][0] = 0;
|
|---|
| 859 | pixelsCoords[1][1] = 0.3+2*hexRadius;
|
|---|
| 860 | pixelsCoords[1][2] = 0;
|
|---|
| 861 | neighbors[0][0] = 1;
|
|---|
| 862 | neighbors[1][3] = 0;
|
|---|
| 863 | //from which side of the previous hexagon are we coming from ?
|
|---|
| 864 | int fromSide = 3;
|
|---|
| 865 | //to which side are we heading to ?
|
|---|
| 866 | int toSide = 0;
|
|---|
| 867 | for (int i=2;i<MAX_NUM_PIXELS;i++)
|
|---|
| 868 | {
|
|---|
| 869 | // cout << "i " << i << endl;
|
|---|
| 870 | toSide = fromSide-1;
|
|---|
| 871 | if (toSide < 0)
|
|---|
| 872 | toSide =5;
|
|---|
| 873 | while (neighbors[i-1][toSide] >= 0)
|
|---|
| 874 | {
|
|---|
| 875 | toSide--;
|
|---|
| 876 | if (toSide < 0)
|
|---|
| 877 | toSide = 5;
|
|---|
| 878 | }
|
|---|
| 879 | fromSide = toSide + 3;
|
|---|
| 880 | if (fromSide > 5)
|
|---|
| 881 | fromSide -= 6;
|
|---|
| 882 | //ok. now we now in which direction we're heading
|
|---|
| 883 | pixelsCoords[i][0] = pixelsCoords[i-1][0];
|
|---|
| 884 | pixelsCoords[i][1] = pixelsCoords[i-1][1];
|
|---|
| 885 | pixelsCoords[i][2] = pixelsCoords[i-1][2];
|
|---|
| 886 | switch (toSide)
|
|---|
| 887 | {
|
|---|
| 888 | case 0:
|
|---|
| 889 | pixelsCoords[i][1] += 2*hexRadius;
|
|---|
| 890 | break;
|
|---|
| 891 | case 1:
|
|---|
| 892 | pixelsCoords[i][0] += (2*hexRadius)*sin(M_PI/3.0);
|
|---|
| 893 | pixelsCoords[i][1] += (2*hexRadius)*cos(M_PI/3.0);
|
|---|
| 894 | break;
|
|---|
| 895 | case 2:
|
|---|
| 896 | pixelsCoords[i][0] += (2*hexRadius)*sin(M_PI/3.0);
|
|---|
| 897 | pixelsCoords[i][1] -= (2*hexRadius)*cos(M_PI/3.0);
|
|---|
| 898 | break;
|
|---|
| 899 | case 3:
|
|---|
| 900 | pixelsCoords[i][1] -= 2*hexRadius;
|
|---|
| 901 | break;
|
|---|
| 902 | case 4:
|
|---|
| 903 | pixelsCoords[i][0] -= (2*hexRadius)*sin(M_PI/3.0);
|
|---|
| 904 | pixelsCoords[i][1] -= (2*hexRadius)*cos(M_PI/3.0);
|
|---|
| 905 | break;
|
|---|
| 906 | case 5:
|
|---|
| 907 | pixelsCoords[i][0] -= (2*hexRadius)*sin(M_PI/3.0);
|
|---|
| 908 | pixelsCoords[i][1] += (2*hexRadius)*cos(M_PI/3.0);
|
|---|
| 909 | break;
|
|---|
| 910 | };
|
|---|
| 911 |
|
|---|
| 912 | updateNeighbors(i);
|
|---|
| 913 | }
|
|---|
| 914 | //Ok. So now we've circled around all the way to MAX_NUM_PIXELS
|
|---|
| 915 | //do the required shifts so that it matches the fact camera up to ACTUAL_NUM_PIXELS pixels
|
|---|
| 916 | //remember the location pixels 1438 and 1439, and re-assign them later on
|
|---|
| 917 | GLfloat backupCoords[4];
|
|---|
| 918 | skipPixels(1200, 1);
|
|---|
| 919 | skipPixels(1218, 3);
|
|---|
| 920 | skipPixels(1236, 1);
|
|---|
| 921 | skipPixels(1256, 1);
|
|---|
| 922 | skipPixels(1274, 3);
|
|---|
| 923 | skipPixels(1292, 3);
|
|---|
| 924 | skipPixels(1309, 6);
|
|---|
| 925 | skipPixels(1323, 7);
|
|---|
| 926 | skipPixels(1337, 6);
|
|---|
| 927 | skipPixels(1354, 6);
|
|---|
| 928 | skipPixels(1368, 7);
|
|---|
| 929 | //la c'est dans 1390 qu'il y a 1439
|
|---|
| 930 | backupCoords[0] = pixelsCoords[1390][0];
|
|---|
| 931 | backupCoords[1] = pixelsCoords[1390][1];
|
|---|
| 932 | skipPixels(1382, 9);
|
|---|
| 933 | skipPixels(1394, 12);
|
|---|
| 934 | skipPixels(1402, 15);
|
|---|
| 935 | skipPixels(1410, 12);
|
|---|
| 936 | //la c'est dans 1422 qu'il y a 1438
|
|---|
| 937 | backupCoords[2] = pixelsCoords[1422][0];
|
|---|
| 938 | backupCoords[3] = pixelsCoords[1422][1];
|
|---|
| 939 | skipPixels(1422, 12);
|
|---|
| 940 | skipPixels(1430, 15);
|
|---|
| 941 |
|
|---|
| 942 | pixelsCoords[1438][0] = backupCoords[2];
|
|---|
| 943 | pixelsCoords[1438][1] = backupCoords[3];
|
|---|
| 944 | pixelsCoords[1439][0] = backupCoords[0];
|
|---|
| 945 | pixelsCoords[1439][1] = backupCoords[1];
|
|---|
| 946 | }
|
|---|
| 947 | void BasicGlCamera::buildVerticesList()
|
|---|
| 948 | {
|
|---|
| 949 | numVertices = 0;
|
|---|
| 950 | GLfloat cVertex[2];
|
|---|
| 951 | for (int i=0;i<NPIX;i++)
|
|---|
| 952 | {
|
|---|
| 953 | for (int j=0;j<6;j++)
|
|---|
| 954 | {
|
|---|
| 955 | for (int k=0;k<2;k++)
|
|---|
| 956 | cVertex[k] = hexcoords[j][k]*hexRadius + pixelsCoords[i][k];
|
|---|
| 957 | bool found = false;
|
|---|
| 958 | for (int k=0;k<numVertices;k++)
|
|---|
| 959 | {
|
|---|
| 960 | if ((cVertex[0] - verticesList[k][0])*
|
|---|
| 961 | (cVertex[0] - verticesList[k][0]) +
|
|---|
| 962 | (cVertex[1] - verticesList[k][1])*
|
|---|
| 963 | (cVertex[1] - verticesList[k][1]) < hexTolerance*hexTolerance)
|
|---|
| 964 | {
|
|---|
| 965 | found = true;
|
|---|
| 966 | break;
|
|---|
| 967 | }
|
|---|
| 968 | }
|
|---|
| 969 | if (!found)
|
|---|
| 970 | {
|
|---|
| 971 | for (int k=0;k<2;k++)
|
|---|
| 972 | verticesList[numVertices][k] = cVertex[k];
|
|---|
| 973 | numVertices++;
|
|---|
| 974 | }
|
|---|
| 975 | }
|
|---|
| 976 | }
|
|---|
| 977 | //cout << "numVertices: " << numVertices << endl;
|
|---|
| 978 | for (int i=0;i<NPIX;i++)
|
|---|
| 979 | {
|
|---|
| 980 | for (int j=0;j<6;j++)
|
|---|
| 981 | {
|
|---|
| 982 | for (int k=0;k<2;k++)
|
|---|
| 983 | cVertex[k] = hexcoords[j][k]*hexRadius + pixelsCoords[i][k];
|
|---|
| 984 | for (int k=0;k<numVertices;k++)
|
|---|
| 985 | {
|
|---|
| 986 | if ((cVertex[0] - verticesList[k][0])*
|
|---|
| 987 | (cVertex[0] - verticesList[k][0]) +
|
|---|
| 988 | (cVertex[1] - verticesList[k][1])*
|
|---|
| 989 | (cVertex[1] - verticesList[k][1]) < hexTolerance*hexTolerance)
|
|---|
| 990 | {
|
|---|
| 991 | verticesIndices[i][j] = k;
|
|---|
| 992 | break;
|
|---|
| 993 | }
|
|---|
| 994 | }
|
|---|
| 995 | }
|
|---|
| 996 | }
|
|---|
| 997 | }
|
|---|
| 998 | void BasicGlCamera::buildPatchesIndices()
|
|---|
| 999 | {
|
|---|
| 1000 | vector<edge>::iterator it;
|
|---|
| 1001 | bool erased = false;
|
|---|
| 1002 | // patchesIndices.resize(NTMARK);
|
|---|
| 1003 | for (int i=0;i<NTMARK;i++)//for all patches
|
|---|
| 1004 | {
|
|---|
| 1005 | patchesIndices[i].clear();
|
|---|
| 1006 | for (int j=0;j<9;j++)//for all cells of the current patch
|
|---|
| 1007 | {
|
|---|
| 1008 | if (softwareMapping[patches[i][j]] >= ACTUAL_NUM_PIXELS)
|
|---|
| 1009 | continue;
|
|---|
| 1010 | for (int k=0;k<6;k++)//for all sides of the current cell
|
|---|
| 1011 | {
|
|---|
| 1012 | int first = k-1;
|
|---|
| 1013 | int second = k;
|
|---|
| 1014 | if (first < 0)
|
|---|
| 1015 | first = 5;
|
|---|
| 1016 | erased = false;
|
|---|
| 1017 | for (it=(patchesIndices[i]).begin(); it != (patchesIndices[i]).end(); it++)//check if this side is here already or not
|
|---|
| 1018 | {
|
|---|
| 1019 | if (((*it).first == verticesIndices[softwareMapping[patches[i][j]]][first] &&
|
|---|
| 1020 | (*it).second == verticesIndices[softwareMapping[patches[i][j]]][second]) ||
|
|---|
| 1021 | ((*it).first == verticesIndices[softwareMapping[patches[i][j]]][second] &&
|
|---|
| 1022 | (*it).second == verticesIndices[softwareMapping[patches[i][j]]][first]))
|
|---|
| 1023 | {
|
|---|
| 1024 | patchesIndices[i].erase(it);
|
|---|
| 1025 | erased = true;
|
|---|
| 1026 | break;
|
|---|
| 1027 | }
|
|---|
| 1028 | }
|
|---|
| 1029 | if (!erased)
|
|---|
| 1030 | {
|
|---|
| 1031 | edge temp;
|
|---|
| 1032 | temp.first = verticesIndices[softwareMapping[patches[i][j]]][first];
|
|---|
| 1033 | temp.second = verticesIndices[softwareMapping[patches[i][j]]][second];
|
|---|
| 1034 | patchesIndices[i].push_back(temp);
|
|---|
| 1035 | }
|
|---|
| 1036 | }
|
|---|
| 1037 | }
|
|---|
| 1038 | }
|
|---|
| 1039 | // for (int i=0;i<NTMARK;i++)
|
|---|
| 1040 | // {
|
|---|
| 1041 | // cout << ".....................patch " << i << " size: " << patchesIndices[i].size() << endl;
|
|---|
| 1042 | // for (unsigned int j=0;j<patchesIndices[i].size();j++)
|
|---|
| 1043 | // {
|
|---|
| 1044 | // if (patchesIndices[i][j].first < 0 || patchesIndices[i][j].first > 3013)
|
|---|
| 1045 | // cout << patchesIndices[i][j].first << " and " << patchesIndices[i][j].second << " and " << j << endl;
|
|---|
| 1046 | // }
|
|---|
| 1047 | // }
|
|---|
| 1048 | }
|
|---|
| 1049 |
|
|---|