Changeset 11874 for trunk/FACT++/gui/QCameraWidget.cc
- Timestamp:
- 08/10/11 14:41:07 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/gui/QCameraWidget.cc
r11865 r11874 14 14 fMax = -1; 15 15 lastFace = -1; 16 unitsText = ""; 17 titleText = "This is a title"; 18 dataText = ""; 19 logScale = false; 20 cameraRotation = 0; 16 21 CalculatePixelsColor(); 17 22 18 } 23 setFont(QFont("Arial", 8)); 24 int buttonShift=0; 25 scaleLabel = new QLabel("Scale", this); 26 // buttonShift += scaleLabel->height(); 27 28 linearButton = new QRadioButton("Linear", this); 29 linearButton->move(scaleLabel->width(), buttonShift); 30 buttonShift += linearButton->height(); 31 32 logButton = new QRadioButton("Log", this); 33 logButton->move(scaleLabel->width(), buttonShift); 34 buttonShift += logButton->height()*1.1f; 35 36 colorPaletteLabel = new QLabel("Colour\nPalette", this); 37 colorPaletteLabel->move(0, buttonShift); 38 // buttonShift += colorPaletteLabel->height(); 39 40 regularPaletteButton = new QRadioButton("Regular", this); 41 regularPaletteButton->move(colorPaletteLabel->width(), buttonShift); 42 buttonShift += regularPaletteButton->height(); 43 44 prettyPaletteButton = new QRadioButton("Pretty", this); 45 prettyPaletteButton->move(colorPaletteLabel->width(), buttonShift); 46 buttonShift += prettyPaletteButton->height(); 47 48 greyScalePaletteButton = new QRadioButton("Grey Scale", this); 49 greyScalePaletteButton->move(colorPaletteLabel->width(), buttonShift); 50 buttonShift += greyScalePaletteButton->height(); 51 52 glowingPaletteButton = new QRadioButton("Glowing", this); 53 glowingPaletteButton->move(colorPaletteLabel->width(), buttonShift); 54 buttonShift += glowingPaletteButton->height()*1.1f; 55 56 rotationLabel = new QLabel("Camera\nRotation", this); 57 rotationLabel->move(0, buttonShift); 58 // buttonShift += rotationLabel->height(); 59 60 zeroRotationButton = new QRadioButton("0°", this); 61 zeroRotationButton->move(rotationLabel->width(), buttonShift); 62 buttonShift += zeroRotationButton->height(); 63 64 minus90RotationButton = new QRadioButton("-90°", this); 65 minus90RotationButton->move(rotationLabel->width(), buttonShift); 66 buttonShift += minus90RotationButton->height(); 67 68 plus90Rotationbutton = new QRadioButton("+90°", this); 69 plus90Rotationbutton->move(rotationLabel->width(), buttonShift); 70 71 72 scaleGroup = new QButtonGroup(pparent); 73 colorGroup = new QButtonGroup(pparent); 74 rotationGroup = new QButtonGroup(pparent); 75 scaleGroup->addButton(linearButton); 76 scaleGroup->addButton(logButton); 77 colorGroup->addButton(regularPaletteButton); 78 colorGroup->addButton(prettyPaletteButton); 79 colorGroup->addButton(greyScalePaletteButton); 80 colorGroup->addButton(glowingPaletteButton); 81 rotationGroup->addButton(zeroRotationButton); 82 rotationGroup->addButton(minus90RotationButton); 83 rotationGroup->addButton(plus90Rotationbutton); 84 85 linearButton->setChecked(true); 86 regularPaletteButton->setChecked(true); 87 zeroRotationButton->setChecked(true); 88 89 // linearButton->palette.setColor(); 90 91 linearButton->setAutoFillBackground(true); 92 logButton->setAutoFillBackground(true); 93 regularPaletteButton->setAutoFillBackground(true); 94 prettyPaletteButton->setAutoFillBackground(true); 95 greyScalePaletteButton->setAutoFillBackground(true); 96 glowingPaletteButton->setAutoFillBackground(true); 97 zeroRotationButton->setAutoFillBackground(true); 98 minus90RotationButton->setAutoFillBackground(true); 99 plus90Rotationbutton->setAutoFillBackground(true); 100 scaleLabel->setAutoFillBackground(true); 101 colorPaletteLabel->setAutoFillBackground(true); 102 rotationLabel->setAutoFillBackground(true); 103 104 linearButton->hide(); 105 logButton->hide(); 106 regularPaletteButton->hide(); 107 prettyPaletteButton->hide(); 108 greyScalePaletteButton->hide(); 109 glowingPaletteButton->hide(); 110 zeroRotationButton->hide(); 111 minus90RotationButton->hide(); 112 plus90Rotationbutton->hide(); 113 scaleLabel->hide(); 114 colorPaletteLabel->hide(); 115 rotationLabel->hide(); 116 117 connect(linearButton, SIGNAL(toggled(bool)), 118 this, SLOT(linearScalePlease(bool))); 119 connect(logButton, SIGNAL(toggled(bool)), 120 this, SLOT(logScalePlease(bool))); 121 connect(regularPaletteButton, SIGNAL(toggled(bool)), 122 this, SLOT(regularPalettePlease(bool))); 123 connect(prettyPaletteButton, SIGNAL(toggled(bool)), 124 this, SLOT(prettyPalettePlease(bool))); 125 connect(greyScalePaletteButton, SIGNAL(toggled(bool)), 126 this, SLOT(greyScalePalettePlease(bool))); 127 connect(glowingPaletteButton, SIGNAL(toggled(bool)), 128 this, SLOT(glowingPalettePlease(bool))); 129 connect(zeroRotationButton, SIGNAL(toggled(bool)), 130 this, SLOT(zeroRotationPlease(bool))); 131 connect(minus90RotationButton, SIGNAL(toggled(bool)), 132 this, SLOT(plus90RotationPlease(bool))); 133 connect(plus90Rotationbutton, SIGNAL(toggled(bool)), 134 this, SLOT(minus90RotationPlease(bool))); 135 136 137 138 } 139 19 140 void QCameraWidget::paintGL() 20 141 { … … 23 144 24 145 glTranslatef(0,-0.44,0); 146 glRotatef(cameraRotation, 0,0,-1); 147 if (cameraRotation == 90) 148 { 149 glTranslatef(-0.45,-0.45,0); 150 // cout << "correction" << endl; 151 } 152 if (cameraRotation == -90) 153 { 154 glTranslatef(0.45,-0.45,0); 155 } 25 156 glScalef(1.5, 1.5, 1.5); 26 157 drawCamera(true); … … 32 163 33 164 DrawCameraText(); 165 166 DrawScale(); 167 168 // if (linearButton->isVisible()) 169 // repaintInterface(); 34 170 } 35 171 void QCameraWidget::drawCamera(bool alsoWire) … … 71 207 fBold.assign(1440, false); 72 208 } 209 void QCameraWidget::toggleInterfaceDisplay() 210 { 211 if (linearButton->isVisible()) 212 { 213 linearButton->hide(); 214 logButton->hide(); 215 regularPaletteButton->hide(); 216 prettyPaletteButton->hide(); 217 greyScalePaletteButton->hide(); 218 glowingPaletteButton->hide(); 219 zeroRotationButton->hide(); 220 minus90RotationButton->hide(); 221 plus90Rotationbutton->hide(); 222 scaleLabel->hide(); 223 colorPaletteLabel->hide(); 224 rotationLabel->hide(); 225 } 226 else 227 { 228 linearButton->show(); 229 logButton->show(); 230 regularPaletteButton->show(); 231 prettyPaletteButton->show(); 232 greyScalePaletteButton->show(); 233 glowingPaletteButton->show(); 234 zeroRotationButton->show(); 235 minus90RotationButton->show(); 236 plus90Rotationbutton->show(); 237 scaleLabel->show(); 238 colorPaletteLabel->show(); 239 rotationLabel->show(); 240 } 241 } 242 void QCameraWidget::repaintInterface() 243 { 244 return; 245 setFont(QFont("Arial", 10)); 246 // glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 247 linearButton->render(this); 248 logButton->render(this); 249 regularPaletteButton->render(this); 250 prettyPaletteButton->render(this); 251 greyScalePaletteButton->render(this); 252 glowingPaletteButton->render(this); 253 zeroRotationButton->render(this); 254 minus90RotationButton->render(this); 255 plus90Rotationbutton->render(this); 256 // scaleLabel->repaint(); 257 colorPaletteLabel->render(this); 258 rotationLabel->render(this); 259 260 scaleLabel->render(this); 261 // cout << scaleLabel->autoFillBackground() << endl; 262 } 73 263 void QCameraWidget::mousePressEvent(QMouseEvent *cEvent) 74 264 { 265 if (cEvent->pos().x() > width()-(width()/50.f)) 266 { 267 toggleInterfaceDisplay(); 268 return; 269 } 75 270 int face = PixelAtPosition(cEvent->pos()); 76 271 if (face != -1) { … … 180 375 } 181 376 color = float((fData[i]-dmin)/(dmax-dmin)); 377 if (logScale) 378 { 379 color *= 9; 380 color += 1; 381 color = log(color); 382 } 182 383 if (!fEnable[i]) 183 384 color = 0; … … 196 397 } 197 398 CalculatePatchColor(); 399 UpdateText(); 198 400 pixelColorUpToDate = true; 199 401 } … … 219 421 updateGL(); 220 422 } 423 void QCameraWidget::UpdateText() 424 { 425 ostringstream str; 426 float min, max, mean, rms, median; 427 min = max = fData[0]; 428 mean = 0; 429 rms = 0; 430 median = 0; 431 set<float> medianSet; 432 for (int i=0;i<ACTUAL_NUM_PIXELS;i++) 433 { 434 if (fData[i] < min) 435 min = fData[i]; 436 if (fData[i] > max) 437 max = fData[i]; 438 mean += fData[i]; 439 rms += fData[i]*fData[i]; 440 medianSet.insert((float)(fData[i])); 441 } 442 mean /= ACTUAL_NUM_PIXELS; 443 rms /= ACTUAL_NUM_PIXELS; 444 rms = sqrt(rms); 445 set<float>::iterator it = medianSet.begin(); 446 for (int i=0;i<(ACTUAL_NUM_PIXELS/2)-1;i++) 447 it++; 448 median = *it; 449 it++; 450 median += *it; 451 median /= 2; 452 453 str << "Min: " << min << " Max: " << max << " Mean: " << mean << " RMS: " << rms << " Median: " << median; 454 str << " Units: " << unitsText; 455 dataText = str.str(); 456 } 221 457 void QCameraWidget::DrawCameraText() 222 458 { 223 459 glPushMatrix(); 224 460 glLoadIdentity(); 225 cout << width() << " " << height() << endl;461 // cout << width() << " " << height() << endl; 226 462 int textSize = (int)(height()*14/600); 227 463 setFont(QFont("Times", textSize)); … … 229 465 float shiftx = 0.01f;//0.55f; 230 466 float shifty = 0.01f;//0.65f; 231 renderText(-shownSizex/2.f + shiftx, -shownSizey/2.f + shifty, 0.f, QString("This is a first text that is scaled according to the drawing size")); 467 renderText(-shownSizex/2.f + shiftx, -shownSizey/2.f + shifty, 0.f, QString(dataText.c_str())); 468 469 470 int textLength = titleText.size(); 471 renderText(-shownSizex/2.f + shiftx, shownSizey/2.f - textSize*pixelSize - shifty, 0.f, QString(titleText.c_str())); 472 232 473 glPopMatrix(); 233 474 } 475 void QCameraWidget::DrawScale() 476 { 477 glPushMatrix(); 478 glLoadIdentity(); 479 glPushAttrib(GL_POLYGON_BIT); 480 glShadeModel(GL_SMOOTH); 481 glBegin(GL_QUADS); 482 float oneX = shownSizex/2.f - shownSizex/50.f; 483 float twoX = shownSizex/2.f; 484 float oneY = -shownSizey/2.f; 485 float twoY = -shownSizey/4.f; 486 float threeY = 0; 487 float fourY = shownSizey/4.f; 488 float fiveY = shownSizey/2.f; 489 glColor3f(rr[0], gg[0], bb[0]); 490 glVertex2f(oneX, oneY); 491 glVertex2f(twoX, oneY); 492 glColor3f(rr[1], gg[1], bb[1]); 493 glVertex2f(twoX, twoY); 494 glVertex2f(oneX, twoY); 495 496 glVertex2f(oneX, twoY); 497 glVertex2f(twoX, twoY); 498 glColor3f(rr[2], gg[2], bb[2]); 499 glVertex2f(twoX, threeY); 500 glVertex2f(oneX, threeY); 501 502 glVertex2f(oneX, threeY); 503 glVertex2f(twoX, threeY); 504 glColor3f(rr[3], gg[3], bb[3]); 505 glVertex2f(twoX, fourY); 506 glVertex2f(oneX, fourY); 507 508 glVertex2f(oneX, fourY); 509 glVertex2f(twoX, fourY); 510 glColor3f(rr[4], gg[4], bb[4]); 511 glVertex2f(twoX, fiveY); 512 glVertex2f(oneX, fiveY); 513 514 glEnd(); 515 glPopAttrib(); 516 glPopMatrix(); 517 } 518 void QCameraWidget::setUnits(string& units) 519 { 520 unitsText = units; 521 } 522 void QCameraWidget::setTitle(string& title) 523 { 524 titleText = title; 525 } 526 void QCameraWidget::linearScalePlease(bool checked) 527 { 528 if (!checked) return; 529 logScale = false; 530 pixelColorUpToDate = false; 531 if (isVisible()) 532 updateGL(); 533 } 534 void QCameraWidget::logScalePlease(bool checked) 535 { 536 if (!checked) return; 537 logScale = true; 538 pixelColorUpToDate = false; 539 if (isVisible()) 540 updateGL(); 541 } 542 void QCameraWidget::regularPalettePlease(bool checked) 543 { 544 if (!checked) return; 545 ss[0] = 0; ss[1] = 0.25f; ss[2] = 0.5f; ss[3] = 0.75f; ss[4] = 1.0f; 546 rr[0] = 0.15; rr[1] = 0; rr[2] = 0; rr[3] = 1.0f; rr[4] = 0.85f; 547 gg[0] = 0.15; gg[1] = 0; gg[2] = 1; gg[3] = 0; gg[4] = 0.85f; 548 bb[0] = 0.15; bb[1] = 1; bb[2] = 0; bb[3] = 0; bb[4] = 0.85f; 549 pixelColorUpToDate = false; 550 if (isVisible()) 551 updateGL(); 552 } 553 void QCameraWidget::prettyPalettePlease(bool checked) 554 { 555 if (!checked) return; 556 ss[0] = 0.f; ss[1] = 0.25f; ss[2] = 0.5f; ss[3] = 0.75f; ss[4] = 1.0f; 557 rr[0] = 0.f; rr[1] = 0.35f; rr[2] = 0.85f; rr[3] = 1.0f; rr[4] = 1.f; 558 gg[0] = 0.f; gg[1] = 0.10f; gg[2] = 0.20f; gg[3] = 0.73f; gg[4] = 1.f; 559 bb[0] = 0.f; bb[1] = 0.03f; bb[2] = 0.06f; bb[3] = 0.00f; bb[4] = 1.f; 560 pixelColorUpToDate = false; 561 if (isVisible()) 562 updateGL(); 563 } 564 void QCameraWidget::greyScalePalettePlease(bool checked) 565 { 566 if (!checked) return; 567 ss[0] = 0; ss[1] = 0.25f; ss[2] = 0.5f; ss[3] = 0.75f; ss[4] = 1.0f; 568 rr[0] = 0; rr[1] = 0.25f; rr[2] = 0.5f; rr[3] = 0.75f; rr[4] = 1.0f; 569 gg[0] = 0; gg[1] = 0.25f; gg[2] = 0.5f; gg[3] = 0.75f; gg[4] = 1.0f; 570 bb[0] = 0; bb[1] = 0.25f; bb[2] = 0.5f; bb[3] = 0.75f; bb[4] = 1.0f; 571 pixelColorUpToDate = false; 572 if (isVisible()) 573 updateGL(); 574 } 575 void QCameraWidget::glowingPalettePlease(bool checked) 576 { 577 if (!checked) return; 578 ss[0] = 0; ss[1] = 0.25f; ss[2] = 0.5f; ss[3] = 0.75f; ss[4] = 1.0f; 579 rr[0] = 0.15; rr[1] = 0.5; rr[2] = 1.f; rr[3] = 0.0f; rr[4] = 1.f; 580 gg[0] = 0.15; gg[1] = 0.5; gg[2] = 1.f; gg[3] = 0.5f; gg[4] = 0.5f; 581 bb[0] = 0.15; bb[1] = 0.5; bb[2] = 1; bb[3] = 1.f; bb[4] = 0.f; 582 pixelColorUpToDate = false; 583 if (isVisible()) 584 updateGL(); 585 } 586 void QCameraWidget::zeroRotationPlease(bool checked) 587 { 588 if (!checked) return; 589 cameraRotation = 0; 590 pixelColorUpToDate = false; 591 if (isVisible()) 592 updateGL(); 593 } 594 void QCameraWidget::plus90RotationPlease(bool checked) 595 { 596 if (!checked) return; 597 cameraRotation = 90; 598 pixelColorUpToDate = false; 599 if (isVisible()) 600 updateGL(); 601 } 602 void QCameraWidget::minus90RotationPlease(bool checked) 603 { 604 if (!checked) return; 605 cameraRotation = -90; 606 pixelColorUpToDate = false; 607 if (isVisible()) 608 updateGL(); 609 }
Note:
See TracChangeset
for help on using the changeset viewer.