Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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#ifdef G4VIS_BUILD_OI_DRIVER
27
28/*----------------------------HEPVis----------------------------------------*/
29/* */
30/* Node: SoGL2PSAction */
31/* Author: Guy Barrand */
32/* */
33/*--------------------------------------------------------------------------*/
34
35// this :
37
38// Inventor :
39#include <Inventor/elements/SoViewportRegionElement.h>
40#include <Inventor/errors/SoDebugError.h>
41
42#include "Geant4_gl2ps.h"
43
44#include <stdio.h>
45
46SO_ACTION_SOURCE(SoGL2PSAction)
47//////////////////////////////////////////////////////////////////////////////
49)
50//////////////////////////////////////////////////////////////////////////////
51//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
52{
53 static bool first = true;
54 if (first) {
55 first = false;
56 SO_ACTION_INIT_CLASS(SoGL2PSAction,SoGLRenderAction);
57 }
58}
59//////////////////////////////////////////////////////////////////////////////
61 const SbViewportRegion& aViewPortRegion
62)
63:SoGLRenderAction(aViewPortRegion)
65//////////////////////////////////////////////////////////////////////////////
66//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
67{
68 setFileName("out.ps");
69 SO_ACTION_CONSTRUCTOR(SoGL2PSAction);
70}
71
73)
74//////////////////////////////////////////////////////////////////////////////
75//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
76{
77 fFile = ::fopen(fFileName,"w");
78 if(!fFile) {
79 SoDebugError::post("SoGL2PSAction::enableFileWriting",
80 "Cannot open file %s",fFileName.c_str());
81 return false;
82 }
83#ifdef __COIN__
84#else //SGI
85 const SbViewportRegion& vpr = getViewportRegion();
86 SoViewportRegionElement::set(getState(),vpr);
88#endif
89 return true;
90}
91//////////////////////////////////////////////////////////////////////////////
93)
94//////////////////////////////////////////////////////////////////////////////
95//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
96{
97#ifdef __COIN__
98#else //SGI
99 gl2psEndPage();
100#endif
101 ::fclose(fFile);
102 fFile = 0;
103}
104
105//////////////////////////////////////////////////////////////////////////////
107 int aWidth
108,int aHeight
109,float aXorig
110,float aYorig
111,float aXmove
112,float aYmove
113)
114/////////////////////////////////////////////////////////////////////////////
115//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
116{
117 if(!fFile) return false;
118 GLboolean valid;
119 glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID,&valid);
120 if(!valid) return false;
121 float pos[4];
122 glGetFloatv(GL_CURRENT_RASTER_POSITION,pos);
123 int xoff = -(int)(aXmove + aXorig);
124 int yoff = -(int)(aYmove + aYorig);
125 int x = (int)(pos[0] + xoff);
126 int y = (int)(pos[1] + yoff);
127 // Should clip against viewport area :
128 GLint vp[4];
129 glGetIntegerv(GL_VIEWPORT,vp);
130 GLsizei w = aWidth;
131 GLsizei h = aHeight;
132 if(x+w>(vp[0]+vp[2])) w = vp[0]+vp[2]-x;
133 if(y+h>(vp[1]+vp[3])) h = vp[1]+vp[3]-y;
134 int s = 3 * w * h;
135 if(s<=0) return false;
136 float* image = (float*)::malloc(s * sizeof(float));
137 if(!image) return false;
138 glReadPixels(x,y,w,h,GL_RGB,GL_FLOAT,image);
139 GLint status = gl2psDrawPixels(w,h,xoff,yoff,GL_RGB,GL_FLOAT,image);
140 ::free(image);
141 return (status!=GL2PS_SUCCESS ? false : true);
142}
143//////////////////////////////////////////////////////////////////////////////
145 SoNode* aNode
146)
147//////////////////////////////////////////////////////////////////////////////
148//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
149{
150 if(fFile) {
151#ifdef __COIN__
152 const SbViewportRegion& vpr = getViewportRegion();
153 SoViewportRegionElement::set(getState(),vpr);
154 G4gl2psBegin();
155 traverse(aNode);
156 gl2psEndPage();
157#else //SGI
158 // Should have already do G4gl2psBegin() before
159 SoGLRenderAction::beginTraversal(aNode);
160 // Should do gl2psEndPage() after
161#endif
162 } else {
163 SoGLRenderAction::beginTraversal(aNode);
164 }
165}
166
167#endif
#define gl2psEndPage
Definition: Geant4_gl2ps.h:35
#define gl2psDrawPixels
Definition: Geant4_gl2ps.h:41
static void initClass()
bool enableFileWriting()
SoGL2PSAction(const SbViewportRegion &)
bool addBitmap(int, int, float=0, float=0, float=0, float=0)
void disableFileWriting()
virtual void beginTraversal(SoNode *)
#define GL2PS_SUCCESS
Definition: gl2ps.h:142