Geant4-11
SoGL2PSAction.cc
Go to the documentation of this file.
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
27/*----------------------------HEPVis----------------------------------------*/
28/* */
29/* Node: SoGL2PSAction */
30/* Author: Guy Barrand */
31/* */
32/*--------------------------------------------------------------------------*/
33
34// this :
36
37// Inventor :
38#include <Inventor/elements/SoViewportRegionElement.h>
39#include <Inventor/errors/SoDebugError.h>
40
41#include "Geant4_gl2ps.h"
42
43#include <stdio.h>
44
45SO_ACTION_SOURCE(SoGL2PSAction)
47void SoGL2PSAction::initClass(
48)
51{
52 static bool first = true;
53 if (first) {
54 first = false;
55 SO_ACTION_INIT_CLASS(SoGL2PSAction,SoGLRenderAction);
56 }
57}
60 const SbViewportRegion& aViewPortRegion
61)
62:SoGLRenderAction(aViewPortRegion)
66{
67 setFileName("out.ps");
68 SO_ACTION_CONSTRUCTOR(SoGL2PSAction);
69}
70
72)
75{
76 fFile = ::fopen(fFileName,"w");
77 if(!fFile) {
78 SoDebugError::post("SoGL2PSAction::enableFileWriting",
79 "Cannot open file %s",fFileName.c_str());
80 return false;
81 }
82#ifdef __COIN__
83#else //SGI
84 const SbViewportRegion& vpr = getViewportRegion();
85 SoViewportRegionElement::set(getState(),vpr);
87#endif
88 return true;
89}
92)
95{
96#ifdef __COIN__
97#else //SGI
98 gl2psEndPage();
99#endif
100 ::fclose(fFile);
101 fFile = 0;
102}
103
106 int aWidth
107,int aHeight
108,float aXorig
109,float aYorig
110,float aXmove
111,float aYmove
112)
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}
144 SoNode* aNode
145)
148{
149 if(fFile) {
150#ifdef __COIN__
151 const SbViewportRegion& vpr = getViewportRegion();
152 SoViewportRegionElement::set(getState(),vpr);
153 G4gl2psBegin();
154 traverse(aNode);
155 gl2psEndPage();
156#else //SGI
157 // Should have already do G4gl2psBegin() before
158 SoGLRenderAction::beginTraversal(aNode);
159 // Should do gl2psEndPage() after
160#endif
161 } else {
162 SoGLRenderAction::beginTraversal(aNode);
163 }
164}
static const G4double pos
static constexpr double s
Definition: G4SIunits.hh:154
#define gl2psEndPage
Definition: Geant4_gl2ps.h:35
#define gl2psDrawPixels
Definition: Geant4_gl2ps.h:41
bool G4gl2psBegin()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void setFileName(const char *)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
bool enableFileWriting()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
SoGL2PSAction(const SbViewportRegion &)
bool addBitmap(int, int, float=0, float=0, float=0, float=0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
virtual void beginTraversal(SoNode *)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void disableFileWriting()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
#define GL2PS_SUCCESS
Definition: gl2ps.h:144