| 1 | #include "QCameraWidget.h"
|
|---|
| 2 | #include <sstream>
|
|---|
| 3 | #include <iostream>
|
|---|
| 4 |
|
|---|
| 5 | QCameraWidget::QCameraWidget(QWidget *pparent) : BasicGlCamera(pparent)
|
|---|
| 6 | {
|
|---|
| 7 | fWhite = -1;
|
|---|
| 8 | fWhitePatch = -1;
|
|---|
| 9 | fBold.resize(1440);
|
|---|
| 10 | fEnable.resize(1440);
|
|---|
| 11 | fBold.assign(1440, false);
|
|---|
| 12 | fEnable.assign(1440, true);
|
|---|
| 13 | fMin = -1;
|
|---|
| 14 | fMax = -1;
|
|---|
| 15 | lastFace = -1;
|
|---|
| 16 | unitsText = "";
|
|---|
| 17 | titleText = "This is a title";
|
|---|
| 18 | dataText = "";
|
|---|
| 19 | logScale = false;
|
|---|
| 20 | cameraRotation = 0;
|
|---|
| 21 |
|
|---|
| 22 | pixelContourColour[0] = 0.1f;
|
|---|
| 23 | pixelContourColour[1] = 0.1f;
|
|---|
| 24 | pixelContourColour[2] = 0.1f;
|
|---|
| 25 | patchesCoulour[0] = 0.15f;
|
|---|
| 26 | patchesCoulour[1] = 0.15f;
|
|---|
| 27 | patchesCoulour[2] = 0.15f;
|
|---|
| 28 | highlightedPatchesCoulour[0] = 0.6f;
|
|---|
| 29 | highlightedPatchesCoulour[1] = 0.6f;
|
|---|
| 30 | highlightedPatchesCoulour[2] = 0.6f;
|
|---|
| 31 | highlightedPixelsCoulour[0] = 0.8f;
|
|---|
| 32 | highlightedPixelsCoulour[1] = 0.8f;
|
|---|
| 33 | highlightedPixelsCoulour[2] = 0.8f;
|
|---|
| 34 |
|
|---|
| 35 | regularPalettePlease();
|
|---|
| 36 |
|
|---|
| 37 | CalculatePixelsColor();
|
|---|
| 38 |
|
|---|
| 39 | setFont(QFont("Arial", 8));
|
|---|
| 40 | int buttonShift=0;
|
|---|
| 41 | scaleLabel = new QLabel("Scale", this);
|
|---|
| 42 | // buttonShift += scaleLabel->height();
|
|---|
| 43 |
|
|---|
| 44 | linearButton = new QRadioButton("Linear", this);
|
|---|
| 45 | linearButton->move(scaleLabel->width(), buttonShift);
|
|---|
| 46 | buttonShift += linearButton->height();
|
|---|
| 47 |
|
|---|
| 48 | logButton = new QRadioButton("Log", this);
|
|---|
| 49 | logButton->move(scaleLabel->width(), buttonShift);
|
|---|
| 50 | buttonShift += logButton->height()*1.1f;
|
|---|
| 51 |
|
|---|
| 52 | colorPaletteLabel = new QLabel("Colour\nPalette", this);
|
|---|
| 53 | colorPaletteLabel->move(0, buttonShift);
|
|---|
| 54 | // buttonShift += colorPaletteLabel->height();
|
|---|
| 55 |
|
|---|
| 56 | regularPaletteButton = new QRadioButton("Regular", this);
|
|---|
| 57 | regularPaletteButton->move(colorPaletteLabel->width(), buttonShift);
|
|---|
| 58 | buttonShift += regularPaletteButton->height();
|
|---|
| 59 |
|
|---|
| 60 | prettyPaletteButton = new QRadioButton("Pretty", this);
|
|---|
| 61 | prettyPaletteButton->move(colorPaletteLabel->width(), buttonShift);
|
|---|
| 62 | buttonShift += prettyPaletteButton->height();
|
|---|
| 63 |
|
|---|
| 64 | greyScalePaletteButton = new QRadioButton("Grey Scale", this);
|
|---|
| 65 | greyScalePaletteButton->move(colorPaletteLabel->width(), buttonShift);
|
|---|
| 66 | buttonShift += greyScalePaletteButton->height();
|
|---|
| 67 |
|
|---|
| 68 | glowingPaletteButton = new QRadioButton("Glowing", this);
|
|---|
| 69 | glowingPaletteButton->move(colorPaletteLabel->width(), buttonShift);
|
|---|
| 70 | buttonShift += glowingPaletteButton->height()*1.1f;
|
|---|
| 71 |
|
|---|
| 72 | rotationLabel = new QLabel("Camera\nRotation", this);
|
|---|
| 73 | rotationLabel->move(0, buttonShift);
|
|---|
| 74 | // buttonShift += rotationLabel->height();
|
|---|
| 75 |
|
|---|
| 76 | unsigned short utf16Array;
|
|---|
| 77 | utf16Array = 0x00b0;
|
|---|
| 78 | QString degreeSymbol(QString::fromUtf16(&utf16Array, 1));
|
|---|
| 79 | QString zerostr("0" + degreeSymbol);
|
|---|
| 80 | zeroRotationButton = new QRadioButton(zerostr, this);
|
|---|
| 81 | zeroRotationButton->move(rotationLabel->width(), buttonShift);
|
|---|
| 82 | buttonShift += zeroRotationButton->height();
|
|---|
| 83 | QString minus90str("-90" + degreeSymbol);
|
|---|
| 84 | minus90RotationButton = new QRadioButton(minus90str, this);
|
|---|
| 85 | minus90RotationButton->move(rotationLabel->width(), buttonShift);
|
|---|
| 86 | buttonShift += minus90RotationButton->height();
|
|---|
| 87 | QString plus90str("+90"+degreeSymbol);
|
|---|
| 88 | plus90Rotationbutton = new QRadioButton(plus90str, this);
|
|---|
| 89 | plus90Rotationbutton->move(rotationLabel->width(), buttonShift);
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 | scaleGroup = new QButtonGroup(pparent);
|
|---|
| 93 | colorGroup = new QButtonGroup(pparent);
|
|---|
| 94 | rotationGroup = new QButtonGroup(pparent);
|
|---|
| 95 | scaleGroup->addButton(linearButton);
|
|---|
| 96 | scaleGroup->addButton(logButton);
|
|---|
| 97 | colorGroup->addButton(regularPaletteButton);
|
|---|
| 98 | colorGroup->addButton(prettyPaletteButton);
|
|---|
| 99 | colorGroup->addButton(greyScalePaletteButton);
|
|---|
| 100 | colorGroup->addButton(glowingPaletteButton);
|
|---|
| 101 | rotationGroup->addButton(zeroRotationButton);
|
|---|
| 102 | rotationGroup->addButton(minus90RotationButton);
|
|---|
| 103 | rotationGroup->addButton(plus90Rotationbutton);
|
|---|
| 104 |
|
|---|
| 105 | linearButton->setChecked(true);
|
|---|
| 106 | regularPaletteButton->setChecked(true);
|
|---|
| 107 | zeroRotationButton->setChecked(true);
|
|---|
| 108 |
|
|---|
| 109 | // linearButton->palette.setColor();
|
|---|
| 110 |
|
|---|
| 111 | linearButton->setAutoFillBackground(true);
|
|---|
| 112 | logButton->setAutoFillBackground(true);
|
|---|
| 113 | regularPaletteButton->setAutoFillBackground(true);
|
|---|
| 114 | prettyPaletteButton->setAutoFillBackground(true);
|
|---|
| 115 | greyScalePaletteButton->setAutoFillBackground(true);
|
|---|
| 116 | glowingPaletteButton->setAutoFillBackground(true);
|
|---|
| 117 | zeroRotationButton->setAutoFillBackground(true);
|
|---|
| 118 | minus90RotationButton->setAutoFillBackground(true);
|
|---|
| 119 | plus90Rotationbutton->setAutoFillBackground(true);
|
|---|
| 120 | scaleLabel->setAutoFillBackground(true);
|
|---|
| 121 | colorPaletteLabel->setAutoFillBackground(true);
|
|---|
| 122 | rotationLabel->setAutoFillBackground(true);
|
|---|
| 123 |
|
|---|
| 124 | linearButton->hide();
|
|---|
| 125 | logButton->hide();
|
|---|
| 126 | regularPaletteButton->hide();
|
|---|
| 127 | prettyPaletteButton->hide();
|
|---|
| 128 | greyScalePaletteButton->hide();
|
|---|
| 129 | glowingPaletteButton->hide();
|
|---|
| 130 | zeroRotationButton->hide();
|
|---|
| 131 | minus90RotationButton->hide();
|
|---|
| 132 | plus90Rotationbutton->hide();
|
|---|
| 133 | scaleLabel->hide();
|
|---|
| 134 | colorPaletteLabel->hide();
|
|---|
| 135 | rotationLabel->hide();
|
|---|
| 136 |
|
|---|
| 137 | connect(linearButton, SIGNAL(toggled(bool)),
|
|---|
| 138 | this, SLOT(linearScalePlease(bool)));
|
|---|
| 139 | connect(logButton, SIGNAL(toggled(bool)),
|
|---|
| 140 | this, SLOT(logScalePlease(bool)));
|
|---|
| 141 | connect(regularPaletteButton, SIGNAL(toggled(bool)),
|
|---|
| 142 | this, SLOT(regularPalettePlease(bool)));
|
|---|
| 143 | connect(prettyPaletteButton, SIGNAL(toggled(bool)),
|
|---|
| 144 | this, SLOT(prettyPalettePlease(bool)));
|
|---|
| 145 | connect(greyScalePaletteButton, SIGNAL(toggled(bool)),
|
|---|
| 146 | this, SLOT(greyScalePalettePlease(bool)));
|
|---|
| 147 | connect(glowingPaletteButton, SIGNAL(toggled(bool)),
|
|---|
| 148 | this, SLOT(glowingPalettePlease(bool)));
|
|---|
| 149 | connect(zeroRotationButton, SIGNAL(toggled(bool)),
|
|---|
| 150 | this, SLOT(zeroRotationPlease(bool)));
|
|---|
| 151 | connect(minus90RotationButton, SIGNAL(toggled(bool)),
|
|---|
| 152 | this, SLOT(plus90RotationPlease(bool)));
|
|---|
| 153 | connect(plus90Rotationbutton, SIGNAL(toggled(bool)),
|
|---|
| 154 | this, SLOT(minus90RotationPlease(bool)));
|
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | void QCameraWidget::paintGL()
|
|---|
| 161 | {
|
|---|
| 162 | glClear(GL_COLOR_BUFFER_BIT);
|
|---|
| 163 | glLoadIdentity();
|
|---|
| 164 |
|
|---|
| 165 | glTranslatef(0,-0.44,0);
|
|---|
| 166 | glRotatef(cameraRotation, 0,0,-1);
|
|---|
| 167 | if (cameraRotation == 90)
|
|---|
| 168 | {
|
|---|
| 169 | glTranslatef(-0.45,-0.45,0);
|
|---|
| 170 | // cout << "correction" << endl;
|
|---|
| 171 | }
|
|---|
| 172 | if (cameraRotation == -90)
|
|---|
| 173 | {
|
|---|
| 174 | glTranslatef(0.45,-0.45,0);
|
|---|
| 175 | }
|
|---|
| 176 | glScalef(1.5, 1.5, 1.5);
|
|---|
| 177 | drawCamera(true);
|
|---|
| 178 |
|
|---|
| 179 | glLineWidth(1.0f);
|
|---|
| 180 | glColor3fv(highlightedPixelsCoulour);
|
|---|
| 181 | for (vector<int>::iterator it = highlightedPixels.begin(); it!= highlightedPixels.end(); it++)
|
|---|
| 182 | {
|
|---|
| 183 | drawHexagon(*it, false);
|
|---|
| 184 | }
|
|---|
| 185 | drawPatches();
|
|---|
| 186 |
|
|---|
| 187 | glLineWidth(1.0f);
|
|---|
| 188 |
|
|---|
| 189 | //glColor3f(1.f - pixelsColor[fWhite][0],1.f - pixelsColor[fWhite][1],1.f - pixelsColor[fWhite][2]);
|
|---|
| 190 | if (fWhite != -1)
|
|---|
| 191 | {
|
|---|
| 192 | glColor3f(1.f, 0.f, 0.f);
|
|---|
| 193 | drawHexagon(fWhite, false);
|
|---|
| 194 | }
|
|---|
| 195 | DrawCameraText();
|
|---|
| 196 |
|
|---|
| 197 | DrawScale();
|
|---|
| 198 |
|
|---|
| 199 | // if (linearButton->isVisible())
|
|---|
| 200 | // repaintInterface();
|
|---|
| 201 | }
|
|---|
| 202 | void QCameraWidget::drawCamera(bool alsoWire)
|
|---|
| 203 | {
|
|---|
| 204 | if (!pixelColorUpToDate)
|
|---|
| 205 | CalculatePixelsColor();
|
|---|
| 206 | glLineWidth(1.0);
|
|---|
| 207 | for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
|
|---|
| 208 | {
|
|---|
| 209 | glColor3fv(pixelsColor[i]);
|
|---|
| 210 | glLoadName(i);
|
|---|
| 211 | drawHexagon(i,true);
|
|---|
| 212 | }
|
|---|
| 213 | if (!alsoWire)
|
|---|
| 214 | return;
|
|---|
| 215 | glColor3fv(pixelContourColour);//0.0f,0.0f,0.0f);
|
|---|
| 216 | for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
|
|---|
| 217 | {
|
|---|
| 218 | drawHexagon(i, false);
|
|---|
| 219 | }
|
|---|
| 220 | }
|
|---|
| 221 | void QCameraWidget::drawPatches()
|
|---|
| 222 | {
|
|---|
| 223 | glLineWidth(2.0f);
|
|---|
| 224 | glColor3fv(patchesCoulour);
|
|---|
| 225 | glBegin(GL_LINES);
|
|---|
| 226 | for (int i=0;i<NTMARK;i++)
|
|---|
| 227 | {
|
|---|
| 228 | for (unsigned int j=0;j<patchesIndices[i].size();j++)
|
|---|
| 229 | {
|
|---|
| 230 | glVertex2fv(verticesList[patchesIndices[i][j].first]);
|
|---|
| 231 | glVertex2fv(verticesList[patchesIndices[i][j].second]);
|
|---|
| 232 | }
|
|---|
| 233 | }
|
|---|
| 234 | glEnd();
|
|---|
| 235 |
|
|---|
| 236 | glColor3fv(highlightedPatchesCoulour);
|
|---|
| 237 | glBegin(GL_LINES);
|
|---|
| 238 | for (vector<int>::iterator it=highlightedPatches.begin(); it!= highlightedPatches.end(); it++)
|
|---|
| 239 | {
|
|---|
| 240 | for (unsigned int j=0;j<patchesIndices[*it].size();j++)
|
|---|
| 241 | {
|
|---|
| 242 | glVertex2fv(verticesList[patchesIndices[*it][j].first]);
|
|---|
| 243 | glVertex2fv(verticesList[patchesIndices[*it][j].second]);
|
|---|
| 244 | }
|
|---|
| 245 | }
|
|---|
| 246 | glEnd();
|
|---|
| 247 | if (fWhitePatch != -1)
|
|---|
| 248 | {
|
|---|
| 249 | glColor3f(1.f, 0.5f, 0.f);//patchColour);//[0],patchColour[1],patchColour[2]);//0.5f, 0.5f, 0.3f);
|
|---|
| 250 | glBegin(GL_LINES);
|
|---|
| 251 | for (unsigned int j=0;j<patchesIndices[fWhitePatch].size();j++)
|
|---|
| 252 | {
|
|---|
| 253 | glVertex2fv(verticesList[patchesIndices[fWhitePatch][j].first]);
|
|---|
| 254 | glVertex2fv(verticesList[patchesIndices[fWhitePatch][j].second]);
|
|---|
| 255 | }
|
|---|
| 256 | glEnd();
|
|---|
| 257 | }
|
|---|
| 258 |
|
|---|
| 259 | }
|
|---|
| 260 | void QCameraWidget::Reset()
|
|---|
| 261 | {
|
|---|
| 262 | fBold.assign(1440, false);
|
|---|
| 263 | }
|
|---|
| 264 | void QCameraWidget::toggleInterfaceDisplay()
|
|---|
| 265 | {
|
|---|
| 266 | if (linearButton->isVisible())
|
|---|
| 267 | {
|
|---|
| 268 | linearButton->hide();
|
|---|
| 269 | logButton->hide();
|
|---|
| 270 | regularPaletteButton->hide();
|
|---|
| 271 | prettyPaletteButton->hide();
|
|---|
| 272 | greyScalePaletteButton->hide();
|
|---|
| 273 | glowingPaletteButton->hide();
|
|---|
| 274 | zeroRotationButton->hide();
|
|---|
| 275 | minus90RotationButton->hide();
|
|---|
| 276 | plus90Rotationbutton->hide();
|
|---|
| 277 | scaleLabel->hide();
|
|---|
| 278 | colorPaletteLabel->hide();
|
|---|
| 279 | rotationLabel->hide();
|
|---|
| 280 | }
|
|---|
| 281 | else
|
|---|
| 282 | {
|
|---|
| 283 | linearButton->show();
|
|---|
| 284 | logButton->show();
|
|---|
| 285 | regularPaletteButton->show();
|
|---|
| 286 | prettyPaletteButton->show();
|
|---|
| 287 | greyScalePaletteButton->show();
|
|---|
| 288 | glowingPaletteButton->show();
|
|---|
| 289 | zeroRotationButton->show();
|
|---|
| 290 | minus90RotationButton->show();
|
|---|
| 291 | plus90Rotationbutton->show();
|
|---|
| 292 | scaleLabel->show();
|
|---|
| 293 | colorPaletteLabel->show();
|
|---|
| 294 | rotationLabel->show();
|
|---|
| 295 | }
|
|---|
| 296 | }
|
|---|
| 297 | void QCameraWidget::repaintInterface()
|
|---|
| 298 | {
|
|---|
| 299 | return;
|
|---|
| 300 | setFont(QFont("Arial", 10));
|
|---|
| 301 | // glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
|---|
| 302 | linearButton->render(this);
|
|---|
| 303 | logButton->render(this);
|
|---|
| 304 | regularPaletteButton->render(this);
|
|---|
| 305 | prettyPaletteButton->render(this);
|
|---|
| 306 | greyScalePaletteButton->render(this);
|
|---|
| 307 | glowingPaletteButton->render(this);
|
|---|
| 308 | zeroRotationButton->render(this);
|
|---|
| 309 | minus90RotationButton->render(this);
|
|---|
| 310 | plus90Rotationbutton->render(this);
|
|---|
| 311 | // scaleLabel->repaint();
|
|---|
| 312 | colorPaletteLabel->render(this);
|
|---|
| 313 | rotationLabel->render(this);
|
|---|
| 314 |
|
|---|
| 315 | scaleLabel->render(this);
|
|---|
| 316 | // cout << scaleLabel->autoFillBackground() << endl;
|
|---|
| 317 | }
|
|---|
| 318 | void QCameraWidget::mousePressEvent(QMouseEvent *cEvent)
|
|---|
| 319 | {
|
|---|
| 320 | if (cEvent->pos().x() > width()-(width()/50.f))
|
|---|
| 321 | {
|
|---|
| 322 | toggleInterfaceDisplay();
|
|---|
| 323 | return;
|
|---|
| 324 | }
|
|---|
| 325 | int face = PixelAtPosition(cEvent->pos());
|
|---|
| 326 | if (face != -1) {
|
|---|
| 327 | fWhite = face;
|
|---|
| 328 | fWhitePatch = pixelsPatch[fWhite];
|
|---|
| 329 | // CalculatePatchColor();
|
|---|
| 330 | emit signalCurrentPixel(face);
|
|---|
| 331 | }
|
|---|
| 332 | else
|
|---|
| 333 | {
|
|---|
| 334 | fWhite = -1;
|
|---|
| 335 | fWhitePatch = -1;
|
|---|
| 336 | }
|
|---|
| 337 | updateGL();
|
|---|
| 338 | }
|
|---|
| 339 | void QCameraWidget::mouseMoveEvent(QMouseEvent* cEvent)
|
|---|
| 340 | {
|
|---|
| 341 | int face = PixelAtPosition(cEvent->pos());
|
|---|
| 342 | if (face != -1 && lastFace != face) {
|
|---|
| 343 | emit signalPixelMoveOver(face);
|
|---|
| 344 | }
|
|---|
| 345 | lastFace = face;
|
|---|
| 346 | }
|
|---|
| 347 | void QCameraWidget::mouseDoubleClickEvent(QMouseEvent* cEvent)
|
|---|
| 348 | {
|
|---|
| 349 | int face = PixelAtPosition(cEvent->pos());
|
|---|
| 350 | if (face != -1) {
|
|---|
| 351 | // cout << "Event !" << endl;
|
|---|
| 352 | fWhite = face;
|
|---|
| 353 | fWhitePatch = pixelsPatch[fWhite];
|
|---|
| 354 | highlightPixel(face);
|
|---|
| 355 | highlightPatch(fWhitePatch);
|
|---|
| 356 | // CalculatePatchColor();
|
|---|
| 357 | emit signalPixelDoubleClick(face);
|
|---|
| 358 | }
|
|---|
| 359 | else
|
|---|
| 360 | {
|
|---|
| 361 | fWhite = -1;
|
|---|
| 362 | fWhitePatch = -1;
|
|---|
| 363 | clearHighlightedPixels();
|
|---|
| 364 | clearHighlightedPatches();
|
|---|
| 365 | }
|
|---|
| 366 | updateGL();
|
|---|
| 367 |
|
|---|
| 368 | }
|
|---|
| 369 |
|
|---|
| 370 | void QCameraWidget::SetWhite(int idx)
|
|---|
| 371 | {
|
|---|
| 372 | fWhite = idx;
|
|---|
| 373 | fWhitePatch = pixelsPatch[fWhite];
|
|---|
| 374 | if (isVisible())
|
|---|
| 375 | updateGL();
|
|---|
| 376 | // CalculatePatchColor();
|
|---|
| 377 | }
|
|---|
| 378 | void QCameraWidget::SetEnable(int idx, bool b)
|
|---|
| 379 | {
|
|---|
| 380 | fEnable[idx] = b;
|
|---|
| 381 | }
|
|---|
| 382 |
|
|---|
| 383 | double QCameraWidget::GetData(int idx)
|
|---|
| 384 | {
|
|---|
| 385 | return fData[idx];
|
|---|
| 386 | }
|
|---|
| 387 | void QCameraWidget::SetMin(int64_t min)
|
|---|
| 388 | {
|
|---|
| 389 | // cout << "min: " << min << endl;
|
|---|
| 390 | fMin = min;
|
|---|
| 391 | pixelColorUpToDate = false;
|
|---|
| 392 | if (isVisible())
|
|---|
| 393 | updateGL();
|
|---|
| 394 | }
|
|---|
| 395 | void QCameraWidget::SetMax(int64_t max)
|
|---|
| 396 | {
|
|---|
| 397 | // cout << "max: " << max << endl;
|
|---|
| 398 | fMax = max;
|
|---|
| 399 | pixelColorUpToDate = false;
|
|---|
| 400 | if (isVisible())
|
|---|
| 401 | updateGL();
|
|---|
| 402 | }
|
|---|
| 403 | const char* QCameraWidget::GetName()
|
|---|
| 404 | {
|
|---|
| 405 | return "QCameraWidget";
|
|---|
| 406 | }
|
|---|
| 407 | char *QCameraWidget::GetObjectInfo(int px, int py)
|
|---|
| 408 | {
|
|---|
| 409 |
|
|---|
| 410 | static stringstream stream;
|
|---|
| 411 | static string str;
|
|---|
| 412 | const int pixel = this->PixelAtPosition(QPoint(px, py));
|
|---|
| 413 | if (pixel >= 0)
|
|---|
| 414 | {
|
|---|
| 415 | stream << "Pixel=" << pixel << " Data=" << fData[pixel] << '\0';
|
|---|
| 416 | }
|
|---|
| 417 | str = stream.str();
|
|---|
| 418 | return const_cast<char*>(str.c_str());
|
|---|
| 419 | }
|
|---|
| 420 | void QCameraWidget::CalculatePixelsColor()
|
|---|
| 421 | {
|
|---|
| 422 | double dmin = fData[0];
|
|---|
| 423 | double dmax = fData[0];
|
|---|
| 424 | if (fMin < 0 || fMax < 0)
|
|---|
| 425 | {
|
|---|
| 426 | for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
|
|---|
| 427 | {
|
|---|
| 428 | if (!fEnable[i]) continue;
|
|---|
| 429 | if (fData[i] > dmax) dmax = fData[i];
|
|---|
| 430 | if (fData[i] < dmin) dmin = fData[i];
|
|---|
| 431 | }
|
|---|
| 432 | }
|
|---|
| 433 | if (fMin >= 0) dmin = fMin;
|
|---|
| 434 | if (fMax >= 0) dmax = fMax;
|
|---|
| 435 | // cout << "min: " << dmin << " max: " << dmax << " fMin: " << fMin << " fMax: " << fMax << endl;
|
|---|
| 436 | float color;
|
|---|
| 437 | for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
|
|---|
| 438 | {
|
|---|
| 439 | if (!fEnable[i])
|
|---|
| 440 | {
|
|---|
| 441 | // cout << "not enabled !" << i << endl;
|
|---|
| 442 | pixelsColor[i][0] = 0.1f;
|
|---|
| 443 | pixelsColor[i][1] = 0.1f;
|
|---|
| 444 | pixelsColor[i][2] = 0.15f;
|
|---|
| 445 | continue;
|
|---|
| 446 | }
|
|---|
| 447 | if (fData[i] < dmin)
|
|---|
| 448 | {
|
|---|
| 449 | pixelsColor[i][0] = tooLowValueCoulour[0];
|
|---|
| 450 | pixelsColor[i][1] = tooLowValueCoulour[1];
|
|---|
| 451 | pixelsColor[i][2] = tooLowValueCoulour[2];
|
|---|
| 452 | continue;
|
|---|
| 453 | }
|
|---|
| 454 | if (fData[i] > dmax)
|
|---|
| 455 | {
|
|---|
| 456 | pixelsColor[i][0] = tooHighValueCoulour[0];
|
|---|
| 457 | pixelsColor[i][1] = tooHighValueCoulour[1];
|
|---|
| 458 | pixelsColor[i][2] = tooHighValueCoulour[2];
|
|---|
| 459 | continue;
|
|---|
| 460 | }
|
|---|
| 461 | color = float((fData[i]-dmin)/(dmax-dmin));
|
|---|
| 462 | if (logScale)
|
|---|
| 463 | {
|
|---|
| 464 | color *= 9;
|
|---|
| 465 | color += 1;
|
|---|
| 466 | color = log10(color);
|
|---|
| 467 | }
|
|---|
| 468 |
|
|---|
| 469 | int index = 0;
|
|---|
| 470 | while (ss[index] < color && index < 4)
|
|---|
| 471 | index++;
|
|---|
| 472 | index--;
|
|---|
| 473 | if (index < 0) index = 0;
|
|---|
| 474 | float weight0 = (color-ss[index]) / (ss[index+1]-ss[index]);
|
|---|
| 475 | if (weight0 > 1.0f) weight0 = 1.0f;
|
|---|
| 476 | if (weight0 < 0.0f) weight0 = 0.0f;
|
|---|
| 477 | float weight1 = 1.0f-weight0;
|
|---|
| 478 | pixelsColor[i][0] = weight1*rr[index] + weight0*rr[index+1];
|
|---|
| 479 | pixelsColor[i][1] = weight1*gg[index] + weight0*gg[index+1];
|
|---|
| 480 | pixelsColor[i][2] = weight1*bb[index] + weight0*bb[index+1];
|
|---|
| 481 | }
|
|---|
| 482 | CalculatePatchColor();
|
|---|
| 483 | UpdateText();
|
|---|
| 484 | pixelColorUpToDate = true;
|
|---|
| 485 | }
|
|---|
| 486 | void QCameraWidget::CalculatePatchColor()
|
|---|
| 487 | {
|
|---|
| 488 | return;
|
|---|
| 489 | //calculate the patch contour color. let's use the anti-colour of the pixels
|
|---|
| 490 | GLfloat averagePatchColour[3] = {0.0f,0.0f,0.0f};
|
|---|
| 491 | for (int i=0;i<9;i++)
|
|---|
| 492 | for (int j=0;j<3;j++)
|
|---|
| 493 | averagePatchColour[j] += pixelsColor[softwareMapping[patches[fWhitePatch][i]]][j];
|
|---|
| 494 | for (int j=0;j<3;j++)
|
|---|
| 495 | averagePatchColour[j] /= 9;
|
|---|
| 496 | for (int j=0;j<3;j++)
|
|---|
| 497 | patchColour[j] = 1.0f - averagePatchColour[j];
|
|---|
| 498 | }
|
|---|
| 499 | void QCameraWidget::SetData(const valarray<double> &ddata)
|
|---|
| 500 | {
|
|---|
| 501 | // fData = ddata;
|
|---|
| 502 | for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
|
|---|
| 503 | fData[i] = ddata[i];
|
|---|
| 504 | pixelColorUpToDate = false;
|
|---|
| 505 | if (isVisible())
|
|---|
| 506 | updateGL();
|
|---|
| 507 | }
|
|---|
| 508 | void QCameraWidget::UpdateText()
|
|---|
| 509 | {
|
|---|
| 510 | ostringstream str;
|
|---|
| 511 | float min, max, mean, rms, median;
|
|---|
| 512 | min = max = fData[0];
|
|---|
| 513 | mean = 0;
|
|---|
| 514 | rms = 0;
|
|---|
| 515 | median = 0;
|
|---|
| 516 | multiset<double> medianSet;
|
|---|
| 517 | for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
|
|---|
| 518 | {
|
|---|
| 519 | if (fData[i] < min)
|
|---|
| 520 | min = fData[i];
|
|---|
| 521 | if (fData[i] > max)
|
|---|
| 522 | max = fData[i];
|
|---|
| 523 | mean += fData[i];
|
|---|
| 524 | rms += fData[i]*fData[i];
|
|---|
| 525 | medianSet.insert(fData[i]);
|
|---|
| 526 | }
|
|---|
| 527 | mean /= ACTUAL_NUM_PIXELS;
|
|---|
| 528 | rms /= ACTUAL_NUM_PIXELS;
|
|---|
| 529 | rms = sqrt(rms);
|
|---|
| 530 | // cout << "Size of the set: " << medianSet.size() << endl;
|
|---|
| 531 | multiset<double>::iterator it = medianSet.begin();
|
|---|
| 532 | for (int i=0;i<(ACTUAL_NUM_PIXELS/2)-1;i++)
|
|---|
| 533 | it++;
|
|---|
| 534 | median = *it;
|
|---|
| 535 | it++;
|
|---|
| 536 | median += *it;
|
|---|
| 537 | median /= 2;
|
|---|
| 538 |
|
|---|
| 539 | str << "Min: " << min << " Max: " << max << " Mean: " << mean << " RMS: " << rms << " Median: " << median;
|
|---|
| 540 | str << " Units: " << unitsText;
|
|---|
| 541 | dataText = str.str();
|
|---|
| 542 | }
|
|---|
| 543 | void QCameraWidget::DrawCameraText()
|
|---|
| 544 | {
|
|---|
| 545 | glPushMatrix();
|
|---|
| 546 | glLoadIdentity();
|
|---|
| 547 | // cout << width() << " " << height() << endl;
|
|---|
| 548 | int textSize = (int)(height()*14/600);
|
|---|
| 549 | setFont(QFont("Times", textSize));
|
|---|
| 550 | qglColor(QColor(255,223,127));
|
|---|
| 551 | float shiftx = 0.01f;//0.55f;
|
|---|
| 552 | float shifty = 0.01f;//0.65f;
|
|---|
| 553 | renderText(-shownSizex/2.f + shiftx, -shownSizey/2.f + shifty, 0.f, QString(dataText.c_str()));
|
|---|
| 554 |
|
|---|
| 555 |
|
|---|
| 556 | int textLength = titleText.size();
|
|---|
| 557 | renderText(-shownSizex/2.f + shiftx, shownSizey/2.f - textSize*pixelSize - shifty, 0.f, QString(titleText.c_str()));
|
|---|
| 558 |
|
|---|
| 559 | glPopMatrix();
|
|---|
| 560 | }
|
|---|
| 561 | void QCameraWidget::DrawScale()
|
|---|
| 562 | {
|
|---|
| 563 | glPushMatrix();
|
|---|
| 564 | glLoadIdentity();
|
|---|
| 565 | glPushAttrib(GL_POLYGON_BIT);
|
|---|
| 566 | glShadeModel(GL_SMOOTH);
|
|---|
| 567 | glBegin(GL_QUADS);
|
|---|
| 568 | float oneX = shownSizex/2.f - shownSizex/50.f;
|
|---|
| 569 | float twoX = shownSizex/2.f;
|
|---|
| 570 | float oneY = -shownSizey/2.f;
|
|---|
| 571 | float twoY = -shownSizey/4.f;
|
|---|
| 572 | float threeY = 0;
|
|---|
| 573 | float fourY = shownSizey/4.f;
|
|---|
| 574 | float fiveY = shownSizey/2.f;
|
|---|
| 575 | glColor3f(rr[0], gg[0], bb[0]);
|
|---|
| 576 | glVertex2f(oneX, oneY);
|
|---|
| 577 | glVertex2f(twoX, oneY);
|
|---|
| 578 | glColor3f(rr[1], gg[1], bb[1]);
|
|---|
| 579 | glVertex2f(twoX, twoY);
|
|---|
| 580 | glVertex2f(oneX, twoY);
|
|---|
| 581 |
|
|---|
| 582 | glVertex2f(oneX, twoY);
|
|---|
| 583 | glVertex2f(twoX, twoY);
|
|---|
| 584 | glColor3f(rr[2], gg[2], bb[2]);
|
|---|
| 585 | glVertex2f(twoX, threeY);
|
|---|
| 586 | glVertex2f(oneX, threeY);
|
|---|
| 587 |
|
|---|
| 588 | glVertex2f(oneX, threeY);
|
|---|
| 589 | glVertex2f(twoX, threeY);
|
|---|
| 590 | glColor3f(rr[3], gg[3], bb[3]);
|
|---|
| 591 | glVertex2f(twoX, fourY);
|
|---|
| 592 | glVertex2f(oneX, fourY);
|
|---|
| 593 |
|
|---|
| 594 | glVertex2f(oneX, fourY);
|
|---|
| 595 | glVertex2f(twoX, fourY);
|
|---|
| 596 | glColor3f(rr[4], gg[4], bb[4]);
|
|---|
| 597 | glVertex2f(twoX, fiveY);
|
|---|
| 598 | glVertex2f(oneX, fiveY);
|
|---|
| 599 | float zeroX = oneX - shownSizex/50.f;
|
|---|
| 600 | float zeroY = fiveY - shownSizey/50.f;
|
|---|
| 601 | glColor3fv(tooHighValueCoulour);
|
|---|
| 602 | glVertex2f(zeroX, fiveY);
|
|---|
| 603 | glVertex2f(oneX, fiveY);
|
|---|
| 604 | glVertex2f(oneX, zeroY);
|
|---|
| 605 | glVertex2f(zeroX, zeroY);
|
|---|
| 606 | glColor3fv(tooLowValueCoulour);
|
|---|
| 607 | glVertex2f(zeroX, -fiveY);
|
|---|
| 608 | glVertex2f(oneX, -fiveY);
|
|---|
| 609 | glVertex2f(oneX, -zeroY);
|
|---|
| 610 | glVertex2f(zeroX, -zeroY);
|
|---|
| 611 | glEnd();
|
|---|
| 612 | //draw linear/log tick marks
|
|---|
| 613 | glColor3f(0.f,0.f,0.f);
|
|---|
| 614 | glBegin(GL_LINES);
|
|---|
| 615 | float value;
|
|---|
| 616 | for (int i=1;i<10;i++)
|
|---|
| 617 | {
|
|---|
| 618 | if (logScale)
|
|---|
| 619 | value = log10(i);
|
|---|
| 620 | else
|
|---|
| 621 | value = (float)(i)/10.f;
|
|---|
| 622 | float y = -shownSizey/2.f + value*shownSizey;
|
|---|
| 623 | glVertex2f(oneX, y);
|
|---|
| 624 | glVertex2f(twoX, y);
|
|---|
| 625 | }
|
|---|
| 626 | glEnd();
|
|---|
| 627 | glPopAttrib();
|
|---|
| 628 | glPopMatrix();
|
|---|
| 629 | }
|
|---|
| 630 | void QCameraWidget::setUnits(const string& units)
|
|---|
| 631 | {
|
|---|
| 632 | unitsText = units;
|
|---|
| 633 | pixelColorUpToDate = false;
|
|---|
| 634 | if (isVisible())
|
|---|
| 635 | updateGL();
|
|---|
| 636 | }
|
|---|
| 637 | void QCameraWidget::setTitle(const string& title)
|
|---|
| 638 | {
|
|---|
| 639 | titleText = title;
|
|---|
| 640 | pixelColorUpToDate = false;
|
|---|
| 641 | if (isVisible())
|
|---|
| 642 | updateGL();
|
|---|
| 643 | }
|
|---|
| 644 | void QCameraWidget::linearScalePlease(bool checked)
|
|---|
| 645 | {
|
|---|
| 646 | if (!checked) return;
|
|---|
| 647 | logScale = false;
|
|---|
| 648 | pixelColorUpToDate = false;
|
|---|
| 649 | if (isVisible())
|
|---|
| 650 | updateGL();
|
|---|
| 651 | }
|
|---|
| 652 | void QCameraWidget::logScalePlease(bool checked)
|
|---|
| 653 | {
|
|---|
| 654 | if (!checked) return;
|
|---|
| 655 | logScale = true;
|
|---|
| 656 | pixelColorUpToDate = false;
|
|---|
| 657 | if (isVisible())
|
|---|
| 658 | updateGL();
|
|---|
| 659 | }
|
|---|
| 660 | void QCameraWidget::regularPalettePlease(bool checked)
|
|---|
| 661 | {
|
|---|
| 662 | if (!checked) return;
|
|---|
| 663 | ss[0] = 0; ss[1] = 0.25f; ss[2] = 0.5f; ss[3] = 0.75f; ss[4] = 1.0f;
|
|---|
| 664 | rr[0] = 0.15; rr[1] = 0; rr[2] = 0; rr[3] = 1.0f; rr[4] = 0.85f;
|
|---|
| 665 | gg[0] = 0.15; gg[1] = 0; gg[2] = 1; gg[3] = 0; gg[4] = 0.85f;
|
|---|
| 666 | bb[0] = 0.15; bb[1] = 1; bb[2] = 0; bb[3] = 0; bb[4] = 0.85f;
|
|---|
| 667 | tooHighValueCoulour[0] = 1.f;
|
|---|
| 668 | tooHighValueCoulour[1] = 1.f;
|
|---|
| 669 | tooHighValueCoulour[2] = 0.f;
|
|---|
| 670 | tooLowValueCoulour[0] = 0.f;
|
|---|
| 671 | tooLowValueCoulour[1] = 1.f;
|
|---|
| 672 | tooLowValueCoulour[2] = 1.f;
|
|---|
| 673 | pixelColorUpToDate = false;
|
|---|
| 674 | if (isVisible())
|
|---|
| 675 | updateGL();
|
|---|
| 676 | }
|
|---|
| 677 | void QCameraWidget::prettyPalettePlease(bool checked)
|
|---|
| 678 | {
|
|---|
| 679 | if (!checked) return;
|
|---|
| 680 | ss[0] = 0.f; ss[1] = 0.25f; ss[2] = 0.5f; ss[3] = 0.75f; ss[4] = 1.0f;
|
|---|
| 681 | rr[0] = 0.f; rr[1] = 0.35f; rr[2] = 0.85f; rr[3] = 1.0f; rr[4] = 1.f;
|
|---|
| 682 | gg[0] = 0.f; gg[1] = 0.10f; gg[2] = 0.20f; gg[3] = 0.73f; gg[4] = 1.f;
|
|---|
| 683 | bb[0] = 0.f; bb[1] = 0.03f; bb[2] = 0.06f; bb[3] = 0.00f; bb[4] = 1.f;
|
|---|
| 684 | tooHighValueCoulour[0] = 0.f;
|
|---|
| 685 | tooHighValueCoulour[1] = 1.f;
|
|---|
| 686 | tooHighValueCoulour[2] = 0.f;
|
|---|
| 687 | tooLowValueCoulour[0] = 0.f;
|
|---|
| 688 | tooLowValueCoulour[1] = 0.f;
|
|---|
| 689 | tooLowValueCoulour[2] = 1.f;
|
|---|
| 690 | pixelColorUpToDate = false;
|
|---|
| 691 | if (isVisible())
|
|---|
| 692 | updateGL();
|
|---|
| 693 | }
|
|---|
| 694 | void QCameraWidget::greyScalePalettePlease(bool checked)
|
|---|
| 695 | {
|
|---|
| 696 | if (!checked) return;
|
|---|
| 697 | ss[0] = 0; ss[1] = 0.25f; ss[2] = 0.5f; ss[3] = 0.75f; ss[4] = 1.0f;
|
|---|
| 698 | rr[0] = 0; rr[1] = 0.25f; rr[2] = 0.5f; rr[3] = 0.75f; rr[4] = 1.0f;
|
|---|
| 699 | gg[0] = 0; gg[1] = 0.25f; gg[2] = 0.5f; gg[3] = 0.75f; gg[4] = 1.0f;
|
|---|
| 700 | bb[0] = 0; bb[1] = 0.25f; bb[2] = 0.5f; bb[3] = 0.75f; bb[4] = 1.0f;
|
|---|
| 701 | tooHighValueCoulour[0] = 0.f;
|
|---|
| 702 | tooHighValueCoulour[1] = 1.f;
|
|---|
| 703 | tooHighValueCoulour[2] = 0.f;
|
|---|
| 704 | tooLowValueCoulour[0] = 0.f;
|
|---|
| 705 | tooLowValueCoulour[1] = 0.f;
|
|---|
| 706 | tooLowValueCoulour[2] = 1.f;
|
|---|
| 707 | pixelColorUpToDate = false;
|
|---|
| 708 | if (isVisible())
|
|---|
| 709 | updateGL();
|
|---|
| 710 | }
|
|---|
| 711 | void QCameraWidget::glowingPalettePlease(bool checked)
|
|---|
| 712 | {
|
|---|
| 713 | if (!checked) return;
|
|---|
| 714 | ss[0] = 0; ss[1] = 0.25f; ss[2] = 0.5f; ss[3] = 0.75f; ss[4] = 1.0f;
|
|---|
| 715 | rr[0] = 0.15; rr[1] = 0.5; rr[2] = 1.f; rr[3] = 0.0f; rr[4] = 1.f;
|
|---|
| 716 | gg[0] = 0.15; gg[1] = 0.5; gg[2] = 1.f; gg[3] = 0.5f; gg[4] = 0.5f;
|
|---|
| 717 | bb[0] = 0.15; bb[1] = 0.5; bb[2] = 1; bb[3] = 1.f; bb[4] = 0.f;
|
|---|
| 718 | tooHighValueCoulour[0] = 1.f;
|
|---|
| 719 | tooHighValueCoulour[1] = 0.f;
|
|---|
| 720 | tooHighValueCoulour[2] = 0.f;
|
|---|
| 721 | tooLowValueCoulour[0] = 0.f;
|
|---|
| 722 | tooLowValueCoulour[1] = 1.f;
|
|---|
| 723 | tooLowValueCoulour[2] = 0.f;
|
|---|
| 724 | pixelColorUpToDate = false;
|
|---|
| 725 | if (isVisible())
|
|---|
| 726 | updateGL();
|
|---|
| 727 | }
|
|---|
| 728 | void QCameraWidget::zeroRotationPlease(bool checked)
|
|---|
| 729 | {
|
|---|
| 730 | if (!checked) return;
|
|---|
| 731 | cameraRotation = 0;
|
|---|
| 732 | pixelColorUpToDate = false;
|
|---|
| 733 | if (isVisible())
|
|---|
| 734 | updateGL();
|
|---|
| 735 | }
|
|---|
| 736 | void QCameraWidget::plus90RotationPlease(bool checked)
|
|---|
| 737 | {
|
|---|
| 738 | if (!checked) return;
|
|---|
| 739 | cameraRotation = 90;
|
|---|
| 740 | pixelColorUpToDate = false;
|
|---|
| 741 | if (isVisible())
|
|---|
| 742 | updateGL();
|
|---|
| 743 | }
|
|---|
| 744 | void QCameraWidget::minus90RotationPlease(bool checked)
|
|---|
| 745 | {
|
|---|
| 746 | if (!checked) return;
|
|---|
| 747 | cameraRotation = -90;
|
|---|
| 748 | pixelColorUpToDate = false;
|
|---|
| 749 | if (isVisible())
|
|---|
| 750 | updateGL();
|
|---|
| 751 | }
|
|---|
| 752 | void QCameraWidget::highlightPixel(int idx)
|
|---|
| 753 | {
|
|---|
| 754 | if (idx < 0 || idx > ACTUAL_NUM_PIXELS)
|
|---|
| 755 | {
|
|---|
| 756 | cout << "Error: requested pixel highlight out of bounds" << endl;
|
|---|
| 757 | return;
|
|---|
| 758 | }
|
|---|
| 759 | highlightedPixels.push_back(idx);
|
|---|
| 760 | if (isVisible())
|
|---|
| 761 | updateGL();
|
|---|
| 762 | }
|
|---|
| 763 | void QCameraWidget::highlightPatch(int idx)
|
|---|
| 764 | {
|
|---|
| 765 | if (idx < 0 || idx > NTMARK)
|
|---|
| 766 | {
|
|---|
| 767 | cout << "Error: requested patch highlight out of bounds" << endl;
|
|---|
| 768 | return;
|
|---|
| 769 | }
|
|---|
| 770 | highlightedPatches.push_back(idx);
|
|---|
| 771 | if (isVisible())
|
|---|
| 772 | updateGL();
|
|---|
| 773 |
|
|---|
| 774 | }
|
|---|
| 775 | void QCameraWidget::clearHighlightedPatches()
|
|---|
| 776 | {
|
|---|
| 777 | highlightedPatches.clear();
|
|---|
| 778 | if (isVisible())
|
|---|
| 779 | updateGL();
|
|---|
| 780 | }
|
|---|
| 781 | void QCameraWidget::clearHighlightedPixels()
|
|---|
| 782 | {
|
|---|
| 783 | highlightedPixels.clear();
|
|---|
| 784 | if (isVisible())
|
|---|
| 785 | updateGL();
|
|---|
| 786 | }
|
|---|
| 787 |
|
|---|
| 788 |
|
|---|
| 789 |
|
|---|
| 790 |
|
|---|