ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4OpenGL2PSAction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4OpenGL2PSAction.cc
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 //
28 //
29 
30 #ifdef G4VIS_BUILD_OPENGL_DRIVER
31  #define G4VIS_BUILD_OPENGL_GL2PS
32 #endif
33 #ifdef G4VIS_BUILD_OI_DRIVER
34  #define G4VIS_BUILD_OPENGL_GL2PS
35 #endif
36 
37 #ifdef G4VIS_BUILD_OPENGL_GL2PS
38 
39 #include "G4OpenGL2PSAction.hh"
40 
41 #include <limits>
42 #include <cstdlib>
43 #include <cstring>
44 
46 )
49 {
50  fFile = 0;
51  fViewport[0] = 0;
52  fViewport[1] = 0;
53  fViewport[2] = 0;
54  fViewport[3] = 0;
55  fBufferSize = 2048;
59 }
60 
63 )
66 {
67  fBufferSize = 2048;
68 }
69 
72  int width
73 )
76 {
77  gl2psLineWidth( width );
78 }
79 
82  int size
83 )
86 {
87  gl2psPointSize( size );
88 }
89 
92 int a
93 ,int b
94 ,int winSizeX
95 ,int winSizeY
96 )
99 {
100  fViewport[0] = a;
101  fViewport[1] = b;
102  fViewport[2] = winSizeX;
103  fViewport[3] = winSizeY;
104 }
105 
108  const char* aFileName
109 )
112 {
113  fFileName = aFileName;
114 }
117 )
120 {
121  fFile = ::fopen(fFileName,"wb");
122  if(!fFile) {
123  return false;
124  }
125 
126  // No buffering for output file
127  setvbuf ( fFile , NULL , _IONBF , 2048 );
128  return G4gl2psBegin();
129 }
132 )
135 {
136  int state = gl2psEndPage();
137  ::fclose(fFile);
138  if (state == GL2PS_OVERFLOW) {
139  return false;
140  }
141  fFile = 0;
142  return true;
143 }
146 )
149 {
150  // extend buffer size *2
151  if (fBufferSize < (fBufferSizeLimit/2)) {
153  return true;
154  }
155  return false;
156 }
157 
158 
159 // FWJ
160 void G4OpenGL2PSAction::setBufferSize(int newSize)
161 {
162  fBufferSize = (newSize < int(fBufferSizeLimit))
163  ? GLint(newSize) : fBufferSizeLimit;
164 }
165 
166 
168 ) const
171 {
172  return (fFile?true:false);
173 }
176 )
179 {
180  if(!fFile) return false;
181  int options =
183  int sort = GL2PS_BSP_SORT;
184 
185  glGetIntegerv(GL_VIEWPORT,fViewport);
186  GLint res = gl2psBeginPage("Geant4 output","Geant4",
187  fViewport,
189  sort,
190  options,
191  GL_RGBA,0, NULL,0,0,0,
192  fBufferSize,
193  fFile,fFileName.c_str());
194  if (res == GL2PS_ERROR) {
195  return false;
196  }
197  // enable blending for all
199 
200  return true;
201 }
202 
203 void G4OpenGL2PSAction::setExportImageFormat(unsigned int type){
204  if(!fFile) {
205  fExportImageFormat = type;
206  } else {
207  // Could not change the file type at this step. Please change it before enableFileWriting()
208  }
209 }
210 
211 
212 
213 
214 #endif