Changeset 724


Ignore:
Timestamp:
Feb 13, 2008, 5:47:04 PM (16 years ago)
Author:
garnier
Message:

video avec de vector:en test

Location:
trunk/geant4/visualization
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/geant4/visualization/OpenGL/include/G4OpenGLQtViewer.hh

    r723 r724  
    8888#endif
    8989  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);
    9292
    9393
     
    146146  QAction *fDrawingLineSurfaceRemoval;
    147147
     148  /** vector to store images in order to put them on disk after */
     149  std::vector <QImage> fVideoVector; 
    148150
    149151private slots :
  • trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc

    r723 r724  
    295295  ,fDeltaDepth(0.01)
    296296  ,fDeltaZoom(0.1)
    297   ,fDeltaMove(0.2)
     297  ,fDeltaMove(0.05)
    298298  ,fHoldKeyEvent(false)
    299299  ,fAutoMove(false)
     
    12801280    return;
    12811281  }
    1282   nomFich += "."+QString("ppm");
     1282
    12831283  QImage image;
    12841284  image = fWindow->grabFrameBuffer();
    12851285  bool res = false;
    12861286 
    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);
    12991314  }
    13001315}
     
    14911506  if (fMouseAction == STYLE1) {  // rotate
    14921507    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);
    15011509    }
    15021510  } else if (fMouseAction == STYLE2) {  // move
     
    15041512      if (fAutoMove) {
    15051513        while (fAutoMove) {
    1506           moveScene(-fDeltaPosX,-fDeltaPosY,0,true);
     1514          moveScene(-fDeltaPosX,-fDeltaPosY,0,true,true);
    15071515          ((QApplication*)G4Qt::getInstance ())->processEvents();
    15081516        }
    15091517      } else {
    1510         moveScene(-fDeltaPosX,-fDeltaPosY,0,true);
     1518        moveScene(-fDeltaPosX,-fDeltaPosY,0,true,false);
    15111519      }
    15121520    }
     
    15301538*/
    15311539
    1532 void G4OpenGLQtViewer::moveScene(G4double dx,G4double dy, G4double dz,bool mouseMove)
     1540void G4OpenGLQtViewer::moveScene(G4double dx,G4double dy, G4double dz,bool mouseMove,bool mAutoMove)
    15331541{
     1542  if( mAutoMove == false) {
     1543    fAutoMove = true;
     1544  }
    15341545  G4double coefTrans = 0;
    15351546  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  }
    15481565}
    15491566
     
    15541571*/
    15551572
    1556 void G4OpenGLQtViewer::rotateScene(G4double dx, G4double dy)
     1573void G4OpenGLQtViewer::rotateScene(G4double dx, G4double dy,bool mAutoRotate)
    15571574{
     1575  if( mAutoRotate == false) {
     1576    fAutoMove = true;
     1577  }
    15581578  dx = dx * fDeltaRotation;
    15591579  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;
    15681586 
    15691587  G4double delta_alpha;
    15701588  G4double delta_theta;
    15711589 
    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;
    15851591  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  }
    16121654}
    16131655
     
    19932035  if ((event->key() == Qt::Key_Return) || (event->key() == Qt::Key_Enter)){ // end of video
    19942036    fRecordFrames = false;
     2037    G4cout << "Recording Stop... \n" << G4endl;
     2038    G4cout << "Saving /temp/output.mpg \n" << G4endl;
    19952039    saveVideo("/temp/output.mpg");
    19962040  }
    19972041  if (event->key() == Qt::Key_Space){ // start/pause of video
    19982042    fRecordFrames = !fRecordFrames;
     2043    if (fRecordFrames) {
     2044      G4cout << "Recording Start... \n" << G4endl;
     2045    } else {
     2046      G4cout << "Recording Pause... \n" << G4endl;
     2047    }
    19992048  }
    20002049
  • trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc

    r723 r724  
    199199  }
    200200
     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
    201209#ifdef GEANT4_QT_DEBUG
    202210  printf("G4OpenGLStoredQtViewer::DrawView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",WinSize_x, WinSize_y);
     
    292300  DrawView();
    293301     
    294   if (fRecordFrames) {
    295     saveForVideo(QString("/temp/Test")+QString::number(fRecordFrameNumber));
    296     fRecordFrameNumber++;
    297 #ifdef GEANT4_QT_DEBUG
    298     printf("G4OpenGLStoredQtViewer::record frame %d\n",fRecordFrameNumber);
    299 #endif
    300   }
    301302  hasToRepaint =false;
    302303     
  • trunk/geant4/visualization/visTutor/exN03Vis12.mac

    r609 r724  
    1919/vis/verbose confirmations
    2020
    21 /vis/open OGLSX
     21/vis/open OGLSQT
    2222/vis/drawVolume
    2323/vis/scene/add/eventID
     
    6565/vis/filtering/trajectories/particleFilter-0/invert true
    6666
    67 /gun/energy 1 GeV
     67/gun/energy 10 GeV
    6868/run/beamOn
    6969/control/alias timeRange 0.1
  • trunk/geant4/visualization/visTutor/exN03Vis13.mac

    r562 r724  
    1919/vis/verbose confirmations
    2020
    21 /vis/open OGLSX 600x600-0+0
     21/vis/open OGLSQT 600x600-0+0
    2222/vis/drawVolume
    2323/vis/scene/add/eventID
  • trunk/geant4/visualization/visTutor/gui.mac

    r707 r724  
    4242/gui/addButton vis Vis10(OIWin32) "/control/execute visTutor/exN03Vis10.mac"
    4343/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"
    4446#
    4547# Viewer menu :
Note: See TracChangeset for help on using the changeset viewer.