[529] | 1 | // |
---|
| 2 | // ******************************************************************** |
---|
| 3 | // * License and Disclaimer * |
---|
| 4 | // * * |
---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
| 7 | // * conditions of the Geant4 Software License, included in the file * |
---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
| 9 | // * include a list of copyright holders. * |
---|
| 10 | // * * |
---|
| 11 | // * Neither the authors of this software system, nor their employing * |
---|
| 12 | // * institutes,nor the agencies providing financial support for this * |
---|
| 13 | // * work make any representation or warranty, express or implied, * |
---|
| 14 | // * regarding this software system or assume any liability for its * |
---|
| 15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
| 16 | // * for the full disclaimer and the limitation of liability. * |
---|
| 17 | // * * |
---|
| 18 | // * This code implementation is the result of the scientific and * |
---|
| 19 | // * technical work of the GEANT4 collaboration. * |
---|
| 20 | // * By using, copying, modifying or distributing the software (or * |
---|
| 21 | // * any work based on the software) you agree to acknowledge its * |
---|
| 22 | // * use in resulting scientific publications, and indicate your * |
---|
| 23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
| 24 | // ******************************************************************** |
---|
| 25 | // |
---|
| 26 | #ifdef G4VIS_BUILD_OI_DRIVER |
---|
| 27 | |
---|
| 28 | /*----------------------------HEPVis----------------------------------------*/ |
---|
| 29 | /* */ |
---|
| 30 | /* Node: SoGL2PSAction */ |
---|
| 31 | /* Author: Guy Barrand */ |
---|
| 32 | /* */ |
---|
| 33 | /*--------------------------------------------------------------------------*/ |
---|
| 34 | |
---|
| 35 | // this : |
---|
| 36 | #include <HEPVis/actions/SoGL2PSAction.h> |
---|
| 37 | |
---|
| 38 | // Inventor : |
---|
| 39 | #include <Inventor/elements/SoViewportRegionElement.h> |
---|
| 40 | #include <Inventor/errors/SoDebugError.h> |
---|
| 41 | |
---|
[923] | 42 | #include "Geant4_gl2ps.h" |
---|
[529] | 43 | |
---|
| 44 | #include <stdio.h> |
---|
| 45 | |
---|
| 46 | SO_ACTION_SOURCE(SoGL2PSAction) |
---|
| 47 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 48 | void SoGL2PSAction::initClass( |
---|
| 49 | ) |
---|
| 50 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 51 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
| 52 | { |
---|
| 53 | SO_ACTION_INIT_CLASS(SoGL2PSAction,SoGLRenderAction); |
---|
| 54 | } |
---|
| 55 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 56 | SoGL2PSAction::SoGL2PSAction( |
---|
| 57 | const SbViewportRegion& aViewPortRegion |
---|
| 58 | ) |
---|
| 59 | :SoGLRenderAction(aViewPortRegion) |
---|
[921] | 60 | ,G4OpenGL2PSAction() |
---|
[529] | 61 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 62 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
| 63 | { |
---|
[925] | 64 | setFileName("out.ps"); |
---|
[529] | 65 | SO_ACTION_CONSTRUCTOR(SoGL2PSAction); |
---|
| 66 | } |
---|
[926] | 67 | |
---|
[927] | 68 | bool SoGL2PSAction::enableFileWriting( |
---|
[926] | 69 | ) |
---|
[529] | 70 | ////////////////////////////////////////////////////////////////////////////// |
---|
[926] | 71 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
| 72 | { |
---|
[1051] | 73 | #ifdef G4DEBUG_VIS_OI |
---|
| 74 | printf("SoGL2PSAction::enableFileWriting\n"); |
---|
| 75 | #endif |
---|
[926] | 76 | fFile = ::fopen(fFileName,"w"); |
---|
| 77 | if(!fFile) { |
---|
| 78 | SoDebugError::post("SoGL2PSAction::enableFileWriting", |
---|
| 79 | "Cannot open file %s",fFileName); |
---|
[927] | 80 | return false; |
---|
[926] | 81 | } |
---|
| 82 | #ifdef __COIN__ |
---|
| 83 | #else //SGI |
---|
| 84 | const SbViewportRegion& vpr = getViewportRegion(); |
---|
| 85 | SoViewportRegionElement::set(getState(),vpr); |
---|
[928] | 86 | G4gl2psBegin(); |
---|
[926] | 87 | #endif |
---|
[927] | 88 | return true; |
---|
[926] | 89 | } |
---|
| 90 | ////////////////////////////////////////////////////////////////////////////// |
---|
[928] | 91 | void SoGL2PSAction::disableFileWriting( |
---|
[529] | 92 | ) |
---|
| 93 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 94 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
| 95 | { |
---|
| 96 | #ifdef __COIN__ |
---|
| 97 | #else //SGI |
---|
[928] | 98 | gl2psEndPage(); |
---|
[529] | 99 | #endif |
---|
[928] | 100 | ::fclose(fFile); |
---|
| 101 | fFile = 0; |
---|
[529] | 102 | } |
---|
[928] | 103 | |
---|
[529] | 104 | ////////////////////////////////////////////////////////////////////////////// |
---|
[929] | 105 | bool SoGL2PSAction::addBitmap( |
---|
| 106 | int aWidth |
---|
| 107 | ,int aHeight |
---|
| 108 | ,float aXorig |
---|
| 109 | ,float aYorig |
---|
| 110 | ,float aXmove |
---|
| 111 | ,float aYmove |
---|
| 112 | ) |
---|
| 113 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 114 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
| 115 | { |
---|
| 116 | if(!fFile) return false; |
---|
| 117 | GLboolean valid; |
---|
| 118 | glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID,&valid); |
---|
| 119 | if(!valid) return false; |
---|
| 120 | float pos[4]; |
---|
| 121 | glGetFloatv(GL_CURRENT_RASTER_POSITION,pos); |
---|
| 122 | int xoff = -(int)(aXmove + aXorig); |
---|
| 123 | int yoff = -(int)(aYmove + aYorig); |
---|
| 124 | int x = (int)(pos[0] + xoff); |
---|
| 125 | int y = (int)(pos[1] + yoff); |
---|
| 126 | // Should clip against viewport area : |
---|
| 127 | GLint vp[4]; |
---|
| 128 | glGetIntegerv(GL_VIEWPORT,vp); |
---|
| 129 | GLsizei w = aWidth; |
---|
| 130 | GLsizei h = aHeight; |
---|
| 131 | if(x+w>(vp[0]+vp[2])) w = vp[0]+vp[2]-x; |
---|
| 132 | if(y+h>(vp[1]+vp[3])) h = vp[1]+vp[3]-y; |
---|
| 133 | int s = 3 * w * h; |
---|
| 134 | if(s<=0) return false; |
---|
| 135 | float* image = (float*)::malloc(s * sizeof(float)); |
---|
| 136 | if(!image) return false; |
---|
| 137 | glReadPixels(x,y,w,h,GL_RGB,GL_FLOAT,image); |
---|
| 138 | GLint status = gl2psDrawPixels(w,h,xoff,yoff,GL_RGB,GL_FLOAT,image); |
---|
| 139 | ::free(image); |
---|
| 140 | return (status!=GL2PS_SUCCESS ? false : true); |
---|
| 141 | } |
---|
| 142 | ////////////////////////////////////////////////////////////////////////////// |
---|
[529] | 143 | void SoGL2PSAction::beginTraversal( |
---|
| 144 | SoNode* aNode |
---|
| 145 | ) |
---|
| 146 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 147 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
| 148 | { |
---|
| 149 | if(fFile) { |
---|
| 150 | #ifdef __COIN__ |
---|
| 151 | const SbViewportRegion& vpr = getViewportRegion(); |
---|
| 152 | SoViewportRegionElement::set(getState(),vpr); |
---|
[923] | 153 | G4gl2psBegin(); |
---|
[529] | 154 | traverse(aNode); |
---|
[928] | 155 | gl2psEndPage(); |
---|
[529] | 156 | #else //SGI |
---|
[928] | 157 | // Should have already do G4gl2psBegin() before |
---|
[529] | 158 | SoGLRenderAction::beginTraversal(aNode); |
---|
[928] | 159 | // Should do gl2psEndPage() after |
---|
[529] | 160 | #endif |
---|
| 161 | } else { |
---|
| 162 | SoGLRenderAction::beginTraversal(aNode); |
---|
| 163 | } |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | #endif |
---|