- Timestamp:
- Feb 13, 2008, 5:47:04 PM (17 years ago)
- Location:
- trunk/geant4/visualization
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/geant4/visualization/OpenGL/include/G4OpenGLQtViewer.hh
r723 r724 88 88 #endif 89 89 void G4keyPressEvent (QKeyEvent * event); 90 void rotateScene(G4double, G4double );91 void moveScene(G4double, G4double, G4double,bool );90 void rotateScene(G4double, G4double,bool mAutoRotate=false); 91 void moveScene(G4double, G4double, G4double,bool,bool mAutoMove=false); 92 92 93 93 … … 146 146 QAction *fDrawingLineSurfaceRemoval; 147 147 148 /** vector to store images in order to put them on disk after */ 149 std::vector <QImage> fVideoVector; 148 150 149 151 private slots : -
trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc
r723 r724 295 295 ,fDeltaDepth(0.01) 296 296 ,fDeltaZoom(0.1) 297 ,fDeltaMove(0. 2)297 ,fDeltaMove(0.05) 298 298 ,fHoldKeyEvent(false) 299 299 ,fAutoMove(false) … … 1280 1280 return; 1281 1281 } 1282 nomFich += "."+QString("ppm"); 1282 1283 1283 QImage image; 1284 1284 image = fWindow->grabFrameBuffer(); 1285 1285 bool res = false; 1286 1286 1287 #if QT_VERSION < 0x040000 1288 res = image.save(nomFich,"ppm"); 1289 #else 1290 res = image.save(nomFich,0); 1291 #endif 1292 if (res == false) { 1293 #if QT_VERSION < 0x040000 1294 G4cerr << "Error while saving file... "<<nomFich.ascii()<<"\n" << G4endl; 1295 #else 1296 G4cerr << "Error while saving file... "<<nomFich.toStdString().c_str()<<"\n" << G4endl; 1297 #endif 1298 fRecordFrames = false; 1287 if (fVideoVector.size() <30) { 1288 fVideoVector.push_back(image); 1289 G4cerr << "Store image " <<fVideoVector.size()<<"\n" << G4endl; 1290 return; 1291 } else { 1292 for (int a=0;a<30;a++) { 1293 G4cerr << "Saving image " <<a <<"\n"<< G4endl; 1294 printf("Saving image %d\n",a ); 1295 nomFich = QString("/temp/Test")+QString::number(fRecordFrameNumber); 1296 nomFich += "."+QString("ppm"); 1297 #if QT_VERSION < 0x040000 1298 res = fVideoVector[a].save(nomFich,"ppm"); 1299 #else 1300 res = fVideoVector[a].save(nomFich,0); 1301 #endif 1302 if (res == false) { 1303 #if QT_VERSION < 0x040000 1304 G4cerr << "Error while saving file... "<<nomFich.ascii()<<"\n" << G4endl; 1305 #else 1306 G4cerr << "Error while saving file... "<<nomFich.toStdString().c_str()<<"\n" << G4endl; 1307 #endif 1308 fRecordFrames = false; 1309 } 1310 fRecordFrameNumber++; 1311 } 1312 fVideoVector.clear(); 1313 fVideoVector.resize(0); 1299 1314 } 1300 1315 } … … 1491 1506 if (fMouseAction == STYLE1) { // rotate 1492 1507 if (mButtons & Qt::LeftButton) { 1493 if (fAutoMove) { 1494 while (fAutoMove) { 1495 rotateScene(fDeltaPosX,fDeltaPosY); 1496 ((QApplication*)G4Qt::getInstance ())->processEvents(); 1497 } 1498 } else { 1499 rotateScene(fDeltaPosX,fDeltaPosY); 1500 } 1508 rotateScene(fDeltaPosX,fDeltaPosY,fAutoMove); 1501 1509 } 1502 1510 } else if (fMouseAction == STYLE2) { // move … … 1504 1512 if (fAutoMove) { 1505 1513 while (fAutoMove) { 1506 moveScene(-fDeltaPosX,-fDeltaPosY,0,true );1514 moveScene(-fDeltaPosX,-fDeltaPosY,0,true,true); 1507 1515 ((QApplication*)G4Qt::getInstance ())->processEvents(); 1508 1516 } 1509 1517 } else { 1510 moveScene(-fDeltaPosX,-fDeltaPosY,0,true );1518 moveScene(-fDeltaPosX,-fDeltaPosY,0,true,false); 1511 1519 } 1512 1520 } … … 1530 1538 */ 1531 1539 1532 void G4OpenGLQtViewer::moveScene(G4double dx,G4double dy, G4double dz,bool mouseMove )1540 void G4OpenGLQtViewer::moveScene(G4double dx,G4double dy, G4double dz,bool mouseMove,bool mAutoMove) 1533 1541 { 1542 if( mAutoMove == false) { 1543 fAutoMove = true; 1544 } 1534 1545 G4double coefTrans = 0; 1535 1546 GLdouble coefDepth = 0; 1536 if(mouseMove) { 1537 coefTrans = ((G4double)getSceneNearWidth())/((G4double)WinSize_x); 1538 if (WinSize_y <WinSize_x) { 1539 coefTrans = ((G4double)getSceneNearWidth())/((G4double)WinSize_y); 1540 } 1541 } else { 1542 coefTrans = getSceneNearWidth()*fDeltaSceneTranslation; 1543 coefDepth = getSceneDepth()*fDeltaDepth; 1544 } 1545 fVP.IncrementPan(-dx*coefTrans,dy*coefTrans,dz*coefDepth); 1546 1547 updateQWidget(); 1547 while (fAutoMove) { 1548 if( mAutoMove == false) { 1549 fAutoMove = false; 1550 } 1551 if(mouseMove) { 1552 coefTrans = ((G4double)getSceneNearWidth())/((G4double)WinSize_x); 1553 if (WinSize_y <WinSize_x) { 1554 coefTrans = ((G4double)getSceneNearWidth())/((G4double)WinSize_y); 1555 } 1556 } else { 1557 coefTrans = getSceneNearWidth()*fDeltaSceneTranslation; 1558 coefDepth = getSceneDepth()*fDeltaDepth; 1559 } 1560 fVP.IncrementPan(-dx*coefTrans,dy*coefTrans,dz*coefDepth); 1561 1562 updateQWidget(); 1563 ((QApplication*)G4Qt::getInstance ())->processEvents(); 1564 } 1548 1565 } 1549 1566 … … 1554 1571 */ 1555 1572 1556 void G4OpenGLQtViewer::rotateScene(G4double dx, G4double dy )1573 void G4OpenGLQtViewer::rotateScene(G4double dx, G4double dy,bool mAutoRotate) 1557 1574 { 1575 if( mAutoRotate == false) { 1576 fAutoMove = true; 1577 } 1558 1578 dx = dx * fDeltaRotation; 1559 1579 dy = dy * fDeltaRotation; 1560 1561 //phi spin stuff here 1562 1563 G4Vector3D vp = fVP.GetViewpointDirection ().unit (); 1564 G4Vector3D up = fVP.GetUpVector ().unit (); 1565 1566 G4Vector3D yprime = (up.cross(vp)).unit(); 1567 G4Vector3D zprime = (vp.cross(yprime)).unit(); 1580 G4Vector3D vp; 1581 G4Vector3D up; 1582 1583 G4Vector3D xprime; 1584 G4Vector3D yprime; 1585 G4Vector3D zprime; 1568 1586 1569 1587 G4double delta_alpha; 1570 1588 G4double delta_theta; 1571 1589 1572 if (fVP.GetLightsMoveWithCamera()) { 1573 delta_alpha = dy; 1574 delta_theta = -dx; 1575 } else { 1576 delta_alpha = -dy; 1577 delta_theta = dx; 1578 } 1579 1580 delta_alpha *= deg; 1581 delta_theta *= deg; 1582 1583 G4Vector3D new_vp = std::cos(delta_alpha) * vp + std::sin(delta_alpha) * zprime; 1584 1590 G4Vector3D new_vp; 1585 1591 G4Vector3D new_up; 1586 if (fVP.GetLightsMoveWithCamera()) { 1587 new_up = (new_vp.cross(yprime)).unit(); 1588 fVP.SetUpVector(new_up); 1589 } else { 1590 new_up = up; 1591 } 1592 //////////////// 1593 // Rotates by fixed azimuthal angle delta_theta. 1594 1595 G4double cosalpha = new_up.dot (new_vp.unit()); 1596 G4double sinalpha = std::sqrt (1. - std::pow (cosalpha, 2)); 1597 yprime = (new_up.cross (new_vp.unit())).unit (); 1598 G4Vector3D xprime = yprime.cross (new_up); 1599 // Projection of vp on plane perpendicular to up... 1600 G4Vector3D a1 = sinalpha * xprime; 1601 // Required new projection... 1602 G4Vector3D a2 = 1603 sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime); 1604 // Required Increment vector... 1605 G4Vector3D delta = a2 - a1; 1606 // So new viewpoint is... 1607 G4Vector3D viewPoint = new_vp.unit() + delta; 1608 1609 fVP.SetViewAndLights (viewPoint); 1610 updateQWidget(); 1611 1592 1593 G4double cosalpha; 1594 G4double sinalpha; 1595 1596 G4Vector3D a1; 1597 G4Vector3D a2; 1598 G4Vector3D delta; 1599 G4Vector3D viewPoint; 1600 1601 while (fAutoMove) { 1602 if( mAutoRotate == false) { 1603 fAutoMove = false; 1604 } 1605 1606 //phi spin stuff here 1607 1608 vp = fVP.GetViewpointDirection ().unit (); 1609 up = fVP.GetUpVector ().unit (); 1610 1611 yprime = (up.cross(vp)).unit(); 1612 zprime = (vp.cross(yprime)).unit(); 1613 1614 if (fVP.GetLightsMoveWithCamera()) { 1615 delta_alpha = dy; 1616 delta_theta = -dx; 1617 } else { 1618 delta_alpha = -dy; 1619 delta_theta = dx; 1620 } 1621 1622 delta_alpha *= deg; 1623 delta_theta *= deg; 1624 1625 new_vp = std::cos(delta_alpha) * vp + std::sin(delta_alpha) * zprime; 1626 1627 if (fVP.GetLightsMoveWithCamera()) { 1628 new_up = (new_vp.cross(yprime)).unit(); 1629 fVP.SetUpVector(new_up); 1630 } else { 1631 new_up = up; 1632 } 1633 //////////////// 1634 // Rotates by fixed azimuthal angle delta_theta. 1635 1636 cosalpha = new_up.dot (new_vp.unit()); 1637 sinalpha = std::sqrt (1. - std::pow (cosalpha, 2)); 1638 yprime = (new_up.cross (new_vp.unit())).unit (); 1639 xprime = yprime.cross (new_up); 1640 // Projection of vp on plane perpendicular to up... 1641 a1 = sinalpha * xprime; 1642 // Required new projection... 1643 a2 = sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime); 1644 // Required Increment vector... 1645 delta = a2 - a1; 1646 // So new viewpoint is... 1647 viewPoint = new_vp.unit() + delta; 1648 1649 fVP.SetViewAndLights (viewPoint); 1650 updateQWidget(); 1651 1652 ((QApplication*)G4Qt::getInstance ())->processEvents(); 1653 } 1612 1654 } 1613 1655 … … 1993 2035 if ((event->key() == Qt::Key_Return) || (event->key() == Qt::Key_Enter)){ // end of video 1994 2036 fRecordFrames = false; 2037 G4cout << "Recording Stop... \n" << G4endl; 2038 G4cout << "Saving /temp/output.mpg \n" << G4endl; 1995 2039 saveVideo("/temp/output.mpg"); 1996 2040 } 1997 2041 if (event->key() == Qt::Key_Space){ // start/pause of video 1998 2042 fRecordFrames = !fRecordFrames; 2043 if (fRecordFrames) { 2044 G4cout << "Recording Start... \n" << G4endl; 2045 } else { 2046 G4cout << "Recording Pause... \n" << G4endl; 2047 } 1999 2048 } 2000 2049 -
trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc
r723 r724 199 199 } 200 200 201 if (fRecordFrames) { 202 saveForVideo(QString("/temp/Test")+QString::number(fRecordFrameNumber)); 203 // fRecordFrameNumber++; 204 #ifdef GEANT4_QT_DEBUG 205 printf("G4OpenGLStoredQtViewer::record frame %d\n",fRecordFrameNumber); 206 #endif 207 } 208 201 209 #ifdef GEANT4_QT_DEBUG 202 210 printf("G4OpenGLStoredQtViewer::DrawView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",WinSize_x, WinSize_y); … … 292 300 DrawView(); 293 301 294 if (fRecordFrames) {295 saveForVideo(QString("/temp/Test")+QString::number(fRecordFrameNumber));296 fRecordFrameNumber++;297 #ifdef GEANT4_QT_DEBUG298 printf("G4OpenGLStoredQtViewer::record frame %d\n",fRecordFrameNumber);299 #endif300 }301 302 hasToRepaint =false; 302 303 -
trunk/geant4/visualization/visTutor/exN03Vis12.mac
r609 r724 19 19 /vis/verbose confirmations 20 20 21 /vis/open OGLS X21 /vis/open OGLSQT 22 22 /vis/drawVolume 23 23 /vis/scene/add/eventID … … 65 65 /vis/filtering/trajectories/particleFilter-0/invert true 66 66 67 /gun/energy 1 GeV67 /gun/energy 10 GeV 68 68 /run/beamOn 69 69 /control/alias timeRange 0.1 -
trunk/geant4/visualization/visTutor/exN03Vis13.mac
r562 r724 19 19 /vis/verbose confirmations 20 20 21 /vis/open OGLS X600x600-0+021 /vis/open OGLSQT 600x600-0+0 22 22 /vis/drawVolume 23 23 /vis/scene/add/eventID -
trunk/geant4/visualization/visTutor/gui.mac
r707 r724 42 42 /gui/addButton vis Vis10(OIWin32) "/control/execute visTutor/exN03Vis10.mac" 43 43 /gui/addButton vis Vis11(OGLSXm) "/control/execute visTutor/exN03Vis11.mac" 44 /gui/addButton vis Vis12(OGLSQT) "/control/execute visTutor/exN03Vis12.mac" 45 /gui/addButton vis Vis13(OGLSQT) "/control/execute visTutor/exN03Vis13.mac" 44 46 # 45 47 # Viewer menu :
Note: See TracChangeset
for help on using the changeset viewer.