- Timestamp:
- Feb 16, 2009, 10:14:30 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.