Changeset 11901 for trunk/FACT++/gui
- Timestamp:
- 08/12/11 16:23:54 (13 years ago)
- Location:
- trunk/FACT++/gui
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/gui/BasicGlCamera.cc
r11894 r11901 20 20 { 21 21 setFormat(QGLFormat(QGL::DoubleBuffer));// | QGL::DepthBuffer)); 22 fWhite = -1; 23 fWhitePatch = -1; 24 fMin = -1; 25 fMax = -1; 26 logScale = false; 27 cameraRotation = 0; 28 unitsText = ""; 29 titleText = ""; 30 dataText = ""; 31 pixelContourColour[0] = 0.1f; 32 pixelContourColour[1] = 0.1f; 33 pixelContourColour[2] = 0.1f; 34 patchesCoulour[0] = 0.1f; 35 patchesCoulour[1] = 0.1f; 36 patchesCoulour[2] = 0.1f; 37 highlightedPatchesCoulour[0] = 0.6f; 38 highlightedPatchesCoulour[1] = 0.6f; 39 highlightedPatchesCoulour[2] = 0.6f; 40 highlightedPixelsCoulour[0] = 0.8f; 41 highlightedPixelsCoulour[1] = 0.8f; 42 highlightedPixelsCoulour[2] = 0.8f; 43 44 regularPalettePlease(true); 45 46 22 47 hexRadius = 0.015f; 23 48 hexTolerance = hexRadius/100.0f; … … 108 133 fcSlice = 0; 109 134 fData.resize(1440); 135 for (int i=0;i<ACTUAL_NUM_PIXELS+2;i++) 136 fData[i] = (double)i;///1.44;//(double)(i)/(double)(ACTUAL_NUM_PIXELS); 137 138 139 setFont(QFont("Arial", 8)); 140 int buttonShift=0; 141 scaleLabel = new QLabel("Scale", this); 142 // buttonShift += scaleLabel->height(); 143 144 linearButton = new QRadioButton("Linear", this); 145 linearButton->move(scaleLabel->width(), buttonShift); 146 buttonShift += linearButton->height(); 147 148 logButton = new QRadioButton("Log", this); 149 logButton->move(scaleLabel->width(), buttonShift); 150 buttonShift += logButton->height()*1.1f; 151 152 colorPaletteLabel = new QLabel("Colour\nPalette", this); 153 colorPaletteLabel->move(0, buttonShift); 154 // buttonShift += colorPaletteLabel->height(); 155 156 regularPaletteButton = new QRadioButton("Regular", this); 157 regularPaletteButton->move(colorPaletteLabel->width(), buttonShift); 158 buttonShift += regularPaletteButton->height(); 159 160 prettyPaletteButton = new QRadioButton("Pretty", this); 161 prettyPaletteButton->move(colorPaletteLabel->width(), buttonShift); 162 buttonShift += prettyPaletteButton->height(); 163 164 greyScalePaletteButton = new QRadioButton("Grey Scale", this); 165 greyScalePaletteButton->move(colorPaletteLabel->width(), buttonShift); 166 buttonShift += greyScalePaletteButton->height(); 167 168 glowingPaletteButton = new QRadioButton("Glowing", this); 169 glowingPaletteButton->move(colorPaletteLabel->width(), buttonShift); 170 buttonShift += glowingPaletteButton->height()*1.1f; 171 172 rotationLabel = new QLabel("Camera\nRotation", this); 173 rotationLabel->move(0, buttonShift); 174 // buttonShift += rotationLabel->height(); 175 176 unsigned short utf16Array; 177 utf16Array = 0x00b0; 178 QString degreeSymbol(QString::fromUtf16(&utf16Array, 1)); 179 QString zerostr("0" + degreeSymbol); 180 zeroRotationButton = new QRadioButton(zerostr, this); 181 zeroRotationButton->move(rotationLabel->width(), buttonShift); 182 buttonShift += zeroRotationButton->height(); 183 QString minus90str("-90" + degreeSymbol); 184 minus90RotationButton = new QRadioButton(minus90str, this); 185 minus90RotationButton->move(rotationLabel->width(), buttonShift); 186 buttonShift += minus90RotationButton->height(); 187 QString plus90str("+90"+degreeSymbol); 188 plus90Rotationbutton = new QRadioButton(plus90str, this); 189 plus90Rotationbutton->move(rotationLabel->width(), buttonShift); 190 191 192 scaleGroup = new QButtonGroup(this); 193 colorGroup = new QButtonGroup(this); 194 rotationGroup = new QButtonGroup(this); 195 scaleGroup->addButton(linearButton); 196 scaleGroup->addButton(logButton); 197 colorGroup->addButton(regularPaletteButton); 198 colorGroup->addButton(prettyPaletteButton); 199 colorGroup->addButton(greyScalePaletteButton); 200 colorGroup->addButton(glowingPaletteButton); 201 rotationGroup->addButton(zeroRotationButton); 202 rotationGroup->addButton(minus90RotationButton); 203 rotationGroup->addButton(plus90Rotationbutton); 204 205 linearButton->setChecked(true); 206 regularPaletteButton->setChecked(true); 207 zeroRotationButton->setChecked(true); 208 209 // linearButton->palette.setColor(); 210 211 linearButton->setAutoFillBackground(true); 212 logButton->setAutoFillBackground(true); 213 regularPaletteButton->setAutoFillBackground(true); 214 prettyPaletteButton->setAutoFillBackground(true); 215 greyScalePaletteButton->setAutoFillBackground(true); 216 glowingPaletteButton->setAutoFillBackground(true); 217 zeroRotationButton->setAutoFillBackground(true); 218 minus90RotationButton->setAutoFillBackground(true); 219 plus90Rotationbutton->setAutoFillBackground(true); 220 scaleLabel->setAutoFillBackground(true); 221 colorPaletteLabel->setAutoFillBackground(true); 222 rotationLabel->setAutoFillBackground(true); 223 224 linearButton->hide(); 225 logButton->hide(); 226 regularPaletteButton->hide(); 227 prettyPaletteButton->hide(); 228 greyScalePaletteButton->hide(); 229 glowingPaletteButton->hide(); 230 zeroRotationButton->hide(); 231 minus90RotationButton->hide(); 232 plus90Rotationbutton->hide(); 233 scaleLabel->hide(); 234 colorPaletteLabel->hide(); 235 rotationLabel->hide(); 236 237 connect(linearButton, SIGNAL(toggled(bool)), 238 this, SLOT(linearScalePlease(bool))); 239 connect(logButton, SIGNAL(toggled(bool)), 240 this, SLOT(logScalePlease(bool))); 241 connect(regularPaletteButton, SIGNAL(toggled(bool)), 242 this, SLOT(regularPalettePlease(bool))); 243 connect(prettyPaletteButton, SIGNAL(toggled(bool)), 244 this, SLOT(prettyPalettePlease(bool))); 245 connect(greyScalePaletteButton, SIGNAL(toggled(bool)), 246 this, SLOT(greyScalePalettePlease(bool))); 247 connect(glowingPaletteButton, SIGNAL(toggled(bool)), 248 this, SLOT(glowingPalettePlease(bool))); 249 connect(zeroRotationButton, SIGNAL(toggled(bool)), 250 this, SLOT(zeroRotationPlease(bool))); 251 connect(minus90RotationButton, SIGNAL(toggled(bool)), 252 this, SLOT(plus90RotationPlease(bool))); 253 connect(plus90Rotationbutton, SIGNAL(toggled(bool)), 254 this, SLOT(minus90RotationPlease(bool))); 255 256 257 258 } 259 BasicGlCamera::~BasicGlCamera() 260 { 261 } 262 void BasicGlCamera::setUnits(const string& units) 263 { 264 unitsText = units; 265 pixelColorUpToDate = false; 266 if (isVisible()) 267 updateGL(); 268 } 269 void BasicGlCamera::setTitle(const string& title) 270 { 271 titleText = title; 272 pixelColorUpToDate = false; 273 if (isVisible()) 274 updateGL(); 275 } 276 void BasicGlCamera::SetWhite(int idx) 277 { 278 fWhite = idx; 279 fWhitePatch = pixelsPatch[fWhite]; 280 if (isVisible()) 281 updateGL(); 282 // CalculatePatchColor(); 283 } 284 void BasicGlCamera::SetMin(int64_t min) 285 { 286 // cout << "min: " << min << endl; 287 fMin = min; 288 pixelColorUpToDate = false; 289 if (isVisible()) 290 updateGL(); 291 } 292 void BasicGlCamera::SetMax(int64_t max) 293 { 294 // cout << "max: " << max << endl; 295 fMax = max; 296 pixelColorUpToDate = false; 297 if (isVisible()) 298 updateGL(); 299 } 300 void BasicGlCamera::linearScalePlease(bool checked) 301 { 302 if (!checked) return; 303 logScale = false; 304 pixelColorUpToDate = false; 305 emit colorPaletteHasChanged(); 306 if (isVisible()) 307 updateGL(); 308 } 309 void BasicGlCamera::UpdateText() 310 { 311 ostringstream str; 312 float min, max, mean, rms, median; 313 min = max = fData[0]; 314 mean = 0; 315 rms = 0; 316 median = 0; 317 multiset<double> medianSet; 110 318 for (int i=0;i<ACTUAL_NUM_PIXELS;i++) 111 fData[i] = (double)i;///1.44;//(double)(i)/(double)(ACTUAL_NUM_PIXELS); 112 } 113 BasicGlCamera::~BasicGlCamera() 114 { 319 { 320 if (fData[i] < min) 321 min = fData[i]; 322 if (fData[i] > max) 323 max = fData[i]; 324 mean += fData[i]; 325 rms += fData[i]*fData[i]; 326 medianSet.insert(fData[i]); 327 } 328 mean /= ACTUAL_NUM_PIXELS; 329 rms /= ACTUAL_NUM_PIXELS; 330 rms = sqrt(rms); 331 // cout << "Size of the set: " << medianSet.size() << endl; 332 multiset<double>::iterator it = medianSet.begin(); 333 for (int i=0;i<(ACTUAL_NUM_PIXELS/2)-1;i++) 334 it++; 335 median = *it; 336 it++; 337 median += *it; 338 median /= 2; 339 340 str << "Min: " << min << " Max: " << max << " Mean: " << mean << " RMS: " << rms << " Median: " << median; 341 str << " Units: " << unitsText; 342 dataText = str.str(); 343 } 344 void BasicGlCamera::DrawCameraText() 345 { 346 glPushMatrix(); 347 glLoadIdentity(); 348 // cout << width() << " " << height() << endl; 349 int textSize = (int)(height()*14/600); 350 setFont(QFont("Times", textSize)); 351 qglColor(QColor(255,223,127)); 352 float shiftx = 0.01f;//0.55f; 353 float shifty = 0.01f;//0.65f; 354 renderText(-shownSizex/2.f + shiftx, -shownSizey/2.f + shifty, 0.f, QString(dataText.c_str())); 355 356 357 int textLength = titleText.size(); 358 renderText(-shownSizex/2.f + shiftx, shownSizey/2.f - textSize*pixelSize - shifty, 0.f, QString(titleText.c_str())); 359 360 glPopMatrix(); 361 } 362 void BasicGlCamera::DrawScale() 363 { 364 glPushMatrix(); 365 glLoadIdentity(); 366 glPushAttrib(GL_POLYGON_BIT); 367 glShadeModel(GL_SMOOTH); 368 glBegin(GL_QUADS); 369 float oneX = shownSizex/2.f - shownSizex/50.f; 370 float twoX = shownSizex/2.f; 371 float oneY = -shownSizey/2.f; 372 float twoY = -shownSizey/4.f; 373 float threeY = 0; 374 float fourY = shownSizey/4.f; 375 float fiveY = shownSizey/2.f; 376 glColor3f(rr[0], gg[0], bb[0]); 377 glVertex2f(oneX, oneY); 378 glVertex2f(twoX, oneY); 379 glColor3f(rr[1], gg[1], bb[1]); 380 glVertex2f(twoX, twoY); 381 glVertex2f(oneX, twoY); 382 383 glVertex2f(oneX, twoY); 384 glVertex2f(twoX, twoY); 385 glColor3f(rr[2], gg[2], bb[2]); 386 glVertex2f(twoX, threeY); 387 glVertex2f(oneX, threeY); 388 389 glVertex2f(oneX, threeY); 390 glVertex2f(twoX, threeY); 391 glColor3f(rr[3], gg[3], bb[3]); 392 glVertex2f(twoX, fourY); 393 glVertex2f(oneX, fourY); 394 395 glVertex2f(oneX, fourY); 396 glVertex2f(twoX, fourY); 397 glColor3f(rr[4], gg[4], bb[4]); 398 glVertex2f(twoX, fiveY); 399 glVertex2f(oneX, fiveY); 400 float zeroX = oneX - shownSizex/50.f; 401 float zeroY = fiveY - shownSizey/50.f; 402 glColor3fv(tooHighValueCoulour); 403 glVertex2f(zeroX, fiveY); 404 glVertex2f(oneX, fiveY); 405 glVertex2f(oneX, zeroY); 406 glVertex2f(zeroX, zeroY); 407 glColor3fv(tooLowValueCoulour); 408 glVertex2f(zeroX, -fiveY); 409 glVertex2f(oneX, -fiveY); 410 glVertex2f(oneX, -zeroY); 411 glVertex2f(zeroX, -zeroY); 412 glEnd(); 413 //draw linear/log tick marks 414 glColor3f(0.f,0.f,0.f); 415 glBegin(GL_LINES); 416 float value; 417 for (int i=1;i<10;i++) 418 { 419 if (logScale) 420 value = log10(i); 421 else 422 value = (float)(i)/10.f; 423 float y = -shownSizey/2.f + value*shownSizey; 424 glVertex2f(oneX, y); 425 glVertex2f(twoX, y); 426 } 427 glEnd(); 428 glPopAttrib(); 429 glPopMatrix(); 430 } 431 void BasicGlCamera::logScalePlease(bool checked) 432 { 433 if (!checked) return; 434 logScale = true; 435 pixelColorUpToDate = false; 436 emit colorPaletteHasChanged(); 437 if (isVisible()) 438 updateGL(); 439 } 440 void BasicGlCamera::regularPalettePlease(bool checked) 441 { 442 if (!checked) return; 443 ss[0] = 0; ss[1] = 0.25f; ss[2] = 0.5f; ss[3] = 0.75f; ss[4] = 1.0f; 444 rr[0] = 0.15; rr[1] = 0; rr[2] = 0; rr[3] = 1.0f; rr[4] = 0.85f; 445 gg[0] = 0.15; gg[1] = 0; gg[2] = 1; gg[3] = 0; gg[4] = 0.85f; 446 bb[0] = 0.15; bb[1] = 1; bb[2] = 0; bb[3] = 0; bb[4] = 0.85f; 447 tooHighValueCoulour[0] = 1.f; 448 tooHighValueCoulour[1] = 1.f; 449 tooHighValueCoulour[2] = 0.f; 450 tooLowValueCoulour[0] = 0.f; 451 tooLowValueCoulour[1] = 1.f; 452 tooLowValueCoulour[2] = 1.f; 453 pixelColorUpToDate = false; 454 455 emit colorPaletteHasChanged(); 456 457 if (isVisible()) 458 updateGL(); 459 } 460 void BasicGlCamera::prettyPalettePlease(bool checked) 461 { 462 if (!checked) return; 463 ss[0] = 0.f; ss[1] = 0.25f; ss[2] = 0.5f; ss[3] = 0.75f; ss[4] = 1.0f; 464 rr[0] = 0.f; rr[1] = 0.35f; rr[2] = 0.85f; rr[3] = 1.0f; rr[4] = 1.f; 465 gg[0] = 0.f; gg[1] = 0.10f; gg[2] = 0.20f; gg[3] = 0.73f; gg[4] = 1.f; 466 bb[0] = 0.f; bb[1] = 0.03f; bb[2] = 0.06f; bb[3] = 0.00f; bb[4] = 1.f; 467 tooHighValueCoulour[0] = 0.f; 468 tooHighValueCoulour[1] = 1.f; 469 tooHighValueCoulour[2] = 0.f; 470 tooLowValueCoulour[0] = 0.f; 471 tooLowValueCoulour[1] = 0.f; 472 tooLowValueCoulour[2] = 1.f; 473 pixelColorUpToDate = false; 474 475 emit colorPaletteHasChanged(); 476 477 if (isVisible()) 478 updateGL(); 479 } 480 void BasicGlCamera::greyScalePalettePlease(bool checked) 481 { 482 if (!checked) return; 483 ss[0] = 0; ss[1] = 0.25f; ss[2] = 0.5f; ss[3] = 0.75f; ss[4] = 1.0f; 484 rr[0] = 0; rr[1] = 0.25f; rr[2] = 0.5f; rr[3] = 0.75f; rr[4] = 1.0f; 485 gg[0] = 0; gg[1] = 0.25f; gg[2] = 0.5f; gg[3] = 0.75f; gg[4] = 1.0f; 486 bb[0] = 0; bb[1] = 0.25f; bb[2] = 0.5f; bb[3] = 0.75f; bb[4] = 1.0f; 487 tooHighValueCoulour[0] = 0.f; 488 tooHighValueCoulour[1] = 1.f; 489 tooHighValueCoulour[2] = 0.f; 490 tooLowValueCoulour[0] = 0.f; 491 tooLowValueCoulour[1] = 0.f; 492 tooLowValueCoulour[2] = 1.f; 493 pixelColorUpToDate = false; 494 495 emit colorPaletteHasChanged(); 496 497 if (isVisible()) 498 updateGL(); 499 } 500 void BasicGlCamera::glowingPalettePlease(bool checked) 501 { 502 if (!checked) return; 503 ss[0] = 0; ss[1] = 0.25f; ss[2] = 0.5f; ss[3] = 0.75f; ss[4] = 1.0f; 504 rr[0] = 0.15; rr[1] = 0.5; rr[2] = 1.f; rr[3] = 0.0f; rr[4] = 1.f; 505 gg[0] = 0.15; gg[1] = 0.5; gg[2] = 1.f; gg[3] = 0.5f; gg[4] = 0.5f; 506 bb[0] = 0.15; bb[1] = 0.5; bb[2] = 1; bb[3] = 1.f; bb[4] = 0.f; 507 tooHighValueCoulour[0] = 1.f; 508 tooHighValueCoulour[1] = 0.f; 509 tooHighValueCoulour[2] = 0.f; 510 tooLowValueCoulour[0] = 0.f; 511 tooLowValueCoulour[1] = 1.f; 512 tooLowValueCoulour[2] = 0.f; 513 pixelColorUpToDate = false; 514 515 emit colorPaletteHasChanged(); 516 517 if (isVisible()) 518 updateGL(); 519 } 520 void BasicGlCamera::zeroRotationPlease(bool checked) 521 { 522 if (!checked) return; 523 cameraRotation = 0; 524 pixelColorUpToDate = false; 525 if (isVisible()) 526 updateGL(); 527 } 528 void BasicGlCamera::plus90RotationPlease(bool checked) 529 { 530 if (!checked) return; 531 cameraRotation = 90; 532 pixelColorUpToDate = false; 533 if (isVisible()) 534 updateGL(); 535 } 536 void BasicGlCamera::minus90RotationPlease(bool checked) 537 { 538 if (!checked) return; 539 cameraRotation = -90; 540 pixelColorUpToDate = false; 541 if (isVisible()) 542 updateGL(); 115 543 } 116 544 … … 125 553 glEnable (GL_BLEND); 126 554 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 127 glHint (GL_LINE_SMOOTH_HINT, GL_ DONT_CARE);555 glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); 128 556 129 557 } … … 163 591 drawPatches(); 164 592 } 593 void BasicGlCamera::toggleInterfaceDisplay() 594 { 595 if (linearButton->isVisible()) 596 { 597 linearButton->hide(); 598 logButton->hide(); 599 regularPaletteButton->hide(); 600 prettyPaletteButton->hide(); 601 greyScalePaletteButton->hide(); 602 glowingPaletteButton->hide(); 603 zeroRotationButton->hide(); 604 minus90RotationButton->hide(); 605 plus90Rotationbutton->hide(); 606 scaleLabel->hide(); 607 colorPaletteLabel->hide(); 608 rotationLabel->hide(); 609 } 610 else 611 { 612 linearButton->show(); 613 logButton->show(); 614 regularPaletteButton->show(); 615 prettyPaletteButton->show(); 616 greyScalePaletteButton->show(); 617 glowingPaletteButton->show(); 618 zeroRotationButton->show(); 619 minus90RotationButton->show(); 620 plus90Rotationbutton->show(); 621 scaleLabel->show(); 622 colorPaletteLabel->show(); 623 rotationLabel->show(); 624 } 625 } 626 165 627 void BasicGlCamera::mousePressEvent(QMouseEvent *cEvent) 166 628 { … … 369 831 for (int i=2;i<MAX_NUM_PIXELS;i++) 370 832 { 833 // cout << "i " << i << endl; 371 834 toSide = fromSide-1; 372 835 if (toSide < 0) -
trunk/FACT++/gui/BasicGlCamera.h
r11874 r11901 12 12 #include <QtGui/QMouseEvent> 13 13 #include <vector> 14 15 #include <QtGui/QRadioButton> 16 #include <QtGui/QLabel> 17 #include <QtGui/QButtonGroup> 18 19 #include <set> 14 20 15 21 using namespace std; … … 43 49 ~BasicGlCamera(); 44 50 51 int fWhite; 52 int fWhitePatch; 53 54 int64_t fMin; 55 int64_t fMax; 56 57 bool pixelColorUpToDate; 58 59 GLfloat patchColour[3]; 60 GLfloat pixelContourColour[3]; 61 GLfloat patchesCoulour[3]; 62 GLfloat highlightedPatchesCoulour[3]; 63 GLfloat highlightedPixelsCoulour[3]; 64 GLfloat tooHighValueCoulour[3]; 65 GLfloat tooLowValueCoulour[3]; 66 67 string dataText; 68 string unitsText; 69 string titleText; 70 71 void setUnits(const string& units); 72 void setTitle(const string& title); 73 void SetWhite(int idx); 74 void SetMin(int64_t min); 75 void SetMax(int64_t max); 76 77 float ss[5];// = {0.00, 0.25, 0.5, 0.75, 1.00}; 78 float rr[5];// = {0.15, 0.00, 0.00, 1.00, 0.85}; 79 float gg[5];// = {0.15, 0.00, 1.00, 0.00, 0.85}; 80 float bb[5];// = {0.15, 1.00, 0.00, 0.00, 0.85}; 81 82 public Q_SLOTS: 83 void linearScalePlease(bool); 84 void logScalePlease(bool); 85 void regularPalettePlease(bool); 86 void prettyPalettePlease(bool); 87 void greyScalePalettePlease(bool); 88 void glowingPalettePlease(bool); 89 void zeroRotationPlease(bool); 90 void plus90RotationPlease(bool); 91 void minus90RotationPlease(bool); 92 93 Q_SIGNALS: 94 void signalCurrentPixel(int pixel); 95 void signalPixelMoveOver(int pixel); 96 void signalPixelDoubleClick(int pixel); 97 void colorPaletteHasChanged(); 98 99 100 45 101 protected: 46 102 void initializeGL(); … … 59 115 vector<double>fData; 60 116 61 float ss[5];// = {0.00, 0.25, 0.5, 0.75, 1.00};62 float rr[5];// = {0.15, 0.00, 0.00, 1.00, 0.85};63 float gg[5];// = {0.15, 0.00, 1.00, 0.00, 0.85};64 float bb[5];// = {0.15, 1.00, 0.00, 0.00, 0.85};65 117 // bool recalcColorPlease; 118 GLfloat pixelsCoords[MAX_NUM_PIXELS][3]; 119 PixelsNeighbors neighbors[MAX_NUM_PIXELS]; 120 int hardwareMapping[NPIX]; 66 121 GLfloat pixelsColor[NPIX][3]; 67 122 GLfloat verticesList[NPIX*6][2]; … … 74 129 float shownSizey; 75 130 float pixelSize; 131 void DrawCameraText(); 132 void UpdateText(); 133 void DrawScale(); 134 void toggleInterfaceDisplay(); 135 QRadioButton* linearButton; 136 QRadioButton* logButton; 137 QRadioButton* regularPaletteButton; 138 QRadioButton* prettyPaletteButton; 139 QRadioButton* greyScalePaletteButton; 140 QRadioButton* glowingPaletteButton; 141 QRadioButton* zeroRotationButton; 142 QRadioButton* minus90RotationButton; 143 QRadioButton* plus90Rotationbutton; 144 QLabel* scaleLabel; 145 QLabel* colorPaletteLabel; 146 QLabel* rotationLabel; 147 QButtonGroup* scaleGroup; 148 QButtonGroup* colorGroup; 149 QButtonGroup* rotationGroup; 150 151 152 bool logScale; 153 int cameraRotation; 154 void buildVerticesList(); 155 virtual void buildPatchesIndices(); 156 void updateNeighbors(int currentPixel); 157 void calculatePixelsCoords(); 76 158 private: 77 void updateNeighbors(int currentPixel);78 159 void skipPixels(int start, int howMany); 79 void calculatePixelsCoords();80 void buildVerticesList();81 void buildPatchesIndices();82 160 float hexRadius; 83 161 float hexTolerance; 84 162 float viewSize; 85 GLfloat pixelsCoords[MAX_NUM_PIXELS][3]; 86 PixelsNeighbors neighbors[MAX_NUM_PIXELS]; 87 88 89 int hardwareMapping[NPIX]; 90 int numVertices; 163 int numVertices; 91 164 92 165 }; -
trunk/FACT++/gui/QCameraWidget.cc
r11894 r11901 5 5 QCameraWidget::QCameraWidget(QWidget *pparent) : BasicGlCamera(pparent) 6 6 { 7 fWhite = -1;8 fWhitePatch = -1;9 7 fBold.resize(1440); 10 8 fEnable.resize(1440); 11 9 fBold.assign(1440, false); 12 10 fEnable.assign(1440, true); 13 fMin = -1;14 fMax = -1;15 11 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.1f;26 patchesCoulour[1] = 0.1f;27 patchesCoulour[2] = 0.1f;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(true);36 12 37 13 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 14 158 15 } … … 262 119 fBold.assign(1440, false); 263 120 } 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 } 121 318 122 void QCameraWidget::mousePressEvent(QMouseEvent *cEvent) 319 123 { … … 368 172 } 369 173 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) 174 void QCameraWidget::SetEnable(int idx, bool b) 379 175 { 380 176 fEnable[idx] = b; … … 384 180 { 385 181 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 182 } 403 183 const char* QCameraWidget::GetName() … … 506 286 updateGL(); 507 287 } 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 } 288 289 752 290 void QCameraWidget::highlightPixel(int idx) 753 291 { -
trunk/FACT++/gui/QCameraWidget.h
r11878 r11901 6 6 #include <set> 7 7 8 #include <QtGui/QRadioButton>9 #include <QtGui/QLabel>10 #include <QtGui/QButtonGroup>11 8 12 9 using namespace std; … … 27 24 vector<int> highlightedPixels; 28 25 29 int fWhite;30 int fWhitePatch;31 32 int64_t fMin;33 int64_t fMax;34 26 35 27 int lastFace; 36 28 37 bool pixelColorUpToDate;38 39 GLfloat patchColour[3];40 GLfloat pixelContourColour[3];41 GLfloat patchesCoulour[3];42 GLfloat highlightedPatchesCoulour[3];43 GLfloat highlightedPixelsCoulour[3];44 GLfloat tooHighValueCoulour[3];45 GLfloat tooLowValueCoulour[3];46 47 string dataText;48 string unitsText;49 string titleText;50 29 51 30 public: … … 54 33 void clearHighlightedPatches(); 55 34 void clearHighlightedPixels(); 56 void setUnits(const string& units);57 void setTitle(const string& title);58 35 QCameraWidget(QWidget *pparent = 0); 59 36 void paintGL(); … … 64 41 void drawCamera(bool alsoWire); 65 42 void drawPatches(); 66 void SetWhite(int idx);67 43 void SetEnable(int idx, bool b); 68 44 double GetData(int idx); 69 void SetMin(int64_t min); 70 void SetMax(int64_t max); 71 const char *GetName(); 45 const char *GetName(); 72 46 73 47 int GetIdx(float px, float py); … … 76 50 void SetData(const valarray<double> &ddata); 77 51 78 public Q_SLOTS:79 void linearScalePlease(bool);80 void logScalePlease(bool);81 void regularPalettePlease(bool);82 void prettyPalettePlease(bool);83 void greyScalePalettePlease(bool);84 void glowingPalettePlease(bool);85 void zeroRotationPlease(bool);86 void plus90RotationPlease(bool);87 void minus90RotationPlease(bool);88 89 Q_SIGNALS:90 void signalCurrentPixel(int pixel);91 void signalPixelMoveOver(int pixel);92 void signalPixelDoubleClick(int pixel);93 52 94 53 private: 95 54 void CalculatePixelsColor(); 96 55 void CalculatePatchColor(); 97 void DrawCameraText();98 void UpdateText();99 void DrawScale();100 void toggleInterfaceDisplay();101 void repaintInterface();102 QRadioButton* linearButton;103 QRadioButton* logButton;104 QRadioButton* regularPaletteButton;105 QRadioButton* prettyPaletteButton;106 QRadioButton* greyScalePaletteButton;107 QRadioButton* glowingPaletteButton;108 QRadioButton* zeroRotationButton;109 QRadioButton* minus90RotationButton;110 QRadioButton* plus90Rotationbutton;111 QLabel* scaleLabel;112 QLabel* colorPaletteLabel;113 QLabel* rotationLabel;114 QButtonGroup* scaleGroup;115 QButtonGroup* colorGroup;116 QButtonGroup* rotationGroup;117 56 118 bool logScale;119 int cameraRotation;120 57 }; 121 58 -
trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.cc
r11900 r11901 25 25 #include "src/Configuration.h" 26 26 27 //Coordinates of an hexagon of radius 1 and center 0 28 GLfloat hexcoords[6][2] = {{-0.577367206, 1}, 29 { 0.577367206, 1}, 30 { 1.154734411, 0}, 31 { 0.577367206, -1}, 32 {-0.577367206, -1}, 33 {-1.154734411, 0}}; 27 //#include "../BasicGlCamera.cc" 28 29 #undef ACTUAL_NUM_PIXELS 30 #define ACTUAL_NUM_PIXELS 1440 34 31 35 32 //bounding box for diplaying the impulse curve … … 37 34 float bboxMax[2] = {0.8,-0.3}; 38 35 /************************************************************ 39 * UPDATE NEIGHBORS recalculate the neighbors of the current pixels. 40 * Only takes the previous pixels into account (and updates them, too) 41 ************************************************************/ 42 void RawDataViewer::updateNeighbors(int currentPixel) 43 { 44 float squaredDistance = 0; 45 for (int i=0;i<currentPixel;i++) 46 { 47 squaredDistance = (pixelsCoords[i][0] - pixelsCoords[currentPixel][0])* 48 (pixelsCoords[i][0] - pixelsCoords[currentPixel][0]) + 49 (pixelsCoords[i][1] - pixelsCoords[currentPixel][1])* 50 (pixelsCoords[i][1] - pixelsCoords[currentPixel][1]); 51 if (squaredDistance < 4*hexRadius*hexRadius*(1.0f+hexTolerance))//neighbor ! 52 {//ok, but which one ? 53 if (fabs(pixelsCoords[i][0] - pixelsCoords[currentPixel][0]) < hexTolerance && 54 pixelsCoords[i][1] < pixelsCoords[currentPixel][1]){//top 55 neighbors[i][0] = currentPixel; 56 neighbors[currentPixel][3] = i; 57 continue;} 58 if (fabs(pixelsCoords[i][0] - pixelsCoords[currentPixel][0]) < hexTolerance && 59 pixelsCoords[i][1] > pixelsCoords[currentPixel][1]){//bottom 60 neighbors[i][3] = currentPixel; 61 neighbors[currentPixel][0] = i; 62 continue;} 63 if (pixelsCoords[i][0] > pixelsCoords[currentPixel][0] && 64 pixelsCoords[i][1] > pixelsCoords[currentPixel][1]){//top right 65 neighbors[i][4] = currentPixel; 66 neighbors[currentPixel][1] = i; 67 continue;} 68 if (pixelsCoords[i][0] > pixelsCoords[currentPixel][0] && 69 pixelsCoords[i][1] < pixelsCoords[currentPixel][1]){//bottom right 70 neighbors[i][5] = currentPixel; 71 neighbors[currentPixel][2] = i; 72 continue;} 73 if (pixelsCoords[i][0] < pixelsCoords[currentPixel][0] && 74 pixelsCoords[i][1] > pixelsCoords[currentPixel][1]){//top left 75 neighbors[i][2] = currentPixel; 76 neighbors[currentPixel][5] = i; 77 continue;} 78 if (pixelsCoords[i][0] < pixelsCoords[currentPixel][0] && 79 pixelsCoords[i][1] < pixelsCoords[currentPixel][1]){//bottom left 80 neighbors[i][1] = currentPixel; 81 neighbors[currentPixel][4] = i; 82 continue;} 83 } 84 } 85 } 86 /************************************************************ 87 * SKIP PIXELS skips a given number of pixels. 88 * Only update the pixel coordinates. i.e. update neighbors must 89 * called again afterwards. 90 ************************************************************/ 91 void RawDataViewer::skipPixels(int start, int howMany) 92 { 93 for (int i=start;i<MAX_NUM_PIXELS-howMany;i++) 94 { 95 pixelsCoords[i][0] = pixelsCoords[i+howMany][0]; 96 pixelsCoords[i][1] = pixelsCoords[i+howMany][1]; 97 } 98 } 99 /************************************************************ 100 * CALCULATE PIXELS COORDS as the name suggests 101 ************************************************************/ 102 void RawDataViewer::calculatePixelsCoords() 103 { 104 pixelsCoords[0][0] = 0; 105 pixelsCoords[0][1] = 0.3; 106 pixelsCoords[0][2] = 0; 107 pixelsCoords[1][0] = 0; 108 pixelsCoords[1][1] = 0.3+2*hexRadius; 109 pixelsCoords[1][2] = 0; 110 neighbors[0][0] = 1; 111 neighbors[1][3] = 0; 112 //from which side of the previous hexagon are we coming from ? 113 int fromSide = 3; 114 //to which side are we heading to ? 115 int toSide = 0; 116 for (int i=2;i<MAX_NUM_PIXELS;i++) 117 { 118 toSide = fromSide-1; 119 if (toSide < 0) 120 toSide =5; 121 while (neighbors[i-1][toSide] >= 0) 122 { 123 toSide--; 124 if (toSide < 0) 125 toSide = 5; 126 } 127 fromSide = toSide + 3; 128 if (fromSide > 5) 129 fromSide -= 6; 130 //ok. now we now in which direction we're heading 131 pixelsCoords[i][0] = pixelsCoords[i-1][0]; 132 pixelsCoords[i][1] = pixelsCoords[i-1][1]; 133 pixelsCoords[i][2] = pixelsCoords[i-1][2]; 134 switch (toSide) 135 { 136 case 0: 137 pixelsCoords[i][1] += 2*hexRadius; 138 break; 139 case 1: 140 pixelsCoords[i][0] += (2*hexRadius)*sin(M_PI/3.0); 141 pixelsCoords[i][1] += (2*hexRadius)*cos(M_PI/3.0); 142 break; 143 case 2: 144 pixelsCoords[i][0] += (2*hexRadius)*sin(M_PI/3.0); 145 pixelsCoords[i][1] -= (2*hexRadius)*cos(M_PI/3.0); 146 break; 147 case 3: 148 pixelsCoords[i][1] -= 2*hexRadius; 149 break; 150 case 4: 151 pixelsCoords[i][0] -= (2*hexRadius)*sin(M_PI/3.0); 152 pixelsCoords[i][1] -= (2*hexRadius)*cos(M_PI/3.0); 153 break; 154 case 5: 155 pixelsCoords[i][0] -= (2*hexRadius)*sin(M_PI/3.0); 156 pixelsCoords[i][1] += (2*hexRadius)*cos(M_PI/3.0); 157 break; 158 }; 159 36 * CALC BLUR COLOR if in blur display mode, calculate the interpolated 37 * colour for a given vertex 38 ************************************************************/ 39 void RawDataViewer::calcBlurColor(int pixel, int vertex) 40 { 41 GLfloat color[3]; 42 int first, second; 43 first = vertex-1; 44 second = vertex; 45 if (first < 0) 46 first = 5; 47 first = neighbors[pixel][first]; 48 second = neighbors[pixel][second]; 49 for (int i=0;i<3;i++) 50 color[i] = pixelsColor[pixel][i]; 51 float divide = 1; 52 if (first != -1) 53 { 54 divide++; 55 for (int i=0;i<3;i++) 56 color[i] += pixelsColor[first][i]; 57 } 58 if (second != -1) 59 { 60 divide++; 61 for (int i=0;i<3;i++) 62 color[i] += pixelsColor[second][i]; 63 } 64 for (int i=0;i<3;i++) 65 color[i] /= divide; 66 glColor3fv(color); 67 } 68 /************************************************************ 69 * DRAW BLURRY HEXAGON. draws a solid hexagon, with interpolated colours 70 ************************************************************/ 71 void RawDataViewer::drawBlurryHexagon(int index) 72 { 73 GLfloat color[3]; 74 for (int i=0;i<3;i++) 75 color[i] = pixelsColor[index][i]; 76 glBegin(GL_TRIANGLES); 77 calcBlurColor(index, 0); 78 glVertex2fv(verticesList[verticesIndices[index][0]]); 79 glColor3fv(color); 80 glVertex2fv(pixelsCoords[index]); 81 calcBlurColor(index, 1); 82 glVertex2fv(verticesList[verticesIndices[index][1]]); 83 84 glVertex2fv(verticesList[verticesIndices[index][1]]); 85 glColor3fv(color); 86 glVertex2fv(pixelsCoords[index]); 87 calcBlurColor(index, 2); 88 glVertex2fv(verticesList[verticesIndices[index][2]]); 89 90 glVertex2fv(verticesList[verticesIndices[index][2]]); 91 glColor3fv(color); 92 glVertex2fv(pixelsCoords[index]); 93 calcBlurColor(index, 3); 94 glVertex2fv(verticesList[verticesIndices[index][3]]); 95 96 glVertex2fv(verticesList[verticesIndices[index][3]]); 97 glColor3fv(color); 98 glVertex2fv(pixelsCoords[index]); 99 calcBlurColor(index, 4); 100 glVertex2fv(verticesList[verticesIndices[index][4]]); 101 102 glVertex2fv(verticesList[verticesIndices[index][4]]); 103 glColor3fv(color); 104 glVertex2fv(pixelsCoords[index]); 105 calcBlurColor(index, 5); 106 glVertex2fv(verticesList[verticesIndices[index][5]]); 107 108 glVertex2fv(verticesList[verticesIndices[index][5]]); 109 glColor3fv(color); 110 glVertex2fv(pixelsCoords[index]); 111 calcBlurColor(index, 0); 112 glVertex2fv(verticesList[verticesIndices[index][0]]); 113 glEnd(); 114 115 return; 116 } 117 118 /************************************************************ 119 * DRAW CAMERA draws all the camera pixels 120 ************************************************************/ 121 void RawDataViewer::drawCamera(bool alsoWire) 122 { 123 glLoadIdentity(); 124 if (!drawImpulse) 125 { 126 glTranslatef(0,-0.44,0); 127 glRotatef(cameraRotation, 0,0,-1); 128 if (cameraRotation == 90) 129 { 130 glTranslatef(-0.45,-0.45,0); 131 // cout << "correction" << endl; 132 } 133 if (cameraRotation == -90) 134 { 135 glTranslatef(0.45,-0.45,0); 136 } 137 glScalef(1.5,1.5,1); 138 } 139 else 140 { 141 glRotatef(cameraRotation, 0,0,-1); 142 if (cameraRotation == 90) 143 { 144 glTranslatef(-0.45/1.5,-0.45/1.5,0); 145 // cout << "correction" << endl; 146 } 147 if (cameraRotation == -90) 148 { 149 glTranslatef(0.45/1.5,-0.45/1.5,0); 150 } 151 } 152 glColor3f(0.5,0.5,0.5); 153 glLineWidth(1.0); 154 float color; 155 //cout << "Actual num pixels: " << ACTUAL_NUM_PIXELS << endl; 156 for (int i=0;i<ACTUAL_NUM_PIXELS;i++) 157 { 158 if (!nRoi) 159 color = (float)(i)/(float)(ACTUAL_NUM_PIXELS); 160 else 161 #ifdef LOAD_RAW 162 color = float(eventsData[eventNum][i][whichSlice]+(VALUES_SPAN/2))/(float)(VALUES_SPAN-1); 163 #else 164 color = float(eventData[nRoi*i + whichSlice]+(VALUES_SPAN/2))/(float)(VALUES_SPAN-1); 165 if (logScale) 166 { 167 color *= 9; 168 color += 1; 169 color = log10(color); 170 } 171 #endif 172 if (color < 0) 173 { 174 pixelsColor[i][0] = tooLowValueCoulour[0]; 175 pixelsColor[i][1] = tooLowValueCoulour[1]; 176 pixelsColor[i][2] = tooLowValueCoulour[2]; 177 continue; 178 } 179 if (color > 1) 180 { 181 pixelsColor[i][0] = tooHighValueCoulour[0]; 182 pixelsColor[i][1] = tooHighValueCoulour[1]; 183 pixelsColor[i][2] = tooHighValueCoulour[2]; 184 continue; 185 } 186 int index = 0; 187 while (ss[index] < color && index < 4) 188 index++; 189 index--; 190 if (index < 0) index = 0; 191 float weight0 = (color-ss[index]) / (ss[index+1]-ss[index]); 192 if (weight0 > 1.0f) weight0 = 1.0f; 193 if (weight0 < 0.0f) weight0 = 0.0f; 194 float weight1 = 1.0f-weight0; 195 pixelsColor[i][0] = weight1*rr[index] + weight0*rr[index+1]; 196 pixelsColor[i][1] = weight1*gg[index] + weight0*gg[index+1]; 197 pixelsColor[i][2] = weight1*bb[index] + weight0*bb[index+1]; 198 } 199 200 for (int i=0;i<ACTUAL_NUM_PIXELS;i++) 201 { 202 if (i == 690 || 203 i == 70) 204 continue; 205 glColor3fv(pixelsColor[i]); 206 glLoadName(i); 207 if (drawBlur) 208 drawBlurryHexagon(i); 209 else 210 drawHexagon(i,true); 211 212 } 213 if (!alsoWire) 214 return; 215 glColor3f(0.0f,0.0f,0.0f); 216 for (int i=0;i<ACTUAL_NUM_PIXELS;i++) 217 { 218 if (i == 690 || 219 i == 70) 220 continue; 221 drawHexagon(i, false); 222 } 223 224 } 225 226 /************************************************************ 227 * TRIM. FIXME this should not be here but taken from an existing class (somewhere) 228 *********************************************************** 229 string Trim(const string &str) 230 { 231 // Trim Both leading and trailing spaces 232 const size_t start = str.find_first_not_of(' '); // Find the first character position after excluding leading blank spaces 233 const size_t end = str.find_last_not_of(' '); // Find the first character position from reverse af 234 235 // if all spaces or empty return an empty string 236 if (string::npos==start || string::npos==end) 237 return string(); 238 239 return str.substr(start, end-start+1); 240 }*/ 241 /************************************************************ 242 * DRAW PIXEL CURVE. draws the raw impulse curve of the currently selected pixel 243 ************************************************************/ 244 void RawDataViewer::drawPixelCurve() 245 { 246 if (!nRoi) 247 return; 248 249 float xZoom, yZoom; 250 xZoom = yZoom = 1.0f; 251 252 glBegin(GL_LINES); 253 glLineWidth(1.0f); 254 glColor3f(0.5,0.5,0.5); 255 glVertex2f(bboxMin[0], bboxMin[1]); 256 glVertex2f(bboxMax[0], bboxMin[1]); 257 glVertex2f(bboxMin[0], bboxMin[1]); 258 glVertex2f(bboxMin[0], bboxMax[1]); 259 glVertex2f(bboxMin[0], (bboxMin[1]+bboxMax[1])/2.0f); 260 glVertex2f(bboxMax[0], (bboxMin[1]+bboxMax[1])/2.0f); 261 float xRange = bboxMax[0] - bboxMin[0]; 262 float yRange = bboxMax[1] - bboxMin[1]; 263 glColor3f(1.0,1.0,1.0); 264 float divideMe = (float)(VALUES_SPAN-1); 265 float plusMe = VALUES_SPAN/2; 266 if (drawCalibrationLoaded) 267 plusMe += 0;//VALUES_SPAN/2; 268 if (drawCalibrationLoaded && calibrationLoaded) 269 { 270 divideMe /=2; 271 plusMe /=2; 272 } 273 for (int i=0;i<nRoi-1;i++) 274 { 275 #ifdef LOAD_RAW 276 glVertex2f(bboxMin[0] + xRange*i/(float)nRoi, 277 bboxMin[1] + yRange*(eventsData[eventNum][selectedPixel][i]+plusMe) /divideMe); 278 glVertex2f(bboxMin[0] + xRange*(i+1)/(float)nRoi, 279 bboxMin[1] + yRange*(eventsData[eventNum][selectedPixel][i+1]+plusMe) /divideMe); 280 #else 281 282 glVertex2f(bboxMin[0] + xRange*i/(float)nRoi, 283 bboxMin[1] + yRange*(eventData[nRoi*selectedPixel + i]+plusMe) /divideMe); 284 glVertex2f(bboxMin[0] + xRange*(i+1)/(float)nRoi, 285 bboxMin[1] + yRange*(eventData[nRoi*selectedPixel + i+1]+plusMe) /divideMe); 286 #endif 287 } 288 glColor3f(1.0,0.0,0.0); 289 glVertex2f(bboxMin[0] + xRange*whichSlice/(float)nRoi, 290 bboxMin[1]); 291 glVertex2f(bboxMin[0] + xRange*whichSlice/(float)nRoi, 292 bboxMax[1]); 293 glEnd(); 294 glEnable(GL_MULTISAMPLE); 295 setFont(QFont("Times", 12)); 296 qglColor(QColor(255,223,127)); 297 float xShift = 0.10f; 298 float yShift = 0.01f; 299 renderText(bboxMin[0]-xShift/2.0f, bboxMax[1]+3*yShift, 0, QString("Volts")); 300 if (drawCalibrationLoaded) 301 { 302 renderText(bboxMin[0]-xShift, bboxMax[1]-yShift,0,QString("+2.10")); 303 renderText(bboxMin[0]-xShift, ((bboxMin[1]+bboxMax[1])/2.0f) - yShift, 0, QString("+1.05"));//((bboxMin[1]+bboxMax[1])/2.0f) 304 renderText(bboxMin[0]-xShift, bboxMin[1]-yShift, 0, QString("0.00")); 305 } 306 else 307 { 308 renderText(bboxMin[0]-xShift, bboxMax[1]-yShift,0,QString("+1.05")); 309 renderText(bboxMin[0]-xShift, ((bboxMin[1]+bboxMax[1])/2.0f) - yShift, 0, QString("+0.00"));//((bboxMin[1]+bboxMax[1])/2.0f) 310 renderText(bboxMin[0]-xShift, bboxMin[1]-yShift, 0, QString("-1.05")); 311 } 312 renderText(bboxMax[0]+xShift/2.0f, bboxMin[1]-4*yShift, 0, QString("Slices")); 313 renderText(bboxMin[0]-yShift/2.0f, bboxMin[1]-4*yShift, 0, QString("0")); 314 ostringstream str; 315 str << nRoi/2; 316 renderText(((bboxMin[0]+bboxMax[0])/2.0f)-xShift/2.0f, bboxMin[1]-4*yShift, 0, QString(str.str().c_str())); 317 str.str(""); 318 str << nRoi; 319 renderText(bboxMax[0]-xShift/2.0f, bboxMin[1]-4*yShift, 0, QString(str.str().c_str())); 320 321 } 322 /************************************************************ 323 * CONSTRUCTOR. 324 ************************************************************/ 325 RawDataViewer::RawDataViewer(QWidget *cParent) : BasicGlCamera(cParent) 326 { 327 // setFormat(QGLFormat(QGL::DoubleBuffer));// | QGL::DepthBuffer)); 328 whichSlice = 0; 329 #ifdef LOAD_RAW 330 nRoi = 1024; 331 #else 332 nRoi = 0; 333 #endif 334 eventNum = 0; 335 rowNum = -1; 336 eventStep = 1; 337 selectedPixel = 393; 338 inputFile = NULL; 339 eventData = NULL; 340 drawPatch = true; 341 drawImpulse = false; 342 drawBlur = false; 343 loopCurrentEvent = false; 344 #ifdef LOAD_RAW 345 loadEvents("/scratch/00000043.001_T.bin"); 346 #endif 347 // cout << "avant" << endl; 348 // calculatePixelsCoords(); 349 // cout << "apres" << endl; 350 /* 351 ifstream fin2("MasterList-v3.txt"); 352 if (!fin2.is_open()) 353 { 354 cout << "Error: file \"MasterList-v3\" missing. aborting." << endl; 355 exit(-1); 356 } 357 int l = 0; 358 string buf; 359 while (getline(fin2, buf, '\n')) 360 { 361 buf = Trim(buf); 362 if (buf[0]=='#') 363 continue; 364 365 unsigned int softid, hardid, dummy; 366 367 stringstream str(buf); 368 369 str >> softid; 370 str >> dummy; 371 str >> hardid; 372 373 if (softid>=1440) 374 continue; 375 376 hardwareMapping[softid] = hardid; 377 softwareMapping[hardid] = softid; 378 379 l++; 380 }*/ 381 GLfloat tempPixelsCoords[MAX_NUM_PIXELS][3]; 382 for (int i=0;i<1440;i++) 383 for (int j=0;j<3;j++) 384 tempPixelsCoords[hardwareMapping[i]][j] = pixelsCoords[i][j]; 385 for (int i=0;i<1440;i++) 386 for (int j=0;j<3;j++) 387 pixelsCoords[i][j] = tempPixelsCoords[i][j]; 388 389 for (int i=0;i<1440;i++) 390 updateNeighbors(i); 391 buildVerticesList(); 392 393 /* ifstream fin1("Trigger-Patches.txt"); 394 if (!fin1.is_open()) 395 { 396 cout << "Error: file \"Trigger-Patches.txt\" missing. Aborting." << endl; 397 exit(-1); 398 } 399 l=0; 400 while (getline(fin1, buf, '\n')) 401 { 402 buf = Trim(buf); 403 if (buf[0]=='#') 404 continue; 405 406 stringstream str(buf); 407 for (int i=0; i<9; i++) 408 { 409 unsigned int n; 410 str >> n; 411 412 if (n>=1440) 413 continue; 414 415 patches[l][i] = hardwareMapping[n]; 416 } 417 l++; 418 }*/ 419 420 buildPatchesIndices(); 421 float color[3]; 422 for (int i=0;i<160;i++) 423 { 424 color[0] = 0.5; color[1] = 0.5; color[2] = 0.3; 425 for (int j=0;j<3;j++) 426 patchesColor[i][j] = color[j]; 427 } 428 429 for (int i=0;i<1440;i++) 160 430 updateNeighbors(i); 161 } 162 //Ok. So now we've circled around all the way to MAX_NUM_PIXELS 163 //do the required shifts so that it matches the fact camera up to ACTUAL_NUM_PIXELS pixels 164 skipPixels(1200, 1); 165 skipPixels(1218, 3); 166 skipPixels(1236, 1); 167 skipPixels(1256, 1); 168 skipPixels(1274, 3); 169 skipPixels(1292, 3); 170 skipPixels(1309, 6); 171 skipPixels(1323, 7); 172 skipPixels(1337, 6); 173 skipPixels(1354, 6); 174 skipPixels(1368, 7); 175 skipPixels(1382, 9); 176 skipPixels(1394, 12); 177 skipPixels(1402, 15); 178 skipPixels(1410, 12); 179 skipPixels(1422, 12); 180 skipPixels(1430, 15); 181 } 182 /************************************************************ 183 * BUILD VERTICES LIST. from the coordinates of the camera pixels, 184 * calculate the list and coordinates of the vertices required to draw the 185 * entire camera. 186 ************************************************************/ 187 void RawDataViewer::buildVerticesList() 188 { 189 numVertices = 0; 190 GLfloat cVertex[2]; 191 for (int i=0;i<ACTUAL_NUM_PIXELS;i++) 192 { 193 for (int j=0;j<6;j++) 194 { 195 for (int k=0;k<2;k++) 196 cVertex[k] = hexcoords[j][k]*hexRadius + pixelsCoords[i][k]; 197 bool found = false; 198 for (int k=0;k<numVertices;k++) 199 { 200 if ((cVertex[0] - verticesList[k][0])* 201 (cVertex[0] - verticesList[k][0]) + 202 (cVertex[1] - verticesList[k][1])* 203 (cVertex[1] - verticesList[k][1]) < hexTolerance*hexTolerance) 204 { 205 found = true; 206 break; 207 } 208 } 209 if (!found) 210 { 211 for (int k=0;k<2;k++) 212 verticesList[numVertices][k] = cVertex[k]; 213 numVertices++; 214 } 215 } 216 } 217 for (int i=0;i<ACTUAL_NUM_PIXELS;i++) 218 { 219 for (int j=0;j<6;j++) 220 { 221 for (int k=0;k<2;k++) 222 cVertex[k] = hexcoords[j][k]*hexRadius + pixelsCoords[i][k]; 223 for (int k=0;k<numVertices;k++) 224 { 225 if ((cVertex[0] - verticesList[k][0])* 226 (cVertex[0] - verticesList[k][0]) + 227 (cVertex[1] - verticesList[k][1])* 228 (cVertex[1] - verticesList[k][1]) < hexTolerance*hexTolerance) 229 { 230 verticesIndices[i][j] = k; 231 break; 232 } 233 } 234 } 235 } 236 } 237 /************************************************************ 238 * BUILD PATCHES INDICES. from the list of patches, crawls through 239 * the list of camera pixels and build the list of edges that should be kept 240 * in order to display the patches' contours. 241 ************************************************************/ 431 432 calibrationLoaded = false; 433 drawCalibrationLoaded = false; 434 435 } 436 /************************************************************ 437 * DESTRUCTOR 438 ************************************************************/ 439 RawDataViewer::~RawDataViewer() 440 { 441 if (inputFile != NULL) 442 { 443 inputFile->close(); 444 delete inputFile; 445 } 446 if (eventData != NULL) { 447 delete[] eventData; 448 delete[] rawEventData; 449 } 450 } 451 242 452 void RawDataViewer::buildPatchesIndices() 243 453 { 244 454 vector<edge>::iterator it; 245 455 bool erased = false; 456 // patchesIndices.resize(NTMARK); 246 457 for (int i=0;i<NTMARK;i++)//for all patches 247 458 { … … 283 494 } 284 495 /************************************************************ 285 * CALC BLUR COLOR if in blur display mode, calculate the interpolated286 * colour for a given vertex287 ************************************************************/288 void RawDataViewer::calcBlurColor(int pixel, int vertex)289 {290 GLfloat color[3];291 int first, second;292 first = vertex-1;293 second = vertex;294 if (first < 0)295 first = 5;296 first = neighbors[pixel][first];297 second = neighbors[pixel][second];298 for (int i=0;i<3;i++)299 color[i] = pixelsColor[pixel][i];300 float divide = 1;301 if (first != -1)302 {303 divide++;304 for (int i=0;i<3;i++)305 color[i] += pixelsColor[first][i];306 }307 if (second != -1)308 {309 divide++;310 for (int i=0;i<3;i++)311 color[i] += pixelsColor[second][i];312 }313 for (int i=0;i<3;i++)314 color[i] /= divide;315 glColor3fv(color);316 }317 /************************************************************318 * DRAW BLURRY HEXAGON. draws a solid hexagon, with interpolated colours319 ************************************************************/320 void RawDataViewer::drawBlurryHexagon(int index)321 {322 GLfloat color[3];323 for (int i=0;i<3;i++)324 color[i] = pixelsColor[index][i];325 glBegin(GL_TRIANGLES);326 calcBlurColor(index, 0);327 glVertex2fv(verticesList[verticesIndices[index][0]]);328 glColor3fv(color);329 glVertex2fv(pixelsCoords[index]);330 calcBlurColor(index, 1);331 glVertex2fv(verticesList[verticesIndices[index][1]]);332 333 glVertex2fv(verticesList[verticesIndices[index][1]]);334 glColor3fv(color);335 glVertex2fv(pixelsCoords[index]);336 calcBlurColor(index, 2);337 glVertex2fv(verticesList[verticesIndices[index][2]]);338 339 glVertex2fv(verticesList[verticesIndices[index][2]]);340 glColor3fv(color);341 glVertex2fv(pixelsCoords[index]);342 calcBlurColor(index, 3);343 glVertex2fv(verticesList[verticesIndices[index][3]]);344 345 glVertex2fv(verticesList[verticesIndices[index][3]]);346 glColor3fv(color);347 glVertex2fv(pixelsCoords[index]);348 calcBlurColor(index, 4);349 glVertex2fv(verticesList[verticesIndices[index][4]]);350 351 glVertex2fv(verticesList[verticesIndices[index][4]]);352 glColor3fv(color);353 glVertex2fv(pixelsCoords[index]);354 calcBlurColor(index, 5);355 glVertex2fv(verticesList[verticesIndices[index][5]]);356 357 glVertex2fv(verticesList[verticesIndices[index][5]]);358 glColor3fv(color);359 glVertex2fv(pixelsCoords[index]);360 calcBlurColor(index, 0);361 glVertex2fv(verticesList[verticesIndices[index][0]]);362 glEnd();363 364 return;365 }366 /************************************************************367 * DRAW HEXAGON. draws a single hexagon.368 ************************************************************/369 void RawDataViewer::drawHexagon(int index, bool solid)370 {371 if (solid)372 glBegin(GL_POLYGON);373 else374 glBegin(GL_LINE_LOOP);375 376 glVertex2fv(verticesList[verticesIndices[index][0]]);377 glVertex2fv(verticesList[verticesIndices[index][1]]);378 glVertex2fv(verticesList[verticesIndices[index][2]]);379 glVertex2fv(verticesList[verticesIndices[index][3]]);380 glVertex2fv(verticesList[verticesIndices[index][4]]);381 glVertex2fv(verticesList[verticesIndices[index][5]]);382 if (solid)383 glVertex2fv(verticesList[verticesIndices[index][0]]);384 385 glEnd();386 387 return;388 }389 390 391 float ss[5] = {0.00, 0.25, 0.5, 0.75, 1.00};392 float rr[5] = {0.15, 0.00, 0.00, 1.00, 0.85};393 float gg[5] = {0.15, 0.00, 1.00, 0.00, 0.85};394 float bb[5] = {0.15, 1.00, 0.00, 0.00, 0.85};395 /*396 float ss[5] = {0., 0.47, 0.475, 0.48, 1.00};397 float rr[5] = {0., 0.35, 0.85, 1.00, 1.00};398 float gg[5] = {0., 0.10, 0.20, 0.73, 1.00};399 float bb[5] = {0., 0.03, 0.06, 0.00, 1.00};400 */401 /************************************************************402 * DRAW PATCHES. draws the clustering patches403 ************************************************************/404 void RawDataViewer::drawPatches()405 {406 glLineWidth(2.0f);407 float backupRadius = hexRadius;408 hexRadius *= 0.95;409 glBegin(GL_LINES);410 for (int i=0;i<NTMARK;i++)411 {412 glColor3fv(patchesColor[i]);413 for (unsigned int j=0;j<patchesIndices[i].size();j++)414 {415 glVertex2fv(verticesList[patchesIndices[i][j].first]);416 glVertex2fv(verticesList[patchesIndices[i][j].second]);417 }418 }419 glEnd();420 hexRadius = backupRadius;421 }422 /************************************************************423 * DRAW CAMERA draws all the camera pixels424 ************************************************************/425 void RawDataViewer::drawCamera(bool alsoWire)426 {427 glColor3f(0.5,0.5,0.5);428 glLineWidth(1.0);429 float color;430 431 for (int i=0;i<ACTUAL_NUM_PIXELS;i++)432 {433 if (!nRoi)434 color = (float)(i)/(float)(ACTUAL_NUM_PIXELS);435 else436 #ifdef LOAD_RAW437 color = float(eventsData[eventNum][i][whichSlice]+(VALUES_SPAN/2))/(float)(VALUES_SPAN-1);438 #else439 color = float(eventData[nRoi*i + whichSlice]+(VALUES_SPAN/2))/(float)(VALUES_SPAN-1);440 #endif441 int index = 0;442 while (ss[index] < color)443 index++;444 index--;445 float weight0 = (color-ss[index]) / (ss[index+1]-ss[index]);446 float weight1 = 1.0f-weight0;447 pixelsColor[i][0] = weight1*rr[index] + weight0*rr[index+1];448 pixelsColor[i][1] = weight1*gg[index] + weight0*gg[index+1];449 pixelsColor[i][2] = weight1*bb[index] + weight0*bb[index+1];450 }451 452 for (int i=0;i<ACTUAL_NUM_PIXELS;i++)453 {454 if (i == 690 ||455 i == 70)456 continue;457 glColor3fv(pixelsColor[i]);458 glLoadName(i);459 if (drawBlur)460 drawBlurryHexagon(i);461 else462 drawHexagon(i,true);463 464 }465 if (!alsoWire)466 return;467 glColor3f(0.0f,0.0f,0.0f);468 for (int i=0;i<ACTUAL_NUM_PIXELS;i++)469 {470 if (i == 690 ||471 i == 70)472 continue;473 drawHexagon(i, false);474 }475 476 }477 478 /************************************************************479 * TRIM. FIXME this should not be here but taken from an existing class (somewhere)480 ************************************************************/481 string Trim(const string &str)482 {483 // Trim Both leading and trailing spaces484 const size_t start = str.find_first_not_of(' '); // Find the first character position after excluding leading blank spaces485 const size_t end = str.find_last_not_of(' '); // Find the first character position from reverse af486 487 // if all spaces or empty return an empty string488 if (string::npos==start || string::npos==end)489 return string();490 491 return str.substr(start, end-start+1);492 }493 /************************************************************494 * DRAW PIXEL CURVE. draws the raw impulse curve of the currently selected pixel495 ************************************************************/496 void RawDataViewer::drawPixelCurve()497 {498 if (!nRoi)499 return;500 501 float xZoom, yZoom;502 xZoom = yZoom = 1.0f;503 504 glBegin(GL_LINES);505 glLineWidth(1.0f);506 glColor3f(0.5,0.5,0.5);507 glVertex2f(bboxMin[0], bboxMin[1]);508 glVertex2f(bboxMax[0], bboxMin[1]);509 glVertex2f(bboxMin[0], bboxMin[1]);510 glVertex2f(bboxMin[0], bboxMax[1]);511 glVertex2f(bboxMin[0], (bboxMin[1]+bboxMax[1])/2.0f);512 glVertex2f(bboxMax[0], (bboxMin[1]+bboxMax[1])/2.0f);513 float xRange = bboxMax[0] - bboxMin[0];514 float yRange = bboxMax[1] - bboxMin[1];515 glColor3f(1.0,1.0,1.0);516 float divideMe = (float)(VALUES_SPAN-1);517 float plusMe = VALUES_SPAN/2;518 if (drawCalibrationLoaded && calibrationLoaded)519 {520 divideMe /=2;521 plusMe /=2;522 }523 for (int i=0;i<nRoi-1;i++)524 {525 #ifdef LOAD_RAW526 glVertex2f(bboxMin[0] + xRange*i/(float)nRoi,527 bboxMin[1] + yRange*(eventsData[eventNum][selectedPixel][i]+plusMe) /divideMe);528 glVertex2f(bboxMin[0] + xRange*(i+1)/(float)nRoi,529 bboxMin[1] + yRange*(eventsData[eventNum][selectedPixel][i+1]+plusMe) /divideMe);530 #else531 532 glVertex2f(bboxMin[0] + xRange*i/(float)nRoi,533 bboxMin[1] + yRange*(eventData[nRoi*selectedPixel + i]+plusMe) /divideMe);534 glVertex2f(bboxMin[0] + xRange*(i+1)/(float)nRoi,535 bboxMin[1] + yRange*(eventData[nRoi*selectedPixel + i+1]+plusMe) /divideMe);536 #endif537 }538 glColor3f(1.0,0.0,0.0);539 glVertex2f(bboxMin[0] + xRange*whichSlice/(float)nRoi,540 bboxMin[1]);541 glVertex2f(bboxMin[0] + xRange*whichSlice/(float)nRoi,542 bboxMax[1]);543 glEnd();544 glEnable(GL_MULTISAMPLE);545 setFont(QFont("Times", 12));546 qglColor(QColor(255,223,127));547 float xShift = 0.10f;548 float yShift = 0.01f;549 renderText(bboxMin[0]-xShift/2.0f, bboxMax[1]+3*yShift, 0, QString("Volts"));550 renderText(bboxMin[0]-xShift, bboxMax[1]-yShift,0,QString("+1.05"));551 renderText(bboxMin[0]-xShift, ((bboxMin[1]+bboxMax[1])/2.0f) - yShift, 0, QString("+0.00"));//((bboxMin[1]+bboxMax[1])/2.0f)552 renderText(bboxMin[0]-xShift, bboxMin[1]-yShift, 0, QString("-1.05"));553 554 renderText(bboxMax[0]+xShift/2.0f, bboxMin[1]-4*yShift, 0, QString("Slices"));555 renderText(bboxMin[0]-yShift/2.0f, bboxMin[1]-4*yShift, 0, QString("0"));556 ostringstream str;557 str << nRoi/2;558 renderText(((bboxMin[0]+bboxMax[0])/2.0f)-xShift/2.0f, bboxMin[1]-4*yShift, 0, QString(str.str().c_str()));559 str.str("");560 str << nRoi;561 renderText(bboxMax[0]-xShift/2.0f, bboxMin[1]-4*yShift, 0, QString(str.str().c_str()));562 563 }564 /************************************************************565 * CONSTRUCTOR.566 ************************************************************/567 RawDataViewer::RawDataViewer(QWidget *cParent) : QGLWidget(cParent)568 {569 setFormat(QGLFormat(QGL::DoubleBuffer));// | QGL::DepthBuffer));570 hexRadius = 0.015f;571 hexTolerance = hexRadius/100.0f;572 viewSize = 1.0f;573 whichSlice = 0;574 #ifdef LOAD_RAW575 nRoi = 1024;576 #else577 nRoi = 0;578 #endif579 eventNum = 0;580 rowNum = -1;581 eventStep = 1;582 selectedPixel = 393;583 inputFile = NULL;584 eventData = NULL;585 drawPatch = true;586 drawImpulse = false;587 drawBlur = false;588 loopCurrentEvent = false;589 #ifdef LOAD_RAW590 loadEvents("/scratch/00000043.001_T.bin");591 #endif592 calculatePixelsCoords();593 594 ifstream fin2("MasterList-v3.txt");595 if (!fin2.is_open())596 {597 cout << "Error: file \"MasterList-v3\" missing. aborting." << endl;598 exit(-1);599 }600 int l = 0;601 string buf;602 while (getline(fin2, buf, '\n'))603 {604 buf = Trim(buf);605 if (buf[0]=='#')606 continue;607 608 unsigned int softid, hardid, dummy;609 610 stringstream str(buf);611 612 str >> softid;613 str >> dummy;614 str >> hardid;615 616 if (softid>=1440)617 continue;618 619 hardwareMapping[softid] = hardid;620 softwareMapping[hardid] = softid;621 622 l++;623 }624 GLfloat tempPixelsCoords[MAX_NUM_PIXELS][3];625 for (int i=0;i<1440;i++)626 for (int j=0;j<3;j++)627 tempPixelsCoords[hardwareMapping[i]][j] = pixelsCoords[i][j];628 for (int i=0;i<1440;i++)629 for (int j=0;j<3;j++)630 pixelsCoords[i][j] = tempPixelsCoords[i][j];631 buildVerticesList();632 ifstream fin1("Trigger-Patches.txt");633 if (!fin1.is_open())634 {635 cout << "Error: file \"Trigger-Patches.txt\" missing. Aborting." << endl;636 exit(-1);637 }638 l=0;639 while (getline(fin1, buf, '\n'))640 {641 buf = Trim(buf);642 if (buf[0]=='#')643 continue;644 645 stringstream str(buf);646 for (int i=0; i<9; i++)647 {648 unsigned int n;649 str >> n;650 651 if (n>=1440)652 continue;653 654 patches[l][i] = hardwareMapping[n];655 }656 l++;657 }658 buildPatchesIndices();659 float color[3];660 for (int i=0;i<160;i++)661 {662 color[0] = 0.5; color[1] = 0.5; color[2] = 0.3;663 for (int j=0;j<3;j++)664 patchesColor[i][j] = color[j];665 }666 667 for (int i=0;i<1440;i++)668 updateNeighbors(i);669 670 calibrationLoaded = false;671 drawCalibrationLoaded = false;672 673 }674 /************************************************************675 * DESTRUCTOR676 ************************************************************/677 RawDataViewer::~RawDataViewer()678 {679 if (inputFile != NULL)680 {681 inputFile->close();682 delete inputFile;683 }684 if (eventData != NULL) {685 delete[] eventData;686 delete[] rawEventData;687 }688 }689 /************************************************************690 * INITIALIZE GL. does not do much.691 ************************************************************/692 void RawDataViewer::initializeGL()693 {694 qglClearColor(QColor(25,25,38));695 glShadeModel(GL_FLAT);696 glDisable(GL_DEPTH_TEST);697 glDisable(GL_CULL_FACE);698 // glEnable(GL_LINE_SMOOTH);699 // glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);700 }701 702 /************************************************************703 * RESIZE GL. reshapes the ortho projection to match the current window size704 ************************************************************/705 void RawDataViewer::resizeGL(int cWidth, int cHeight)706 {707 glViewport(0, 0, cWidth, cHeight);708 glMatrixMode(GL_PROJECTION);709 glLoadIdentity();710 GLfloat windowRatio = (float)cWidth/(float)cHeight;711 if (windowRatio < 1)712 {713 windowRatio = 1.0f/windowRatio;714 gluOrtho2D(-viewSize, viewSize, -viewSize*windowRatio, viewSize*windowRatio);715 pixelSize = 2*viewSize/(float)cWidth;716 shownSizex = 2*viewSize;717 shownSizey = 2*viewSize*windowRatio;718 }719 else720 {721 gluOrtho2D(-viewSize*windowRatio, viewSize*windowRatio, -viewSize, viewSize);722 pixelSize = 2*viewSize/(float)cHeight;723 shownSizex = 2*viewSize*windowRatio;724 shownSizey = 2*viewSize;725 }726 glMatrixMode(GL_MODELVIEW);727 }728 729 /************************************************************730 496 * PAINT GL. main drawing function. 731 497 ************************************************************/ … … 735 501 glLoadIdentity(); 736 502 737 if (!drawImpulse) 738 { 739 glTranslatef(0,-0.44,0); 740 glScalef(1.5,1.5,1); 741 } 503 742 504 if (drawBlur) 743 505 { … … 749 511 glShadeModel(GL_FLAT); 750 512 drawCamera(true); 751 }752 if (drawImpulse)753 {754 glLineWidth(2.0);755 drawPixelCurve();756 513 } 757 514 if (drawPatch) … … 764 521 drawHexagon(selectedPixel, false); 765 522 } 523 if (drawImpulse) 524 { 525 // glRotatef(cameraRotation, 0,0,1); 526 glLoadIdentity(); 527 glLineWidth(2.0); 528 drawPixelCurve(); 529 } 530 531 DrawScale(); 766 532 } 767 533 … … 771 537 void RawDataViewer::mousePressEvent(QMouseEvent *cEvent) 772 538 { 539 if (cEvent->pos().x() > width()-(width()/50.f)) 540 { 541 toggleInterfaceDisplay(); 542 return; 543 } 773 544 lastPos = cEvent->pos(); 774 545 setCorrectSlice(cEvent); … … 822 593 } 823 594 824 /************************************************************825 * PIXEL AT POSITION. figures out which camera pixel was clicked.826 ************************************************************/827 int RawDataViewer::PixelAtPosition(const QPoint &cPos)828 {829 const int MaxSize = 512;830 GLuint buffer[MaxSize];831 GLint viewport[4];832 833 makeCurrent();834 835 glGetIntegerv(GL_VIEWPORT, viewport);836 glSelectBuffer(MaxSize, buffer);837 glRenderMode(GL_SELECT);838 839 glInitNames();840 glPushName(0);841 842 glMatrixMode(GL_PROJECTION);843 glPushMatrix();844 glLoadIdentity();845 GLfloat windowRatio = GLfloat(width()) / GLfloat(height());846 gluPickMatrix(GLdouble(cPos.x()), GLdouble(viewport[3] - cPos.y()),847 1.0, 1.0, viewport);848 849 if (windowRatio < 1)850 {851 windowRatio = 1.0f/windowRatio;852 gluOrtho2D(-viewSize, viewSize, -viewSize*windowRatio, viewSize*windowRatio);853 }854 else855 {856 gluOrtho2D(-viewSize*windowRatio, viewSize*windowRatio, -viewSize, viewSize);857 }858 859 glMatrixMode(GL_MODELVIEW);860 drawCamera(false);861 glMatrixMode(GL_PROJECTION);862 glPopMatrix();863 864 //for some reason that I cannot understand, the push/pop matrix doesn't do the trick here... bizarre865 //ok, so re-do the resizeGL thing.866 resizeGL(width(), height());867 868 if (!glRenderMode(GL_RENDER))869 return -1;870 871 return buffer[3];872 }873 595 /************************************************************ 874 596 * OPEN FILE. opens a new fits file … … 1006 728 calibInputFile->GetNextRow(); 1007 729 1008 for (int i=0;i<1024;i++)1009 cout << gainMean[i] << " ";1010 cout << endl << endl;730 // for (int i=0;i<1024;i++) 731 // cout << gainMean[i] << " "; 732 // cout << endl << endl; 1011 733 1012 734 delete calibInputFile; … … 1066 788 for (int j=0;j<nRoi;j++) 1067 789 { 790 int realj = (j+startPix[j])%1024; 1068 791 eventData[i*1024+j] *= 2000.f/4096.f; 1069 eventData[i*1024+j] -= (baseLineMean[i*1024+ j]+triggerOffsetMean[i*1024+j]);1070 eventData[i*1024+j] /= gainMean[i*1024+ j];792 eventData[i*1024+j] -= (baseLineMean[i*1024+realj]+triggerOffsetMean[i*1024+realj]); 793 eventData[i*1024+j] /= gainMean[i*1024+realj]; 1071 794 eventData[i*1024+j] *= (50000.f/65536.f) * 2500.f; 1072 795 } … … 1150 873 // cout << "start value: " << viewer->eventData[i*1024+j] << " baseline: " << viewer->baseLineMean[i*1024+j]; 1151 874 // cout << " triggerOffset: " << viewer->triggerOffsetMean[i*1024+j] << " gain: " << viewer->gainMean[i*1024+j]; 875 int realj = (j+viewer->startPix[j])%1024; 1152 876 viewer->eventData[i*1024+j] *= 2000.f/4096.f; 1153 viewer->eventData[i*1024+j] -= (viewer->baseLineMean[i*1024+ j]+viewer->triggerOffsetMean[i*1024+j]);1154 viewer->eventData[i*1024+j] /= viewer->gainMean[i*1024+ j];877 viewer->eventData[i*1024+j] -= (viewer->baseLineMean[i*1024+realj]+viewer->triggerOffsetMean[i*1024+realj]); 878 viewer->eventData[i*1024+j] /= viewer->gainMean[i*1024+realj]; 1155 879 viewer->eventData[i*1024+j] *= (50000.f/65536.f) * 2500.f; 1156 880 // cout << " end value: " << viewer->eventData[i*1024+j] << endl; … … 1171 895 for (int j=0;j<viewer->nRoi;j++) 1172 896 { 1173 897 int realj = (j+viewer->startPix[j])%1024; 1174 898 viewer->eventData[i*1024+j] /= (50000.f/65536.f) * 2500.f; 1175 viewer->eventData[i*1024+j] *= viewer->gainMean[i*1024+ j];1176 viewer->eventData[i*1024+j] += (viewer->baseLineMean[i*1024+ j]+viewer->triggerOffsetMean[i*1024+j]);899 viewer->eventData[i*1024+j] *= viewer->gainMean[i*1024+realj]; 900 viewer->eventData[i*1024+j] += (viewer->baseLineMean[i*1024+realj]+viewer->triggerOffsetMean[i*1024+realj]); 1177 901 viewer->eventData[i*1024+j] /= 2000.f/4096.f; 1178 902 } … … 1181 905 1182 906 } 907 autoScalePressed(); 1183 908 1184 909 } … … 1249 974 void UIConnector::rangeChanged0(double value) 1250 975 { 1251 ss[0] = (float)value;976 viewer->ss[0] = (float)value; 1252 977 viewer->updateGL(); 1253 978 } … … 1257 982 void UIConnector::rangeChanged1(double value) 1258 983 { 1259 ss[1] = (float)value;984 viewer->ss[1] = (float)value; 1260 985 viewer->updateGL(); 1261 986 } … … 1265 990 void UIConnector::rangeChanged2(double value) 1266 991 { 1267 ss[2] = (float)value;992 viewer->ss[2] = (float)value; 1268 993 viewer->updateGL(); 1269 994 } … … 1273 998 void UIConnector::rangeChanged3(double value) 1274 999 { 1275 ss[3] = (float)value;1000 viewer->ss[3] = (float)value; 1276 1001 viewer->updateGL(); 1277 1002 } … … 1281 1006 void UIConnector::rangeChanged4(double value) 1282 1007 { 1283 ss[4] = (float)value;1008 viewer->ss[4] = (float)value; 1284 1009 viewer->updateGL(); 1285 1010 } … … 1289 1014 void UIConnector::redChanged0(double value) 1290 1015 { 1291 rr[0] = (float)value;1016 viewer->rr[0] = (float)value; 1292 1017 viewer->updateGL(); 1293 1018 } … … 1297 1022 void UIConnector::redChanged1(double value) 1298 1023 { 1299 rr[1] = (float)value;1024 viewer->rr[1] = (float)value; 1300 1025 viewer->updateGL(); 1301 1026 } … … 1305 1030 void UIConnector::redChanged2(double value) 1306 1031 { 1307 rr[2] = (float)value;1032 viewer->rr[2] = (float)value; 1308 1033 viewer->updateGL(); 1309 1034 } … … 1313 1038 void UIConnector::redChanged3(double value) 1314 1039 { 1315 rr[3] = (float)value;1040 viewer->rr[3] = (float)value; 1316 1041 viewer->updateGL(); 1317 1042 } … … 1321 1046 void UIConnector::redChanged4(double value) 1322 1047 { 1323 rr[4] = (float)value;1048 viewer->rr[4] = (float)value; 1324 1049 viewer->updateGL(); 1325 1050 } … … 1329 1054 void UIConnector::greenChanged0(double value) 1330 1055 { 1331 gg[0] = (float)value;1056 viewer->gg[0] = (float)value; 1332 1057 viewer->updateGL(); 1333 1058 } … … 1337 1062 void UIConnector::greenChanged1(double value) 1338 1063 { 1339 gg[1] = (float)value;1064 viewer->gg[1] = (float)value; 1340 1065 viewer->updateGL(); 1341 1066 } … … 1345 1070 void UIConnector::greenChanged2(double value) 1346 1071 { 1347 gg[2] = (float)value;1072 viewer->gg[2] = (float)value; 1348 1073 viewer->updateGL(); 1349 1074 } … … 1353 1078 void UIConnector::greenChanged3(double value) 1354 1079 { 1355 gg[3] = (float)value;1080 viewer->gg[3] = (float)value; 1356 1081 viewer->updateGL(); 1357 1082 } … … 1361 1086 void UIConnector::greenChanged4(double value) 1362 1087 { 1363 gg[4] = (float)value;1088 viewer->gg[4] = (float)value; 1364 1089 viewer->updateGL(); 1365 1090 } … … 1369 1094 void UIConnector::blueChanged0(double value) 1370 1095 { 1371 bb[0] = (float)value;1096 viewer->bb[0] = (float)value; 1372 1097 viewer->updateGL(); 1373 1098 } … … 1377 1102 void UIConnector::blueChanged1(double value) 1378 1103 { 1379 bb[1] = (float)value;1104 viewer->bb[1] = (float)value; 1380 1105 viewer->updateGL(); 1381 1106 } … … 1385 1110 void UIConnector::blueChanged2(double value) 1386 1111 { 1387 bb[2] = (float)value;1112 viewer->bb[2] = (float)value; 1388 1113 viewer->updateGL(); 1389 1114 } … … 1393 1118 void UIConnector::blueChanged3(double value) 1394 1119 { 1395 bb[3] = (float)value;1120 viewer->bb[3] = (float)value; 1396 1121 viewer->updateGL(); 1397 1122 } … … 1401 1126 void UIConnector::blueChanged4(double value) 1402 1127 { 1403 bb[4] = (float)value;1128 viewer->bb[4] = (float)value; 1404 1129 viewer->updateGL(); 1405 1130 } … … 1544 1269 emit updateCurrentPixelSliceValue(qstr); 1545 1270 1271 if (autoScaleColor->isChecked()) 1272 emit viewer->colorPaletteHasChanged();//autoScalePressed(); 1273 1546 1274 boardsTimeList->clear(); 1547 1275 startPixelsList->clear(); … … 1896 1624 return; 1897 1625 1626 if (hwID == pixel) 1627 return; 1898 1628 for (int i=0;i<viewer->nRoi;i++) 1899 1629 { … … 1918 1648 hwID = pixel; 1919 1649 swID = viewer->softwareMapping[pixel]; 1920 crateID = (pixel/4)/10; 1921 boardID = (pixel/4)%10; 1922 patchID = pixel%4; 1923 HwIDBox->setValue(hwID); 1924 SwIDBox->setValue(swID); 1925 crateIDBox->setValue(crateID); 1926 boardIDBox->setValue(boardID); 1927 patchIDBox->setValue(patchID); 1650 // cout << "here" << endl; 1651 /* int channel = hwID%360; 1652 channel = channel%36; 1653 channel = channel%9; 1654 int inter = (pixel-channel)%360; 1655 inter = inter%36; 1656 patchID = inter/9; 1657 inter = pixel - channel - patchID*9; 1658 inter = inter%360; 1659 boardID = inter/36; 1660 inter = pixel - channel - patchID*9 - boardID*36; 1661 crateID = inter/360; 1662 */ 1663 crateID = pixel/360; 1664 boardID = (pixel - crateID*360)/36; 1665 patchID = (pixel - crateID*360 - boardID*36)/9; 1666 // cout << "Value: " << hwID << " " << swID; 1667 // cout << " " << crateID << " " << boardID; 1668 // cout << " " << patchID << endl; 1669 // cout << "there " << crateID << " " << boardID << " " << patchID << endl; 1670 // crateID = (pixel/4)/10; 1671 // boardID = (pixel/4)%10; 1672 // patchID = pixel%4; 1673 // cout << "there2 " << crateID << " " << boardID << " " << patchID << endl; 1674 1675 if (HwIDBox->value() != hwID) 1676 HwIDBox->setValue(hwID); 1677 if (SwIDBox->value() != swID) 1678 SwIDBox->setValue(swID); 1679 if (crateIDBox->value() != crateID) 1680 crateIDBox->setValue(crateID); 1681 if (boardIDBox->value() != boardID) 1682 boardIDBox->setValue(boardID); 1683 if (patchIDBox->value() != patchID) 1684 patchIDBox->setValue(patchID); 1928 1685 1929 1686 ostringstream str; … … 1945 1702 hwID = hwid; 1946 1703 swID = viewer->softwareMapping[hwid]; 1947 crateID = (hwid/4)/10; 1948 boardID = (hwid/4)%10; 1949 patchID = hwid%4; 1704 crateID = hwID/360; 1705 boardID = (hwID - crateID*360)/36; 1706 patchID = (hwID - crateID*360 - boardID*36)/9; 1707 1708 // crateID = (hwid/4)/10; 1709 // boardID = (hwid/4)%10; 1710 // patchID = hwid%4; 1950 1711 HwIDBox->setValue(hwID); 1951 1712 SwIDBox->setValue(swID); … … 1963 1724 swID = swid; 1964 1725 hwID = viewer->hardwareMapping[swid]; 1965 crateID = (hwID/4)/10; 1966 boardID = (hwID/4)%10; 1967 patchID = hwID%4; 1726 crateID = hwID/360; 1727 boardID = (hwID - crateID*360)/36; 1728 patchID = (hwID - crateID*360 - boardID*36)/9; 1729 1730 // crateID = (hwID/4)/10; 1731 // boardID = (hwID/4)%10; 1732 // patchID = hwID%4; 1968 1733 HwIDBox->setValue(hwID); 1969 1734 SwIDBox->setValue(swID); … … 1978 1743 void UIConnector::crateIDChanged(int cid) 1979 1744 { 1745 hwID -= 360*crateID; 1980 1746 crateID = cid; 1981 hwID = 40*crateID + 4*boardID + patchID;1747 hwID += 360*crateID; 1982 1748 swID = viewer->softwareMapping[hwID]; 1983 1749 HwIDBox->setValue(hwID); … … 1989 1755 void UIConnector::boardIDChanged(int bid) 1990 1756 { 1757 hwID -= 36*boardID; 1991 1758 boardID = bid; 1992 hwID = 40*crateID + 4*boardID + patchID;1759 hwID += 36*boardID; 1993 1760 swID = viewer->softwareMapping[hwID]; 1994 1761 HwIDBox->setValue(hwID); … … 2000 1767 void UIConnector::patchIDChanged(int pid) 2001 1768 { 1769 hwID -= 9*patchID; 2002 1770 patchID = pid; 2003 hwID = 40*crateID + 4*boardID +patchID;1771 hwID += 9*patchID; 2004 1772 swID = viewer->softwareMapping[hwID]; 2005 1773 HwIDBox->setValue(hwID); … … 2011 1779 void UIConnector::autoScalePressed() 2012 1780 { 1781 if (!autoScaleColor->isChecked()) 1782 return; 2013 1783 if (!viewer->nRoi) 2014 1784 return; … … 2047 1817 double maxRange = (double)(max+(VALUES_SPAN/2))/(double)VALUES_SPAN; 2048 1818 double midRange = (double)(average+(VALUES_SPAN/2))/(double)VALUES_SPAN; 2049 ss[0] = minRange; 2050 range0->setValue(ss[0]); 2051 ss[4] = maxRange; 2052 range4->setValue(ss[4]); 2053 ss[2] = midRange; 2054 range2->setValue(ss[2]); 2055 ss[1] = (minRange+midRange)/2; 2056 range1->setValue(ss[1]); 2057 ss[3] = (maxRange+midRange)/2; 2058 range3->setValue(ss[3]); 1819 if (viewer->logScale) 1820 { 1821 minRange *= 9; 1822 maxRange *= 9; 1823 // midRange *= 9; 1824 minRange += 1; 1825 maxRange += 1; 1826 // midRange += 1; 1827 minRange = log10(minRange); 1828 maxRange = log10(maxRange); 1829 // midRange = (minRange + maxRange)/2.f; 1830 midRange = log10(midRange); 1831 } 1832 viewer->ss[0] = minRange; 1833 range0->setValue(viewer->ss[0]); 1834 viewer->ss[4] = maxRange; 1835 range4->setValue(viewer->ss[4]); 1836 viewer->ss[2] = midRange; 1837 range2->setValue(viewer->ss[2]); 1838 viewer->ss[1] = (minRange+midRange)/2; 1839 range1->setValue(viewer->ss[1]); 1840 viewer->ss[3] = (maxRange+midRange)/2; 1841 range3->setValue(viewer->ss[3]); 2059 1842 2060 1843 … … 2118 1901 int main(int argc, char *argv[]) 2119 1902 { 1903 QApplication app(argc, argv); 1904 1905 if (!QGLFormat::hasOpenGL()) { 1906 std::cerr << "This system has no OpenGL support" << std::endl; 1907 return 1; 1908 } 1909 1910 QMainWindow mainWindow; 1911 1912 Ui_MainWindow myUi; 1913 myUi.setupUi(&mainWindow); 1914 1915 UIConnector connector; 1916 1917 RawDataViewer *canvas = myUi.GLWindow; 1918 2120 1919 Configuration conf(argv[0]); 2121 1920 conf.SetPrintUsage(PrintHelp); … … 2133 1932 } 2134 1933 for (int i=0;i<5;i++) 2135 ss[i] = value[i];1934 canvas->ss[i] = value[i]; 2136 1935 } 2137 1936 … … 2145 1944 } 2146 1945 for (int i=0;i<5;i++) 2147 rr[i] = value[i];1946 canvas->rr[i] = value[i]; 2148 1947 } 2149 1948 … … 2157 1956 } 2158 1957 for (int i=0;i<5;i++) 2159 gg[i] = value[i];1958 canvas->gg[i] = value[i]; 2160 1959 } 2161 1960 … … 2169 1968 } 2170 1969 for (int i=0;i<5;i++) 2171 bb[i] = value[i]; 2172 } 2173 2174 QApplication app(argc, argv); 2175 2176 if (!QGLFormat::hasOpenGL()) { 2177 std::cerr << "This system has no OpenGL support" << std::endl; 2178 return 1; 2179 } 2180 2181 QMainWindow mainWindow; 2182 2183 Ui_MainWindow myUi; 2184 myUi.setupUi(&mainWindow); 2185 2186 RawDataViewer *canvas = myUi.GLWindow; 1970 canvas->bb[i] = value[i]; 1971 } 1972 1973 2187 1974 2188 1975 QObject::connect(myUi.eventsMinusButton, SIGNAL(clicked()), … … 2192 1979 QObject::connect(myUi.eventsStepBox, SIGNAL(valueChanged(int)), 2193 1980 canvas, SLOT(setEventStep(int))); 2194 myUi.colorRange0->setValue(ss[0]); 2195 myUi.colorRange1->setValue(ss[1]); 2196 myUi.colorRange2->setValue(ss[2]); 2197 myUi.colorRange3->setValue(ss[3]); 2198 myUi.colorRange4->setValue(ss[4]); 2199 myUi.redValue0->setValue(rr[0]); 2200 myUi.redValue1->setValue(rr[1]); 2201 myUi.redValue2->setValue(rr[2]); 2202 myUi.redValue3->setValue(rr[3]); 2203 myUi.redValue4->setValue(rr[4]); 2204 myUi.greenValue0->setValue(gg[0]); 2205 myUi.greenValue1->setValue(gg[1]); 2206 myUi.greenValue2->setValue(gg[2]); 2207 myUi.greenValue3->setValue(gg[3]); 2208 myUi.greenValue4->setValue(gg[4]); 2209 myUi.blueValue0->setValue(bb[0]); 2210 myUi.blueValue1->setValue(bb[1]); 2211 myUi.blueValue2->setValue(bb[2]); 2212 myUi.blueValue3->setValue(bb[3]); 2213 myUi.blueValue4->setValue(bb[4]); 2214 2215 UIConnector connector; 1981 myUi.colorRange0->setValue(canvas->ss[0]); 1982 myUi.colorRange1->setValue(canvas->ss[1]); 1983 myUi.colorRange2->setValue(canvas->ss[2]); 1984 myUi.colorRange3->setValue(canvas->ss[3]); 1985 myUi.colorRange4->setValue(canvas->ss[4]); 1986 myUi.redValue0->setValue(canvas->rr[0]); 1987 myUi.redValue1->setValue(canvas->rr[1]); 1988 myUi.redValue2->setValue(canvas->rr[2]); 1989 myUi.redValue3->setValue(canvas->rr[3]); 1990 myUi.redValue4->setValue(canvas->rr[4]); 1991 myUi.greenValue0->setValue(canvas->gg[0]); 1992 myUi.greenValue1->setValue(canvas->gg[1]); 1993 myUi.greenValue2->setValue(canvas->gg[2]); 1994 myUi.greenValue3->setValue(canvas->gg[3]); 1995 myUi.greenValue4->setValue(canvas->gg[4]); 1996 myUi.blueValue0->setValue(canvas->bb[0]); 1997 myUi.blueValue1->setValue(canvas->bb[1]); 1998 myUi.blueValue2->setValue(canvas->bb[2]); 1999 myUi.blueValue3->setValue(canvas->bb[3]); 2000 myUi.blueValue4->setValue(canvas->bb[4]); 2001 2216 2002 connector.setViewer(canvas); 2217 2003 connector.boardsTimeList = myUi.boardsTimeList; … … 2223 2009 connector.triggerDelayHisto = myUi.triggerDelayHisto; 2224 2010 connector.triggerDelayList = myUi.triggerDelayList; 2011 connector.autoScaleColor = myUi.autoScaleColor; 2225 2012 2226 2013 connector.startTimeMarksList = myUi.startTimeMarksList; … … 2260 2047 QObject::connect(myUi.autoScaleColor, SIGNAL(clicked()), 2261 2048 &connector, SLOT(autoScalePressed())); 2049 QObject::connect(canvas, SIGNAL(colorPaletteHasChanged()), 2050 &connector, SLOT(autoScalePressed())); 2051 2262 2052 QObject::connect(myUi.currentPixelScale, SIGNAL(toggled(bool)), 2263 2053 &connector, SLOT(currentPixelChanged(bool))); -
trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.h
r11898 r11901 20 20 #include <QtGui/QListWidget> 21 21 #include <QtGui/QMainWindow> 22 #include <QtOpenGL/QGLWidget> 22 #include <QtGui/QPushButton> 23 24 //#include <QtOpenGL/QGLWidget> 25 #include "../BasicGlCamera.h" 26 23 27 #include <QtGui/QMouseEvent> 24 28 #include <QtGui/QColorDialog> … … 42 46 #include "externals/fits.h" 43 47 44 using namespace std;45 46 #define NUM_STORED_EVENTS 547 #define MAX_NUM_PIXELS 160048 #define ACTUAL_NUM_PIXELS 144049 50 ///structure for storing edges of hexagons (for blurry display)51 struct edge52 {53 int first;54 int second;55 };56 57 ///structure for storing neighbors of pixels. For camera position calculation and blurry display58 struct PixelsNeighbors59 {60 //neighbors. clockwise, starting from top61 int neighbors[6];62 PixelsNeighbors()63 {64 for (int i=0;i<6;i++)65 neighbors[i] = -1;66 }67 int& operator[](int index){return neighbors[index];}68 };69 70 48 /************************************************* 71 49 * Class Raw Data Viewer. FACT raw data diplayer 72 50 *************************************************/ 73 class RawDataViewer : public QGLWidget51 class RawDataViewer : public BasicGlCamera//QGLWidget 74 52 { 75 53 Q_OBJECT … … 82 60 void openCalibFile(string& file); 83 61 62 63 84 64 public Q_SLOTS: 85 65 void plusEvent(); … … 94 74 void newFileLoaded(); 95 75 void signalCurrentPixel(int pixel); 76 void signalAutoScaleNeeded(); 96 77 97 78 protected: 98 void initializeGL();99 void resizeGL(int width, int height);79 // void initializeGL(); 80 // void resizeGL(int width, int height); 100 81 void paintGL(); 101 82 void mousePressEvent(QMouseEvent *event); … … 103 84 void mouseDoubleClickEvent(QMouseEvent *event); 104 85 void drawCamera(bool alsoWire); 105 void drawPatches();106 int PixelAtPosition(const QPoint &pos);107 void drawHexagon(int index, bool solid);86 // void drawPatches(); 87 // int PixelAtPosition(const QPoint &pos); 88 // void drawHexagon(int index, bool solid); 108 89 int selectedPixel; 109 90 float *eventData; … … 112 93 private: 113 94 void drawPixelCurve(); 114 void updateNeighbors(int currentPixel);115 void skipPixels(int start, int howMany);116 void calculatePixelsCoords();95 // void updateNeighbors(int currentPixel); 96 // void skipPixels(int start, int howMany); 97 // void calculatePixelsCoords(); 117 98 void setCorrectSlice(QMouseEvent* event); 118 99 void eventStepping(bool plus); 119 void buildVerticesList();100 // void buildVerticesList(); 120 101 void buildPatchesIndices(); 121 102 void calcBlurColor(int pixel, int vertex); 122 103 void drawBlurryHexagon(int index); 123 float hexRadius;124 float hexTolerance;125 float viewSize;126 104 int whichSlice; 127 float pixelSize; 128 float shownSizex; 129 float shownSizey; 105 // float shownSizex; 106 // float shownSizey; 130 107 bool drawPatch; 131 108 bool drawImpulse; … … 165 142 int eventStep; 166 143 167 int hardwareMapping[1440];168 int softwareMapping[1440];169 int patches[160][9];144 // int hardwareMapping[1440]; 145 // int softwareMapping[1440]; 146 //// int patches[160][9]; 170 147 GLfloat patchesColor[160][3]; 171 vector<edge> patchesIndices[160];148 // vector<edge> patchesIndices[160]; 172 149 fits* inputFile; 173 150 fits* calibInputFile; … … 180 157 QPoint lastPos; 181 158 182 GLfloat pixelsCoords[MAX_NUM_PIXELS][3];183 PixelsNeighbors neighbors[MAX_NUM_PIXELS];184 GLfloat pixelsColor[ACTUAL_NUM_PIXELS][3];185 GLfloat verticesList[ACTUAL_NUM_PIXELS*6][2];186 int verticesIndices[ACTUAL_NUM_PIXELS][6];187 int numVertices;159 // GLfloat pixelsCoords[MAX_NUM_PIXELS][3]; 160 // PixelsNeighbors neighbors[MAX_NUM_PIXELS]; 161 // GLfloat pixelsColor[ACTUAL_NUM_PIXELS][3]; 162 // GLfloat verticesList[ACTUAL_NUM_PIXELS*6][2]; 163 // int verticesIndices[ACTUAL_NUM_PIXELS][6]; 164 // int numVertices; 188 165 }; 189 166 190 class Camera : public RawDataViewer191 {192 Q_OBJECT193 194 typedef pair<double, double> Position;195 typedef vector<Position> Positions;196 197 Positions fGeom;198 199 valarray<double> fData;200 vector<bool> fBold;201 vector<bool> fEnable;202 203 int fWhite;204 205 int64_t fMin;206 int64_t fMax;207 208 public:209 Camera(QWidget *pparent = 0);210 void Reset();211 void SetBold(int idx);212 void SetWhite(int idx);213 void SetEnable(int idx, bool b);214 void Toggle(int idx);215 double GetData(int idx);216 void SetMin(int64_t min);217 void SetMax(int64_t max);218 const char *GetName();219 220 void Paint();221 222 int GetIdx(float px, float py);223 char *GetObjectInfo(int px, int py);224 225 void SetData(const valarray<double> &ddata);226 227 };228 167 /************************************************* 229 168 * Class UIConnector. used to connect the interface to the raw data displayer … … 335 274 QwtPlotCurve triggerDelayHistoItem; 336 275 QwtPlotZoomer* triggerDelayHistoZoom; 276 277 QPushButton* autoScaleColor; 278 337 279 QListWidget* triggerDelayList; 338 280 -
trunk/FACT++/gui/RawEventsViewer/viewer.ui
r11753 r11901 339 339 <widget class="QSpinBox" name="crateIDBox"> 340 340 <property name="maximum"> 341 <number> 39</number>341 <number>99</number> 342 342 </property> 343 343 <property name="value"> 344 <number> 9</number>344 <number>0</number> 345 345 </property> 346 346 </widget> … … 349 349 <widget class="QSpinBox" name="boardIDBox"> 350 350 <property name="maximum"> 351 <number>9 </number>351 <number>99</number> 352 352 </property> 353 353 <property name="value"> 354 <number> 8</number>354 <number>0</number> 355 355 </property> 356 356 </widget> … … 359 359 <widget class="QSpinBox" name="patchIDBox"> 360 360 <property name="maximum"> 361 <number> 3</number>361 <number>99</number> 362 362 </property> 363 363 <property name="value"> 364 <number> 1</number>364 <number>0</number> 365 365 </property> 366 366 </widget> … … 775 775 </property> 776 776 <property name="text"> 777 <string>AutoScale !</string> 777 <string>AutoScale</string> 778 </property> 779 <property name="checkable"> 780 <bool>true</bool> 778 781 </property> 779 782 </widget>
Note:
See TracChangeset
for help on using the changeset viewer.