Changeset 921 for trunk/source/visualization/OpenInventor
- Timestamp:
- Feb 16, 2009, 10:14:30 AM (15 years ago)
- Location:
- trunk/source/visualization/OpenInventor
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/visualization/OpenInventor/GNUmakefile
r529 r921 18 18 include $(G4INSTALL)/config/interactivity.gmk 19 19 20 ifdef G4VIS_BUILD_OPENGL_DRIVER 21 CPPFLAGS += -I$(G4BASE)/visualization/externals/gl2ps/include 22 endif 23 ifdef G4VIS_BUILD_OI_DRIVER 24 CPPFLAGS += -I$(G4BASE)/visualization/externals/gl2ps/include 25 endif 26 20 27 CPPFLAGS += -I$(G4BASE)/visualization/management/include 21 28 CPPFLAGS += -I$(G4BASE)/visualization/modeling/include … … 33 40 CPPFLAGS += -I$(G4BASE)/digits_hits/hits/include 34 41 42 INTYLIBS += -L$(G4LIBDIR) -lG4gl2ps 43 35 44 include $(G4INSTALL)/config/common.gmk 36 45 -
trunk/source/visualization/OpenInventor/include/HEPVis/actions/SoGL2PSAction.h
r529 r921 28 28 29 29 #include <Inventor/actions/SoGLRenderAction.h> 30 #include "G4OpenGL2PSAction.hh" 30 31 31 32 /** … … 37 38 #define SoGL2PSAction Geant4_SoGL2PSAction 38 39 39 class SoGL2PSAction : public SoGLRenderAction {40 class SoGL2PSAction : public SoGLRenderAction, public G4OpenGL2PSAction { 40 41 SO_ACTION_HEADER(SoGL2PSAction); 41 42 public: 42 43 SoGL2PSAction(const SbViewportRegion&); 43 void setFileName(const char*);44 void enableFileWriting();45 void disableFileWriting();46 SbBool fileWritingEnabled() const;47 SbBool addBitmap(int,int,float=0,float=0,float=0,float=0);48 void beginViewport();49 void endViewport();50 44 public: /*SoINTERNAL*/ 51 45 static void initClass(); 52 46 protected: 53 47 virtual void beginTraversal(SoNode*); 54 private: 55 void gl2psBegin(); 56 private: 57 SbString fFileName; 58 FILE* fFile; 48 void setViewport(); 59 49 }; 60 50 -
trunk/source/visualization/OpenInventor/src/G4OpenInventorViewer.cc
r850 r921 50 50 #include "G4Scene.hh" 51 51 #include "Geant4_SoPolyhedron.h" 52 #include "G4AttValue.hh" 53 #include "G4AttDef.hh" 52 #include "G4AttValue.hh"#include "G4AttDef.hh" 54 53 #include "G4AttCheck.hh" 55 54 #include "G4AttHolder.hh" … … 480 479 fGL2PSAction->setFileName(aFile.c_str()); 481 480 G4cout << "Produce " << aFile << "..." << G4endl; 482 fGL2PSAction->enableFileWriting(); 483 ViewerRender(); 484 fGL2PSAction->disableFileWriting(); 481 if (fGL2PSAction->enableFileWriting()) { 482 ViewerRender(); 483 fGL2PSAction->disableFileWriting(); 484 } 485 485 } 486 486 -
trunk/source/visualization/OpenInventor/src/SoGL2PSAction.cc
r529 r921 33 33 /*--------------------------------------------------------------------------*/ 34 34 35 35 36 // this : 36 37 #include <HEPVis/actions/SoGL2PSAction.h> … … 40 41 #include <Inventor/errors/SoDebugError.h> 41 42 42 #include "Geant4_gl2ps.h"43 //#include "Geant4_gl2ps.h" 43 44 44 45 #include <stdio.h> … … 58 59 ) 59 60 :SoGLRenderAction(aViewPortRegion) 60 ,fFileName("out.ps") 61 ,fFile(0) 61 ,G4OpenGL2PSAction() 62 62 ////////////////////////////////////////////////////////////////////////////// 63 63 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// 64 64 { 65 setFileName("out.ps"); 65 66 SO_ACTION_CONSTRUCTOR(SoGL2PSAction); 66 67 } 67 68 ////////////////////////////////////////////////////////////////////////////// 68 void SoGL2PSAction::setFileName( 69 const char* aFileName 69 void SoGL2PSAction::setViewport( 70 70 ) 71 71 ////////////////////////////////////////////////////////////////////////////// 72 72 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// 73 73 { 74 fFileName = aFileName; 75 } 76 ////////////////////////////////////////////////////////////////////////////// 77 void SoGL2PSAction::enableFileWriting( 78 ) 79 ////////////////////////////////////////////////////////////////////////////// 80 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// 81 { 82 fFile = ::fopen(fFileName.getString(),"w"); 83 if(!fFile) { 84 SoDebugError::post("SoGL2PSAction::enableFileWriting", 85 "Cannot open file %s",fFileName.getString()); 86 return; 87 } 74 // FIXME Useful ?? 75 88 76 #ifdef __COIN__ 89 77 #else //SGI 90 78 const SbViewportRegion& vpr = getViewportRegion(); 91 79 SoViewportRegionElement::set(getState(),vpr); 92 gl2psBegin(); 80 81 const SbVec2s& win = vpr.getWindowSize(); 82 fViewport[0] = 0; 83 fViewport[1] = 0; 84 fViewport[2] = win[0]; 85 fViewport[3] = win[1]; 93 86 #endif 94 }95 //////////////////////////////////////////////////////////////////////////////96 void SoGL2PSAction::disableFileWriting(97 )98 //////////////////////////////////////////////////////////////////////////////99 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//100 {101 #ifdef __COIN__102 #else //SGI103 gl2psEndPage();104 #endif105 ::fclose(fFile);106 fFile = 0;107 }108 //////////////////////////////////////////////////////////////////////////////109 SbBool SoGL2PSAction::fileWritingEnabled(110 ) const111 //////////////////////////////////////////////////////////////////////////////112 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//113 {114 return (fFile?TRUE:FALSE);115 }116 //////////////////////////////////////////////////////////////////////////////117 SbBool SoGL2PSAction::addBitmap(118 int aWidth119 ,int aHeight120 ,float aXorig121 ,float aYorig122 ,float aXmove123 ,float aYmove124 )125 /////////////////////////////////////////////////////////////////////////////126 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//127 {128 if(!fFile) return FALSE;129 GLboolean valid;130 glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID,&valid);131 if(valid==GL_FALSE) return FALSE;132 float pos[4];133 glGetFloatv(GL_CURRENT_RASTER_POSITION,pos);134 int xoff = -(int)(aXmove + aXorig);135 int yoff = -(int)(aYmove + aYorig);136 int x = (int)(pos[0] + xoff);137 int y = (int)(pos[1] + yoff);138 // Should clip against viewport area :139 GLint vp[4];140 glGetIntegerv(GL_VIEWPORT,vp);141 GLsizei w = aWidth;142 GLsizei h = aHeight;143 if(x+w>(vp[0]+vp[2])) w = vp[0]+vp[2]-x;144 if(y+h>(vp[1]+vp[3])) h = vp[1]+vp[3]-y;145 int s = 3 * w * h;146 if(s<=0) return FALSE;147 float* image = (float*)::malloc(s * sizeof(float));148 if(!image) return FALSE;149 glReadPixels(x,y,w,h,GL_RGB,GL_FLOAT,image);150 GLint status = gl2psDrawPixels(w,h,xoff,yoff,GL_RGB,GL_FLOAT,image);151 ::free(image);152 return (status!=GL2PS_SUCCESS ? FALSE : TRUE);153 }154 //////////////////////////////////////////////////////////////////////////////155 void SoGL2PSAction::beginViewport(156 )157 /////////////////////////////////////////////////////////////////////////////158 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//159 {160 if(!fFile) return;161 GLint vp[4];162 glGetIntegerv(GL_VIEWPORT,vp);163 gl2psBeginViewport(vp);164 }165 //////////////////////////////////////////////////////////////////////////////166 void SoGL2PSAction::endViewport(167 )168 /////////////////////////////////////////////////////////////////////////////169 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//170 {171 if(!fFile) return;172 gl2psEndViewport();173 87 } 174 88 ////////////////////////////////////////////////////////////////////////////// … … 183 97 const SbViewportRegion& vpr = getViewportRegion(); 184 98 SoViewportRegionElement::set(getState(),vpr); 185 gl2psBegin();99 Geant4_gl2psBegin(); 186 100 traverse(aNode); 187 gl2psEndPage();101 Geant4_gl2psEndPage(); 188 102 #else //SGI 189 103 SoGLRenderAction::beginTraversal(aNode); … … 193 107 } 194 108 } 195 //////////////////////////////////////////////////////////////////////////////196 void SoGL2PSAction::gl2psBegin(197 )198 //////////////////////////////////////////////////////////////////////////////199 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//200 {201 if(!fFile) return;202 int options = GL2PS_OCCLUSION_CULL |203 GL2PS_BEST_ROOT | GL2PS_SILENT | GL2PS_DRAW_BACKGROUND;204 int sort = GL2PS_BSP_SORT;205 //int sort = GL2PS_SIMPLE_SORT;206 207 const SbViewportRegion& vpr = getViewportRegion();208 SoViewportRegionElement::set(getState(),vpr);209 210 const SbVec2s& win = vpr.getWindowSize();211 GLint vp[4];212 vp[0] = 0;213 vp[1] = 0;214 vp[2] = win[0];215 vp[3] = win[1];216 217 int bufsize = 0;218 gl2psBeginPage("title","HEPVis::SoGL2PSAction",219 vp,220 GL2PS_EPS,221 sort,222 options,223 GL_RGBA,0, NULL,0,0,0,224 bufsize,225 fFile,fFileName.getString());226 }227 109 228 110 #endif
Note: See TracChangeset
for help on using the changeset viewer.