Changeset 723


Ignore:
Timestamp:
Feb 12, 2008, 6:05:28 PM (16 years ago)
Author:
garnier
Message:

debud de la video

Location:
trunk/geant4/visualization/OpenGL
Files:
3 edited

Legend:

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

    r721 r723  
    9898  QDialog* GLWindow;
    9999  bool hasPendingEvents();
     100  void saveForVideo(QString);
     101  bool saveVideo(QString);
     102  bool fRecordFrames;
     103  int fRecordFrameNumber;
    100104
    101105private:
     
    142146  QAction *fDrawingLineSurfaceRemoval;
    143147
     148
    144149private slots :
    145150  void actionMouseRotate();
  • trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc

    r722 r723  
    5555#include <qlayout.h>
    5656#include <qdialog.h>
     57#include <qprocess.h>
    5758
    5859#if QT_VERSION >= 0x040000
     
    286287  ,G4OpenGLViewer (scene)
    287288  ,fWindow(0)
     289  ,fRecordFrames(false)
     290  ,fRecordFrameNumber(0)
    288291  ,fContextMenu(0)
    289292  ,fMouseAction(STYLE1)
     
    981984    G4cout << "Press SHIFT+up/down arrows to rotate volume up/down\n" << G4endl;
    982985    G4cout << "Press ALT+/- to slow/speed auto rotation/move\n" << G4endl;
     986    G4cout << "In video mode : \n" << G4endl;
     987    G4cout << "  Press SPACE to Start/Pause video recording \n" << G4endl;
     988    G4cout << "  Press RETURN to Stop video recording \n" << G4endl;
    983989  } else  if (fMouseAction == STYLE2) { //move
    984990    G4cout << "Move camera point of view with mouse\n" << G4endl;
     
    990996    G4cout << "Press +/- to zoom into volume\n" << G4endl;
    991997    G4cout << "Press ALT+/- to slow/speed auto rotation/move\n" << G4endl;
     998    G4cout << "In video mode : \n" << G4endl;
     999    G4cout << "  Press SPACE to Start/Pause video recording \n" << G4endl;
     1000    G4cout << "  Press RETURN to Stop video recording \n" << G4endl;
    9921001  } else  if (fMouseAction == STYLE3) { //pick
    9931002    G4cout << "Click and pick \n" << G4endl;
     
    12651274  }
    12661275}
     1276
     1277
     1278void G4OpenGLQtViewer::saveForVideo(QString nomFich) {
     1279  if (nomFich == "") {
     1280    return;
     1281  }
     1282  nomFich += "."+QString("ppm");
     1283  QImage image;
     1284  image = fWindow->grabFrameBuffer();
     1285  bool res = false;
     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;
     1299  }
     1300}
     1301
     1302
    12671303
    12681304void G4OpenGLQtViewer::actionCreateEPS() {
     
    14791515#ifdef GEANT4_QT_DEBUG
    14801516  if (mButtons & Qt::LeftButton) {
    1481     printf("                  end of  mouse move event %d %d delta:%d %d\n",pos_x,pos_y,fDeltaPosX,fDeltaPosY);
    1482   } else {
    1483     printf("                  end of  mouse move event %d %d delta:%d %d --------------NO BUTTON\n",pos_x,pos_y,fDeltaPosX,fDeltaPosY);
     1517    printf("                  end of  mouse move event %d %d delta:%f %f\n",pos_x,pos_y,fDeltaPosX,fDeltaPosY);
     1518  } else {
     1519    printf("                  end of  mouse move event %d %d delta:%f %f --------------NO BUTTON\n",pos_x,pos_y,fDeltaPosX,fDeltaPosY);
    14841520  }
    14851521#endif
     
    19551991  }
    19561992
     1993  if ((event->key() == Qt::Key_Return) || (event->key() == Qt::Key_Enter)){ // end of video
     1994    fRecordFrames = false;
     1995    saveVideo("/temp/output.mpg");
     1996  }
     1997  if (event->key() == Qt::Key_Space){ // start/pause of video
     1998    fRecordFrames = !fRecordFrames;
     1999  }
     2000
    19572001  // with no modifiers
    19582002#if QT_VERSION < 0x040000
     
    19822026}
    19832027
     2028bool G4OpenGLQtViewer::saveVideo (QString outputName) {
     2029
     2030  // save the parameter file
     2031  FILE* fp;
     2032  fp = fopen ("/temp/parameter_file.par", "w");
     2033
     2034  if (fp == NULL) {
     2035    return false;
     2036  }
     2037
     2038  fprintf (fp,"# parameter file template with lots of comments to assist you\n");
     2039  fprintf (fp,"#\n");
     2040  fprintf (fp,"# you can use this as a template, copying it to a separate file then modifying\n");
     2041  fprintf (fp,"# the copy\n");
     2042  fprintf (fp,"#\n");
     2043  fprintf (fp,"#\n");
     2044  fprintf (fp,"# any line beginning with '#' is a comment\n");
     2045  fprintf (fp,"#\n");
     2046  fprintf (fp,"# no line should be longer than 255 characters\n");
     2047  fprintf (fp,"#\n");
     2048  fprintf (fp,"#\n");
     2049  fprintf (fp,"# general format of each line is:\n");
     2050  fprintf (fp,"#          \n");
     2051  fprintf (fp,"#\n");
     2052  fprintf (fp,"# lines can generally be in any order\n");
     2053  fprintf (fp,"#\n");
     2054  fprintf (fp,"# an exception is the option 'INPUT' which must be followed by input\n");
     2055  fprintf (fp,"# files in the order in which they must appear, followed by 'END_INPUT'\n");
     2056  fprintf (fp,"#\n");
     2057  fprintf (fp,"# Also, if you use the `command` method of generating input file names,\n");
     2058  fprintf (fp,"# the command will only be executed in the INPUT_DIR if INPUT_DIR preceeds\n");
     2059  fprintf (fp,"# the INPUT parameter.\n");
     2060  fprintf (fp,"#\n");
     2061  fprintf (fp,"#  MUST be in UPPER CASE\n");
     2062  fprintf (fp,"#\n");
     2063  fprintf (fp,"\n");
     2064  fprintf (fp,"# Pattern affects speed, quality and compression. See the User's Guide\n");
     2065  fprintf (fp,"# for more info.\n");
     2066  fprintf (fp,"\n");
     2067  fprintf (fp,"PATTERN          IBBPBBPBBPBBPBBP\n");
     2068#if QT_VERSION < 0x040000
     2069  fprintf (fp,"OUTPUT           %s\n",outputName.ascii());
     2070#else
     2071  fprintf (fp,"OUTPUT           %s\n",outputName.toStdString().c_str());
     2072#endif
     2073  fprintf (fp,"\n");
     2074  fprintf (fp,"# mpeg_encode really only accepts 3 different file formats, but using a\n");
     2075  fprintf (fp,"# conversion statement it can effectively handle ANY file format\n");
     2076  fprintf (fp,"#\n");
     2077  fprintf (fp,"# You must specify the type of the input files.  The choices are:\n");
     2078  fprintf (fp,"#    YUV, PPM, JMOVIE, Y, JPEG, PNM\n");
     2079  fprintf (fp,"#        (must be upper case)\n");
     2080  fprintf (fp,"#\n");
     2081  fprintf (fp,"BASE_FILE_FORMAT PPM\n");
     2082  fprintf (fp,"\n");
     2083  fprintf (fp,"#\n");
     2084  fprintf (fp,"# if YUV format (or using parallel version), must provide width and height\n");
     2085  fprintf (fp,"# YUV_SIZE       widthxheight\n");
     2086  fprintf (fp,"# this option is ignored if BASE_FILE_FORMAT is not YUV and you're running\n");
     2087  fprintf (fp,"# on just one machine\n");
     2088  fprintf (fp,"#\n");
     2089  fprintf (fp,"YUV_SIZE 352x240\n");
     2090  fprintf (fp,"\n");
     2091  fprintf (fp,"# If you are using YUV, there are different supported file formats.\n");
     2092  fprintf (fp,"# EYUV or UCB are the same as previous versions of this encoder.\n");
     2093  fprintf (fp,"# (All the Y's, then U's then V's, in 4:2:0 subsampling.)\n");
     2094  fprintf (fp,"# Other formats, such as Abekas, Phillips, or a general format are\n");
     2095  fprintf (fp,"# permissible, the general format is a string of Y's, U's, and V's\n");
     2096  fprintf (fp,"# to specify the file order.\n");
     2097  fprintf (fp,"\n");
     2098  fprintf (fp,"INPUT_FORMAT UCB\n");
     2099  fprintf (fp,"\n");
     2100  fprintf (fp,"# the conversion statement\n");
     2101  fprintf (fp,"#\n");
     2102  fprintf (fp,"# Each occurrence of '*' will be replaced by the input file\n");
     2103  fprintf (fp,"#\n");
     2104  fprintf (fp,"# e.g., if you have a bunch of GIF files, then this might be:\n");
     2105  fprintf (fp,"#        INPUT_CONVERT   giftoppm *\n");
     2106  fprintf (fp,"#\n");
     2107  fprintf (fp,"# e.g., if you have a bunch of files like a.Y a.U a.V, etc., then:\n");
     2108  fprintf (fp,"#        INPUT_CONVERT   cat *.Y *.U *.V\n");
     2109  fprintf (fp,"#\n");
     2110  fprintf (fp,"# e.g., if you are grabbing from laser disc you might have something like\n");
     2111  fprintf (fp,"#        INPUT_CONVERT   goto frame *; grabppm\n");
     2112  fprintf (fp,"# 'INPUT_CONVERT *' means the files are already in the base file format\n");
     2113  fprintf (fp,"#\n");
     2114  fprintf (fp,"INPUT_CONVERT    * \n");
     2115  fprintf (fp,"\n");
     2116  fprintf (fp,"# number of frames in a GOP.\n");
     2117  fprintf (fp,"#\n");
     2118  fprintf (fp,"# since each GOP must have at least one I-frame, the encoder will find the\n");
     2119  fprintf (fp,"# the first I-frame after GOP_SIZE frames to start the next GOP\n");
     2120  fprintf (fp,"#\n");
     2121  fprintf (fp,"# later, will add more flexible GOP signalling\n");
     2122  fprintf (fp,"#\n");
     2123  fprintf (fp,"GOP_SIZE 16\n");
     2124  fprintf (fp,"\n");
     2125  fprintf (fp,"# number of slices in a frame\n");
     2126  fprintf (fp,"#\n");
     2127  fprintf (fp,"# 1 is a good number.  another possibility is the number of macroblock rows\n");
     2128  fprintf (fp,"# (which is the height divided by 16)\n");
     2129  fprintf (fp,"#\n");
     2130  fprintf (fp,"SLICES_PER_FRAME 1\n");
     2131  fprintf (fp,"\n");
     2132  fprintf (fp,"# directory to get all input files from (makes this file easier to read)\n");
     2133  fprintf (fp,"INPUT_DIR        /temp\n");
     2134  fprintf (fp,"\n");
     2135  fprintf (fp,"# There are a bunch of ways to specify the input files.\n");
     2136  fprintf (fp,"# from a simple one-per-line listing, to the following \n");
     2137  fprintf (fp,"# way of numbering them.  See the manual for more information.\n");
     2138  fprintf (fp,"INPUT\n");
     2139  fprintf (fp,"# '*' is replaced by the numbers 01, 02, 03, 04\n");
     2140  fprintf (fp,"# if I instead do [01-11], it would be 01, 02, ..., 09, 10, 11\n");
     2141  fprintf (fp,"# if I instead do [1-11], it would be 1, 2, 3, ..., 9, 10, 11\n");
     2142  fprintf (fp,"# if I instead do [1-11+3], it would be 1, 4, 7, 10\n");
     2143  fprintf (fp,"# the program assumes none of your input files has a name ending in ']'\n");
     2144  fprintf (fp,"# if you do, too bad!!!\n");
     2145  fprintf (fp,"#\n");
     2146  fprintf (fp,"#\n");
     2147  fprintf (fp,"Test*.ppm        [0-%d]\n",fRecordFrameNumber);
     2148  fprintf (fp,"# can have more files here if you want...there is no limit on the number\n");
     2149  fprintf (fp,"# of files\n");
     2150  fprintf (fp,"END_INPUT\n");
     2151  fprintf (fp,"\n");
     2152  fprintf (fp,"\n");
     2153  fprintf (fp,"\n");
     2154  fprintf (fp,"# Many of the remaining options have to do with the motion search and qscale\n");
     2155  fprintf (fp,"\n");
     2156  fprintf (fp,"# FULL or HALF -- must be upper case\n");
     2157  fprintf (fp,"# Should be FULL for computer generated images\n");
     2158  fprintf (fp,"PIXEL            FULL\n");
     2159  fprintf (fp,"\n");
     2160  fprintf (fp,"# means +/- this many pixels for both P and B frame searches\n");
     2161  fprintf (fp,"# specify two numbers if you wish to serc different ranges in the two.\n");
     2162  fprintf (fp,"RANGE            10\n");
     2163  fprintf (fp,"\n");
     2164  fprintf (fp,"# The two search algorithm parameters below mostly affect speed,\n");
     2165  fprintf (fp,"# with some affect on compression and almost none on quality.\n");
     2166  fprintf (fp,"\n");
     2167  fprintf (fp,"# this must be one of {EXHAUSTIVE, SUBSAMPLE, LOGARITHMIC}\n");
     2168  fprintf (fp,"PSEARCH_ALG      LOGARITHMIC\n");
     2169  fprintf (fp,"\n");
     2170  fprintf (fp,"# this must be one of {SIMPLE, CROSS2, EXHAUSTIVE}\n");
     2171  fprintf (fp,"#\n");
     2172  fprintf (fp,"# note that EXHAUSTIVE is really, really, really slow\n");
     2173  fprintf (fp,"#\n");
     2174  fprintf (fp,"BSEARCH_ALG      SIMPLE\n");
     2175  fprintf (fp,"\n");
     2176  fprintf (fp,"#\n");
     2177  fprintf (fp,"# these specify the q-scale for I, P, and B frames\n");
     2178  fprintf (fp,"# (values must be between 1 and 31)\n");
     2179  fprintf (fp,"# These are the Qscale values for the entire frame in variable bit-rate\n");
     2180  fprintf (fp,"# mode, and starting points (but not important) for constant bit rate\n");
     2181  fprintf (fp,"#\n");
     2182  fprintf (fp,"\n");
     2183  fprintf (fp,"# Qscale (Quantization scale) affects quality and compression,\n");
     2184  fprintf (fp,"# but has very little effect on speed.\n");
     2185  fprintf (fp,"\n");
     2186  fprintf (fp,"IQSCALE          4\n");
     2187  fprintf (fp,"PQSCALE          5\n");
     2188  fprintf (fp,"BQSCALE          12\n");
     2189  fprintf (fp,"\n");
     2190  fprintf (fp,"# this must be ORIGINAL or DECODED\n");
     2191  fprintf (fp,"REFERENCE_FRAME  ORIGINAL\n");
     2192  fprintf (fp,"\n");
     2193  fprintf (fp,"# for parallel parameters see parallel.param in the exmaples subdirectory\n");
     2194  fprintf (fp,"\n");
     2195  fprintf (fp,"# if you want constant bit-rate mode, specify it as follows (number is bits/sec):\n");
     2196  fprintf (fp,"#BIT_RATE  1000000\n");
     2197  fprintf (fp,"\n");
     2198  fprintf (fp,"# To specify the buffer size (327680 is default, measused in bits, for 16bit words)\n");
     2199  fprintf (fp,"BUFFER_SIZE 327680\n");
     2200  fprintf (fp,"\n");
     2201  fprintf (fp,"# The frame rate is the number of frames/second (legal values:\n");
     2202  fprintf (fp,"# 23.976, 24, 25, 29.97, 30, 50 ,59.94, 60\n");
     2203  fprintf (fp,"FRAME_RATE 30\n");
     2204  fprintf (fp,"\n");
     2205  fprintf (fp,"# There are many more options, see the users manual for examples....\n");
     2206  fprintf (fp,"# ASPECT_RATIO, USER_DATA, GAMMA, IQTABLE, etc.\n");
     2207  fprintf (fp,"\n");
     2208  fprintf (fp,"\n");
     2209  fclose (fp);
     2210
     2211  QProcess::execute ("/sw/bin/mpeg_encode", QStringList("/temp/parameter_file.par"));
     2212  return true;
     2213}
    19842214
    19852215/*
  • trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc

    r720 r723  
    252252void G4OpenGLStoredQtViewer::paintGL()
    253253{
    254      
    255254  if (!readyToPaint) {
    256255#ifdef GEANT4_QT_DEBUG
     
    293292  DrawView();
    294293     
     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  }
    295301  hasToRepaint =false;
    296302     
Note: See TracChangeset for help on using the changeset viewer.