Changeset 11901 for trunk/FACT++/gui/RawEventsViewer
- Timestamp:
- 08/12/11 16:23:54 (13 years ago)
- Location:
- trunk/FACT++/gui/RawEventsViewer
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
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.