Changeset 673 for trunk/geant4
- Timestamp:
- Jan 9, 2008, 12:07:04 PM (17 years ago)
- Location:
- trunk/geant4/visualization/OpenGL
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/geant4/visualization/OpenGL/include/G4OpenGLQtViewer.hh
r656 r673 68 68 void ShowView (); 69 69 virtual void updateQWidget()=0; 70 void setupViewport(int, int); 70 71 71 72 protected: … … 74 75 void manageContextMenuEvent(QContextMenuEvent *e); 75 76 void G4MousePressEvent(QPoint); 77 void G4MouseReleaseEvent(QPoint p); 78 void G4MouseDoubleClickEvent(QPoint p); 76 79 #if QT_VERSION < 0x040000 77 80 void G4MouseMoveEvent(int, int, Qt::ButtonState); … … 119 122 void actionDrawingSurfaceRemoval(); 120 123 void actionDrawingLineSurfaceRemoval(); 121 void actionControlPanels();122 void actionExitG4();124 // void actionControlPanels(); 125 // void actionExitG4(); 123 126 void actionCreateEPS(); 124 127 -
trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredQtViewer.hh
r600 r673 66 66 void mousePressEvent(QMouseEvent *event); 67 67 void mouseMoveEvent(QMouseEvent *event); 68 void mouseDoubleClickEvent(QMouseEvent *event); 69 void mouseReleaseEvent(QMouseEvent *event); 68 70 void contextMenuEvent(QContextMenuEvent *e); 69 71 … … 71 73 bool hasToRepaint; 72 74 bool readyToPaint; 75 bool zoomAction; 73 76 int nbPaint; 77 QPoint beginZoom; 78 QPoint endZoom; 79 QImage glBufferImage; 74 80 }; 75 81 -
trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateQtViewer.cc
r608 r673 139 139 //Make sure current viewer is attached and clean... 140 140 //Qt version needed 141 glViewport (0, 0, WinSize_x, WinSize_y);141 // glViewport (0, 0, WinSize_x, WinSize_y); 142 142 143 143 if(style!=G4ViewParameters::hlr && … … 191 191 ,int height) 192 192 { 193 int side = width; 194 if (width > height) { 195 side = height; 196 } 197 glViewport((width - side) / 2, (height - side) / 2, side, side); 198 glMatrixMode(GL_PROJECTION); 199 glLoadIdentity(); 200 glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0); 201 glMatrixMode(GL_MODELVIEW); 193 setupViewport(width,height); 202 194 #ifdef GEANT4_QT_DEBUG 203 195 printf("G4OpenGLImmediateQtViewer::resizeGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n"); … … 223 215 WinSize_y = (G4int) height(); 224 216 225 glViewport (0, 0, width(),height());217 setupViewport(width(),height()); 226 218 227 219 SetView(); -
trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc
r660 r673 97 97 } 98 98 99 /** 100 * Set the viewport of the scene 101 */ 102 void G4OpenGLQtViewer::setupViewport(int aWidth, int aHeight) 103 { 104 int side = qMin(aWidth, aHeight); 105 glViewport((aWidth - side) / 2, (aHeight - side) / 2, side, side); 106 107 glMatrixMode(GL_PROJECTION); 108 glLoadIdentity(); 109 glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0); 110 glMatrixMode(GL_MODELVIEW); 111 } 99 112 100 113 … … 514 527 515 528 #if QT_VERSION < 0x030200 516 QAction *controlPanels = new QAction("&Control panels","&Control panels",CTRL+Key_C,mActions);517 QAction *exitG4 = new QAction("&Exit to G4Vis >","&Exit to G4Vis >",CTRL+Key_E,mActions);529 // QAction *controlPanels = new QAction("&Control panels","&Control panels",CTRL+Key_C,mActions); 530 // QAction *exitG4 = new QAction("&Exit to G4Vis >","&Exit to G4Vis >",CTRL+Key_E,mActions); 518 531 QAction *createEPS = new QAction("&Save as ...","&Save as ...",CTRL+Key_S,mActions); 519 532 #else 520 QAction *controlPanels = new QAction("&Control panels",CTRL+Key_C,mActions);521 QAction *exitG4 = new QAction("&Exit to G4Vis >",CTRL+Key_E,mActions);533 // QAction *controlPanels = new QAction("&Control panels",CTRL+Key_C,mActions); 534 // QAction *exitG4 = new QAction("&Exit to G4Vis >",CTRL+Key_E,mActions); 522 535 QAction *createEPS = new QAction("&Save as ...",CTRL+Key_S,mActions); 523 536 #endif 524 controlPanels->addTo(mActions);525 exitG4->addTo(mActions);537 // controlPanels->addTo(mActions); 538 // exitG4->addTo(mActions); 526 539 createEPS->addTo(mActions); 527 QObject ::connect(controlPanels,528 SIGNAL(activated()),529 this,530 SLOT(actionControlPanels()));531 QObject ::connect(exitG4,532 SIGNAL(activated()),533 this,534 SLOT(actionExitG4()));540 // QObject ::connect(controlPanels, 541 // SIGNAL(activated()), 542 // this, 543 // SLOT(actionControlPanels())); 544 // QObject ::connect(exitG4, 545 // SIGNAL(activated()), 546 // this, 547 // SLOT(actionExitG4())); 535 548 QObject ::connect(createEPS, 536 549 SIGNAL(activated()), … … 541 554 // === Action Menu === 542 555 QMenu *mActions = fContextMenu->addMenu("&Actions"); 543 QAction *controlPanels = mActions->addAction("Control panels");544 QAction *exitG4 = mActions->addAction("Exit to G4Vis >");556 // QAction *controlPanels = mActions->addAction("Control panels"); 557 // QAction *exitG4 = mActions->addAction("Exit to G4Vis >"); 545 558 QAction *createEPS = mActions->addAction("Save as ..."); 546 QObject ::connect(controlPanels,547 SIGNAL(triggered()),548 this,549 SLOT(actionControlPanels()));550 QObject ::connect(exitG4,551 SIGNAL(triggered()),552 this,553 SLOT(actionExitG4()));559 // QObject ::connect(controlPanels, 560 // SIGNAL(triggered()), 561 // this, 562 // SLOT(actionControlPanels())); 563 // QObject ::connect(exitG4, 564 // SIGNAL(triggered()), 565 // this, 566 // SLOT(actionExitG4())); 554 567 QObject ::connect(createEPS, 555 568 SIGNAL(triggered()), … … 1031 1044 1032 1045 1033 void G4OpenGLQtViewer::actionControlPanels() {1034 #ifdef GEANT4_QT_DEBUG1035 printf("G4OpenGLQtViewer::actionControlPanels \n");1036 #endif1037 }1038 1039 void G4OpenGLQtViewer::actionExitG4() {1040 #ifdef GEANT4_QT_DEBUG1041 printf("G4OpenGLQtViewer::actionExitG4() \n");1042 #endif1043 }1046 // void G4OpenGLQtViewer::actionControlPanels() { 1047 // #ifdef GEANT4_QT_DEBUG 1048 // printf("G4OpenGLQtViewer::actionControlPanels \n"); 1049 // #endif 1050 // } 1051 1052 // void G4OpenGLQtViewer::actionExitG4() { 1053 // #ifdef GEANT4_QT_DEBUG 1054 // printf("G4OpenGLQtViewer::actionExitG4() \n"); 1055 // #endif 1056 // } 1044 1057 1045 1058 void G4OpenGLQtViewer::actionCreateEPS() { … … 1194 1207 } 1195 1208 1209 1196 1210 /** 1197 1211 @param pos_x mouse x position … … 1203 1217 void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::ButtonState mButtons) 1204 1218 #else 1205 void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons)1219 void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons) 1206 1220 #endif 1207 1221 { 1208 1222 int dx = pos_x - lastPos.x(); 1209 1223 int dy = pos_y - lastPos.y(); 1210 1211 1224 if (fMouseAction) { // rotate 1212 1225 if (mButtons & Qt::LeftButton) { … … 1292 1305 } 1293 1306 1294 1295 1307 /** This is the benning of a rescale function. It does nothing for the moment 1296 1308 @param aWidth : new width … … 1308 1320 FILE* file; 1309 1321 1310 feedback_buffer = new GLfloat[size];1311 glFeedbackBuffer (size, GL_3D_COLOR, feedback_buffer);1312 glRenderMode (GL_FEEDBACK);1313 1314 glViewport (0, 0, aWidth, aHeight);1315 DrawView();1316 returned = glRenderMode (GL_RENDER);1322 // feedback_buffer = new GLfloat[size]; 1323 // glFeedbackBuffer (size, GL_3D_COLOR, feedback_buffer); 1324 // glRenderMode (GL_FEEDBACK); 1325 1326 // glViewport (0, 0, aWidth, aHeight); 1327 // DrawView(); 1328 // returned = glRenderMode (GL_RENDER); 1317 1329 1318 1330 } … … 1358 1370 } else { 1359 1371 #if QT_VERSION < 0x040000 1360 G4cerr << "Could not open "<< file.ascii()<<"\n" << G4endl;1361 #else 1362 G4cerr << "Could not open "<< file.toStdString().c_str()<<"\n" << G4endl;1372 G4cerr << "Could not open "<< aFilename.ascii()<<"\n" << G4endl; 1373 #else 1374 G4cerr << "Could not open "<< aFilename.toStdString().c_str()<<"\n" << G4endl; 1363 1375 #endif 1364 1376 } -
trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc
r652 r673 43 43 //#include <qmouseevent.h> 44 44 #include <qevent.h> // include <qcontextmenuevent.h> 45 #include <qpainter.h> 45 46 46 47 G4OpenGLStoredQtViewer::G4OpenGLStoredQtViewer … … 53 54 QGLWidget() // FIXME : gerer le pb du parent ! 54 55 { 56 zoomAction = false; 55 57 nbPaint =0; 56 58 hasToRepaint =false; … … 230 232 ,int aHeight) 231 233 { 232 glViewport(0, 0, aWidth, aHeight); 233 glMatrixMode(GL_PROJECTION); 234 glMatrixMode(GL_MODELVIEW); 234 setupViewport(aWidth,aHeight); 235 236 // glViewport(0, 0, aWidth, aHeight); 237 // glMatrixMode(GL_PROJECTION); 238 // glMatrixMode(GL_MODELVIEW); 235 239 236 240 if (((WinSize_x != (G4int)aWidth)) || (WinSize_y != (G4int) aHeight)) { … … 246 250 247 251 252 /** 253 @see : 254 */ 248 255 249 256 void G4OpenGLStoredQtViewer::paintGL() 250 257 { 251 if (!readyToPaint) { 252 #ifdef GEANT4_QT_DEBUG 253 printf("G4OpenGLStoredQtViewer::paintGL ============ Not ready %d\n",readyToPaint); 254 #endif 255 readyToPaint= true; 256 return; 257 } 258 // DO NOT RESIZE IF SIZE HAS NOT CHANGE : 259 // WHEN CLICK ON THE FRAME FOR EXAMPLE 260 // EXECEPT WHEN MOUSE MOVE EVENT 261 if ( !hasToRepaint) { 262 if (((WinSize_x == (G4int)width())) &&(WinSize_y == (G4int) height())) { 263 #ifdef GEANT4_QT_DEBUG 264 printf("G4OpenGLStoredQtViewer::paintGL ============ Dont repaint\n"); 265 #endif 258 if (zoomAction) { 259 QPainter painter; 260 painter.begin(this); 261 // painter.setRenderHint(QPainter::Antialiasing); 262 QColor bg = QColor(glBufferImage.pixel(0,0)); 263 printf("%d+%d+%d+%d %d+%d+%d+%d",bg.red(),bg.green(),bg.blue(),bg.alpha(),qAlpha(glBufferImage.pixel(0,0)),qRed(glBufferImage.pixel(0,0)),qGreen(glBufferImage.pixel(0,0)),qBlue(glBufferImage.pixel(0,0))); 264 painter.setBackground(QBrush(bg)); 265 // painter.drawRect(10,10,50,80); 266 // QImage test = grabFrameBuffer().copy(); 267 // painter.drawImage(0, 0,test); 268 for (int ay=0;ay<glBufferImage.height();ay++) { 269 for (int ax=0;ax<glBufferImage.width();ax++) { 270 if(QColor(glBufferImage.pixel(ax,ay)) != bg) { 271 // painter.setPen(QColor(glBufferImage.pixel(ax,ay))); 272 // painter.drawPoint(ax,glBufferImage.height()-ay); 273 } else { 274 printf("o"); 275 } 276 // printf("%d+%d+%d+%d ",QColor(glBufferImage.pixel(ax,ay)).red(),QColor(glBufferImage.pixel(ax,ay)).green(),QColor(glBufferImage.pixel(ax,ay)).blue(),QColor(glBufferImage.pixel(ax,ay)).alpha()); 277 // if (glBufferImage.pixel(ax,ay) == 255) { 278 // test.setPixel(ax,ay,1); 279 // } else { 280 // test.setPixel(ax,ay,0); 281 // } 282 } 283 // printf("\n"); 284 } 285 // for (int ay=0;ay<test.height();ay++) { 286 // for (int ax=0;ax<test.width();ax++) { 287 // if (test.pixel(ax,ay) == 1) { 288 // printf("."); 289 // } else if (!test.pixel(ax,ay)) { 290 // printf("X"); 291 // } else { 292 // printf("%d",test.pixel(ax,ay)); 293 // } 294 // } 295 // printf("\n"); 296 // } 297 298 // painter.drawImage(0, 0, glBufferImage); 299 // painter.drawImage(0, 0, test,0,0,-1,-1,Qt::ColorOnly); 300 301 printf("paint event zoom \n"); 302 // painter.drawRect(beginZoom.x(),beginZoom.y(),endZoom.x()-beginZoom.x(),endZoom.y()-beginZoom.y()); 303 painter.end(); 304 } else { 305 306 if (!readyToPaint) { 307 #ifdef GEANT4_QT_DEBUG 308 printf("G4OpenGLStoredQtViewer::paintGL ============ Not ready %d\n",readyToPaint); 309 #endif 310 readyToPaint= true; 266 311 return; 267 312 } 313 // DO NOT RESIZE IF SIZE HAS NOT CHANGE : 314 // WHEN CLICK ON THE FRAME FOR EXAMPLE 315 // EXECEPT WHEN MOUSE MOVE EVENT 316 if ( !hasToRepaint) { 317 if (((WinSize_x == (G4int)width())) &&(WinSize_y == (G4int) height())) { 318 #ifdef GEANT4_QT_DEBUG 319 printf("G4OpenGLStoredQtViewer::paintGL ============ Dont repaint\n"); 320 #endif 321 return; 322 } 323 } 324 nbPaint++; 325 #ifdef GEANT4_QT_DEBUG 326 printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV %d ready %d\n",nbPaint,readyToPaint); 327 #endif 328 WinSize_x = (G4int) width(); 329 WinSize_y = (G4int) height(); 330 331 setupViewport(width(),height()); 332 // glViewport (0, 0, width(), height()); 333 // glLoadIdentity(); 334 335 336 SetView(); 337 338 // // printf("before ClearView\n"); 339 #ifdef GEANT4_QT_DEBUG 340 printf(" ClearView\n"); 341 #endif 342 343 ClearView (); //ok, put the background correct 344 DrawView(); 345 346 hasToRepaint =false; 347 348 #ifdef GEANT4_QT_DEBUG 349 printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d ready %d\n",nbPaint,readyToPaint); 350 #endif 268 351 } 269 nbPaint++;270 #ifdef GEANT4_QT_DEBUG271 printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV %d ready %d\n",nbPaint,readyToPaint);272 #endif273 WinSize_x = (G4int) width();274 WinSize_y = (G4int) height();275 276 glViewport (0, 0, width(), height());277 // glLoadIdentity();278 279 280 SetView();281 282 // // printf("before ClearView\n");283 #ifdef GEANT4_QT_DEBUG284 printf(" ClearView\n");285 #endif286 287 ClearView (); //ok, put the background correct288 DrawView();289 290 hasToRepaint =false;291 292 #ifdef GEANT4_QT_DEBUG293 printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d ready %d\n",nbPaint,readyToPaint);294 #endif295 352 } 296 353 … … 300 357 printf("G4OpenGLStoredQtViewer::mousePressEvent\n"); 301 358 #endif 359 setMouseTracking(true); 302 360 G4MousePressEvent(event->pos()); 303 361 } 304 362 363 void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *event) 364 { 365 #ifdef GEANT4_QT_DEBUG 366 printf("G4OpenGLStoredQtViewer::mouseDoubleClickEvent\n"); 367 #endif 368 setMouseTracking(true); 369 zoomAction=true; 370 makeCurrent(); 371 glBufferImage = QImage( width(), height(), QImage::Format_ARGB32_Premultiplied ); 372 glReadPixels( 0, 0, width(), height(), GL_RGBA, GL_UNSIGNED_BYTE, glBufferImage.bits() ); 373 // glBufferImage = grabFrameBuffer(false).convertToFormat(QImage::Format_RGB16); //QImage::Format_ARGB32_Premultiplied 374 375 #ifdef GEANT4_QT_DEBUG 376 // for (int ay=0;ay<glBufferImage.height();ay++) { 377 // for (int ax=0;ax<glBufferImage.width();ax++) { 378 // if (glBufferImage.pixel(ax,ay) == 255) { 379 // printf("."); 380 // } else if (!glBufferImage.pixel(ax,ay)) { 381 // printf("X"); 382 // } else { 383 // printf("%d",glBufferImage.pixel(ax,ay)); 384 // } 385 // } 386 // printf("\n"); 387 // } 388 #endif 389 beginZoom.setX(event->x()); 390 beginZoom.setY(event->y()); 391 } 392 393 void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *event) 394 { 395 #ifdef GEANT4_QT_DEBUG 396 printf("G4OpenGLStoredQtViewer::mouseReleaseEvent\n"); 397 #endif 398 setMouseTracking(false); 399 zoomAction =false; 400 } 401 305 402 void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event) 306 403 { 404 // special case of mouse zoom action, it should draw a rect on 405 // the openGL buffer, so it could only be done in this class 406 // and sould be reimplemented in G4OpenGLImmediateQtViewer 407 if (!zoomAction) { 307 408 #if QT_VERSION < 0x040000 308 G4MouseMoveEvent(event->x(),event->y(),event->state());409 G4MouseMoveEvent(event->x(),event->y(),event->state()); 309 410 #else 310 G4MouseMoveEvent(event->x(),event->y(),event->buttons()); 311 #endif 411 G4MouseMoveEvent(event->x(),event->y(),event->buttons()); 412 #endif 413 } else { 414 #ifdef GEANT4_QT_DEBUG 415 printf("G4OpenGLStoredQtViewer::mouseMoveEvent zoom\n"); 416 #endif 417 endZoom.setX(event->x()); 418 endZoom.setY(event->y()); 419 updateGL(); 420 } 312 421 // DrawView(); 313 422 } … … 328 437 } 329 438 330 #endif 439 440 #endif
Note: See TracChangeset
for help on using the changeset viewer.