Changeset 945 for trunk


Ignore:
Timestamp:
Mar 16, 2009, 6:36:09 PM (15 years ago)
Author:
garnier
Message:

en test

Location:
trunk/source/visualization
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/visualization/History

    r944 r945  
    3131    constructor so that a user may set verbosity before initialisation.
    3232  o G4VisExecutive.icc: made methods inline.
     33
     345th March 2009, Laurent Garnier
     35 - Now using Gl2PS method to do PS
     36 - Add flag in GNUMakefile to compile in debug mode
     37 - Remplacing glBitmap by GL_POINTS to draw marker : Speed improvment
     38  and gl2ps can now draw Markers.
    3339
    344025th February 2009  John Allison
  • trunk/source/visualization/OpenGL/History

    r942 r945  
    2020History file for visualization/OpenGL
    2121-------------------------------------
     22
     2316th March 2009, Laurent Garnier
     24 - G4OpenGLViewer : Add a check on max viewport dimensions when setting size.
    2225
    23264rd March 2009, Laurent Garnier
  • trunk/source/visualization/OpenGL/include/G4OpenGLXViewer.hh

    r915 r945  
    8080  Colormap                          cmap;
    8181  XSetWindowAttributes              swa;
    82   GLXDrawable                       win;
     82  GLXDrawable                       fGLXWin;
    8383  GLXContext                        cx;
    8484  XEvent                            event;
     
    9898  char                              charViewName [100];
    9999
     100  GLubyte* grabPixelsX (int inColor, unsigned int width, unsigned int height);
     101  int generateEPSX (const char* filnam,int inColour, unsigned int width,unsigned int height);
     102
     103
    100104private:
    101105  G4OpenGLXViewer (const G4OpenGLXViewer&);
  • trunk/source/visualization/OpenGL/src/G4OpenGLImmediateXViewer.cc

    r915 r945  
    8686
    8787  //Make sure current viewer is attached and clean...
    88   glXMakeCurrent (dpy, win, cx);
     88  glXMakeCurrent (dpy, fGLXWin, cx);
    8989
    9090  if(style!=G4ViewParameters::hlr &&
  • trunk/source/visualization/OpenGL/src/G4OpenGLImmediateXmViewer.cc

    r915 r945  
    9292
    9393  //Make sure current viewer is attached and clean...
    94   glXMakeCurrent (dpy, win, cx);
     94  glXMakeCurrent (dpy, fGLXWin, cx);
    9595
    9696  if(style!=G4ViewParameters::hlr &&
  • trunk/source/visualization/OpenGL/src/G4OpenGLQtViewer.cc

    r941 r945  
    3232//                     functionality for OpenGL in GEANT4
    3333//
    34 // 27/06/2003 : G.Barrand : implementation (at last !).
    3534
    3635#ifdef G4VIS_BUILD_OPENGLQT_DRIVER
  • trunk/source/visualization/OpenGL/src/G4OpenGLStoredSceneHandler.cc

    r942 r945  
    222222  if (fLastPolymarkers.size() > 0 ) {
    223223
    224     // Loop new poly to check
     224    // Loop new point to check
    225225    for (unsigned int b=0; b< polymarker.size();b++) {
    226       printf("check %d/%d\n",b,polymarker.size());
     226      //      printf("check %d/%d\n",b,polymarker.size());
    227227      res= false;
     228
     229      // Look for stored point list
    228230      for (unsigned int a=0; a< fLastPolymarkers.size() ;a++) {
    229         printf("against vect %d/%d\n",a,fLastPolymarker.size());
     231        //        printf("against vect %d/%d\n",a,fLastPolymarker.size());
    230232        std::vector < G4Polymarker > storedPoly = fLastPolymarkers[a];
    231233        int size= storedPoly.size()-1;
    232         for (unsigned int aPoly=0; aPoly< storedPoly[a].size() ;aPoly++) {
    233           printf("against poly %d/%d\n",aPoly,storedPoly.size());
     234
     235        // Look for point
     236        for (int aPoly=0; aPoly< size ;aPoly++) {
     237          //          printf("against poly %d/%d\n",aPoly,storedPoly.size());
    234238          if (( storedPoly[size-aPoly].GetPosition().x() == polymarker[b].x()) &&
    235239              ( storedPoly[size-aPoly].GetPosition().y() == polymarker[b].y()) &&
     
    238242            res= true;
    239243            nbDoublons++;
    240             printf("G4OpenGLStoredSceneHandler::AddPrimitive  PT %d/%d ALREADY FOUND TOT:%d. OLD pos %d/%d in %d PolyMarkerList STILL %d Marker in list. Point is %f %f %f\n",b,polymarker.size(),  nbDoublons,  aPoly,storedPoly[a].size(),a   ,reste,polymarker[b].x(),polymarker[b].y(),polymarker[b].z());
     244            //            printf("G4OpenGLStoredSceneHandler::AddPrimitive  PT %d/%d ALREADY FOUND TOT:%d. OLD pos %d/%d in %d PolyMarkerList STILL %d Marker in list. Point is %f %f %f\n",b,polymarker.size(),  nbDoublons,  aPoly,size,a   ,reste,polymarker[b].x(),polymarker[b].y(),polymarker[b].z());
    241245          }
    242246        }
  • trunk/source/visualization/OpenGL/src/G4OpenGLStoredViewer.cc

    r911 r945  
    125125
    126126void G4OpenGLStoredViewer::DrawDisplayLists () {
     127#ifdef G4DEBUG_VIS_OGL
     128      printf("G4OpenGLStoredViewer::DrawDisplayLists \n");
     129#endif
    127130
    128131  const G4Planes& cutaways = fVP.GetCutawayPlanes();
     
    131134  size_t nPasses = cutawayUnion? cutaways.size(): 1;
    132135  for (size_t i = 0; i < nPasses; ++i) {
     136#ifdef G4DEBUG_VIS_OGL
     137    printf("G4OpenGLStoredViewer::DrawDisplayLists cutaway %d/%d\n",i,nPasses);
     138#endif
    133139
    134140    if (cutawayUnion) {
     
    146152
    147153    for (size_t i = 0; i < fG4OpenGLStoredSceneHandler.fTOList.size(); ++i) {
     154#ifdef G4DEBUG_VIS_OGL
     155      printf("+");
     156#endif
    148157      G4OpenGLStoredSceneHandler::TO& to =
    149158        fG4OpenGLStoredSceneHandler.fTOList[i];
  • trunk/source/visualization/OpenGL/src/G4OpenGLStoredXViewer.cc

    r911 r945  
    7878
    7979  //Make sure current viewer is attached and clean...
    80   glXMakeCurrent (dpy, win, cx);
     80  glXMakeCurrent (dpy, fGLXWin, cx);
    8181
    8282  G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
     
    127127  GLint renderMode;
    128128  glGetIntegerv(GL_RENDER_MODE, &renderMode);
    129   if (renderMode == GL_RENDER) glXSwapBuffers (dpy, win); 
     129  if (renderMode == GL_RENDER) glXSwapBuffers (dpy, fGLXWin); 
    130130}
    131131
  • trunk/source/visualization/OpenGL/src/G4OpenGLStoredXmViewer.cc

    r940 r945  
    8787
    8888  //Make sure current viewer is attached and clean...
    89   glXMakeCurrent (dpy, win, cx);
     89  glXMakeCurrent (dpy, fGLXWin, cx);
    9090
    9191  G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
     
    141141  GLint renderMode;
    142142  glGetIntegerv(GL_RENDER_MODE, &renderMode);
    143   if (renderMode == GL_RENDER) glXSwapBuffers (dpy, win); 
     143  if (renderMode == GL_RENDER) glXSwapBuffers (dpy, fGLXWin); 
    144144}
    145145
  • trunk/source/visualization/OpenGL/src/G4OpenGLViewer.cc

    r942 r945  
    131131/**
    132132 * Set the viewport of the scene
     133 * MAXIMUM SIZE is :
     134 * GLint dims[2];
     135 * glGetIntegerv(GL_MAX_VIEWPORT_DIMS, dims);
    133136 */
    134137void G4OpenGLViewer::ResizeGLView()
    135138{
     139  // Check size
     140  GLint dims[2];
     141  glGetIntegerv(GL_MAX_VIEWPORT_DIMS, dims);
     142  if (fWinSize_x > (unsigned)dims[0]) {
     143    G4cerr << "Try to resize view greater than max X viewport dimension. Desired size "<<dims[0] <<" is resize to "<<  dims[0] << G4endl;
     144    fWinSize_x = dims[0];
     145  }
     146  if (fWinSize_y > (unsigned)dims[1]) {
     147    G4cerr << "Try to resize view greater than max Y viewport dimension. Desired size "<<dims[0] <<" is resize to "<<  dims[1] << G4endl;
     148    fWinSize_y = dims[1];
     149  }
    136150  int side = fWinSize_x;
    137151  if (fWinSize_y < fWinSize_x) side = fWinSize_y;
     
    560574  if (!fGL2PSAction) return false;
    561575
     576
    562577  fGL2PSAction->setFileName(fPrintFilename.c_str());
    563578  // try to resize
     
    567582  fWinSize_x = width;
    568583  fWinSize_y = height;
     584
    569585  ResizeGLView();
    570586  if (fGL2PSAction->enableFileWriting()) {
     587
     588    // FIXME : How to get the point size.... ?
     589    fGL2PSAction->setLineWidth(1);
     590    // FIXME : How to get the line width.... ?
     591    fGL2PSAction->setPointSize(30);
     592
    571593    DrawView ();
    572594    fGL2PSAction->disableFileWriting();
  • trunk/source/visualization/OpenGL/src/G4OpenGLXViewer.cc

    r942 r945  
    9191
    9292void G4OpenGLXViewer::SetView () {
    93   glXMakeCurrent (dpy, win, cx);
     93  glXMakeCurrent (dpy, fGLXWin, cx);
    9494  G4OpenGLViewer::SetView (); 
    9595}
     
    258258  class_hints -> res_class = NewString("G4OpenGL");
    259259
    260    win = XCreateWindow (dpy, XRootWindow (dpy, vi -> screen), x_origin,
     260   fGLXWin = XCreateWindow (dpy, XRootWindow (dpy, vi -> screen), x_origin,
    261261                        y_origin, fWinSize_x, fWinSize_y, 0, vi -> depth,
    262262                        InputOutput, vi -> visual, 
     
    265265                        &swa);
    266266 
    267    XSetWMProperties (dpy, win, &windowName, &iconName, 0, 0,
     267   XSetWMProperties (dpy, fGLXWin, &windowName, &iconName, 0, 0,
    268268                     size_hints, wm_hints, class_hints);
    269269 
    270270// request X to Draw window on screen.
    271   XMapWindow (dpy, win);
     271  XMapWindow (dpy, fGLXWin);
    272272
    273273// Wait for window to appear (wait for an "expose" event).
    274   XIfEvent (dpy, &event, G4OpenGLXViewerWaitForNotify, (char*) win);
     274  XIfEvent (dpy, &event, G4OpenGLXViewerWaitForNotify, (char*) fGLXWin);
    275275
    276276// connect the context to a window
    277   Bool success = glXMakeCurrent (dpy, win, cx);
     277  Bool success = glXMakeCurrent (dpy, fGLXWin, cx);
    278278  if (!success) {
    279279    fViewId = -1;  // This flags an error.
     
    404404    glXMakeCurrent (dpy, None, NULL);
    405405    glXDestroyContext (dpy, cx);
    406     if (win) XDestroyWindow (dpy, win); // ...if already deleted in
     406    if (fGLXWin) XDestroyWindow (dpy, fGLXWin); // ...if already deleted in
    407407    // sub-class G4OpenGLXmViewer.
    408408    XFlush (dpy);
     
    415415  //cout << "print_col_callback requested with file name: " << fPrintFilename << G4endl;
    416416 
     417  if (fVectoredPs) {
    417418#ifdef G4DEBUG_VIS_OGL
    418   printf("G4OpenGLXViewer::print \n");
     419    printf("G4OpenGLXViewer::print Vectored\n");
    419420#endif
    420   if (fVectoredPs) {
    421421    printEPS();   
    422422  } else {
     423#ifdef G4DEBUG_VIS_OGL
     424    printf("G4OpenGLXViewer::print non Vectored\n");
     425#endif
    423426    //    printEPS ();
    424427    //    return;
     
    446449   
    447450    GLXDrawable tmp_win;
    448     tmp_win=win;
    449     win=glxpmap;
    450    
     451    tmp_win=fGLXWin;
     452    fGLXWin=glxpmap;
     453   
     454    // This won't work because fGLXWin is not known in G4OpenGLViewer...
     455
    451456    glXMakeCurrent (dpy,
    452                     win,
     457                    fGLXWin,
    453458                    cx);
    454459       
     460    glViewport (0, 0, fWinSize_x, fWinSize_y);
     461   
    455462    ClearView ();
    456463    SetView ();
    457464    DrawView ();
    458465   
    459     printEPS ();
    460    
    461     win=tmp_win;
     466    std::string file = "G4OpenGL_XPixmap.eps";
     467    generateEPSX (file.c_str(),
     468                 fPrintColour,
     469                 fWinSize_x, fWinSize_y);
     470   
     471    fGLXWin=tmp_win;
    462472    cx=tmp_cx;
    463473   
    464474    glXMakeCurrent (dpy,
    465                     win,
     475                    fGLXWin,
    466476                    cx);
    467477   
     
    489499}
    490500
     501
     502GLubyte* G4OpenGLXViewer::grabPixelsX (int inColor, unsigned int width, unsigned int height) {
     503         
     504  GLubyte* buffer;
     505  GLint swapbytes, lsbfirst, rowlength;
     506  GLint skiprows, skippixels, alignment;
     507  GLenum format;
     508  int size;
     509       
     510  if (inColor) {
     511    format = GL_RGB;
     512    size = width*height*3;
     513  } else {
     514    format = GL_LUMINANCE;
     515    size = width*height*1;
     516  }
     517       
     518  buffer = new GLubyte[size];
     519  if (buffer == NULL)
     520    return NULL;
     521       
     522  glGetIntegerv (GL_UNPACK_SWAP_BYTES, &swapbytes);
     523  glGetIntegerv (GL_UNPACK_LSB_FIRST, &lsbfirst);
     524  glGetIntegerv (GL_UNPACK_ROW_LENGTH, &rowlength);
     525       
     526  glGetIntegerv (GL_UNPACK_SKIP_ROWS, &skiprows);
     527  glGetIntegerv (GL_UNPACK_SKIP_PIXELS, &skippixels);
     528  glGetIntegerv (GL_UNPACK_ALIGNMENT, &alignment);
     529       
     530  glPixelStorei (GL_UNPACK_SWAP_BYTES, GL_FALSE);
     531  glPixelStorei (GL_UNPACK_LSB_FIRST, GL_FALSE);
     532  glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);
     533       
     534  glPixelStorei (GL_UNPACK_SKIP_ROWS, 0);
     535  glPixelStorei (GL_UNPACK_SKIP_PIXELS, 0);
     536  glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
     537       
     538  glReadPixels (0, 0, (GLsizei)width, (GLsizei)height, format, GL_UNSIGNED_BYTE, (GLvoid*) buffer);
     539       
     540  glPixelStorei (GL_UNPACK_SWAP_BYTES, swapbytes);
     541  glPixelStorei (GL_UNPACK_LSB_FIRST, lsbfirst);
     542  glPixelStorei (GL_UNPACK_ROW_LENGTH, rowlength);
     543         
     544  glPixelStorei (GL_UNPACK_SKIP_ROWS, skiprows);
     545  glPixelStorei (GL_UNPACK_SKIP_PIXELS, skippixels);
     546  glPixelStorei (GL_UNPACK_ALIGNMENT, alignment);
     547         
     548  return buffer;
     549}
     550       
     551int G4OpenGLXViewer::generateEPSX (const char* filnam,
     552                                  int inColour,
     553                                  unsigned int width,
     554                                  unsigned int height) {
     555       
     556  FILE* fp;
     557  GLubyte* pixels;
     558  GLubyte* curpix;
     559  int components, pos, i;
     560       
     561  pixels = grabPixelsX (inColour, width, height);
     562       
     563  if (pixels == NULL)
     564    return 1;
     565  if (inColour) {
     566    components = 3;
     567  } else {
     568    components = 1;
     569  }
     570         
     571  fp = fopen (filnam, "w");
     572  if (fp == NULL) {
     573    return 2;
     574  }
     575         
     576  fprintf (fp, "%%!PS-Adobe-2.0 EPSF-1.2\n");
     577  fprintf (fp, "%%%%Title: %s\n", filnam);
     578  fprintf (fp, "%%%%Creator: OpenGL pixmap render output\n");
     579  fprintf (fp, "%%%%BoundingBox: 0 0 %d %d\n", width, height);
     580  fprintf (fp, "%%%%EndComments\n");
     581  fprintf (fp, "gsave\n");
     582  fprintf (fp, "/bwproc {\n");
     583  fprintf (fp, "    rgbproc\n");
     584  fprintf (fp, "    dup length 3 idiv string 0 3 0 \n");
     585  fprintf (fp, "    5 -1 roll {\n");
     586  fprintf (fp, "    add 2 1 roll 1 sub dup 0 eq\n");
     587  fprintf (fp, "    { pop 3 idiv 3 -1 roll dup 4 -1 roll dup\n");
     588  fprintf (fp, "       3 1 roll 5 -1 roll } put 1 add 3 0 \n");
     589  fprintf (fp, "    { 2 1 roll } ifelse\n");
     590  fprintf (fp, "    }forall\n");
     591  fprintf (fp, "    pop pop pop\n");
     592  fprintf (fp, "} def\n");
     593  fprintf (fp, "systemdict /colorimage known not {\n");
     594  fprintf (fp, "   /colorimage {\n");
     595  fprintf (fp, "       pop\n");
     596  fprintf (fp, "       pop\n");
     597  fprintf (fp, "       /rgbproc exch def\n");
     598  fprintf (fp, "       { bwproc } image\n");
     599  fprintf (fp, "   }  def\n");
     600  fprintf (fp, "} if\n");
     601  fprintf (fp, "/picstr %d string def\n", width * components);
     602  fprintf (fp, "%d %d scale\n", width, height);
     603  fprintf (fp, "%d %d %d\n", width, height, 8);
     604  fprintf (fp, "[%d 0 0 %d 0 0]\n", width, height);
     605  fprintf (fp, "{currentfile picstr readhexstring pop}\n");
     606  fprintf (fp, "false %d\n", components);
     607  fprintf (fp, "colorimage\n");
     608         
     609  curpix = (GLubyte*) pixels;
     610  pos = 0;
     611  for (i = width*height*components; i>0; i--) {
     612    fprintf (fp, "%02hx ", *(curpix++));
     613    if (++pos >= 32) {
     614      fprintf (fp, "\n");
     615      pos = 0;
     616    }
     617  }
     618  if (pos)
     619    fprintf (fp, "\n");
     620       
     621  fprintf (fp, "grestore\n");
     622  fprintf (fp, "showpage\n");
     623  delete pixels;
     624  fclose (fp);
     625  return 0;
     626}
     627       
     628
    491629#endif
  • trunk/source/visualization/OpenGL/src/G4OpenGLXmViewer.cc

    r915 r945  
    635635  // can bind the OpenGL rendering context to the window.
    636636
    637   win = XtWindow (glxarea);
    638 
    639   glXMakeCurrent (dpy, win, cx);
     637  fGLXWin = XtWindow (glxarea);
     638
     639  glXMakeCurrent (dpy, fGLXWin, cx);
    640640
    641641  // This should be add AFTER glXMakeCurrent done because it will fire a resizeCallback
     
    684684{
    685685  XtDestroyWidget  (shell);
    686   win = 0; // ...to avoid XDestroyWindow in G4OpenGLXViewer base class
     686  fGLXWin = 0; // ...to avoid XDestroyWindow in G4OpenGLXViewer base class
    687687  // because XtDestroyWidget has already destroyed it.
    688688  G4Xt::getInstance () ->RemoveShell (shell);
  • trunk/source/visualization/externals/gl2ps/include/G4OpenGL2PSAction.hh

    r943 r945  
    4343
    4444 bool fileWritingEnabled() const;
     45 void setLineWidth(int);
     46 void setPointSize(int);
    4547
    4648protected:
Note: See TracChangeset for help on using the changeset viewer.