Geant4  10.01.p03
G4OpenGL2PSAction.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 // $Id: G4OpenGL2PSAction.cc 82763 2014-07-08 14:22:48Z gcosmo $
28 //
29 //
30 
31 #ifdef G4VIS_BUILD_OPENGL_DRIVER
32  #define G4VIS_BUILD_OPENGL_GL2PS
33 #endif
34 #ifdef G4VIS_BUILD_OI_DRIVER
35  #define G4VIS_BUILD_OPENGL_GL2PS
36 #endif
37 
38 #ifdef G4VIS_BUILD_OPENGL_GL2PS
39 
40 #include "G4OpenGL2PSAction.hh"
41 
42 #include <limits>
43 #include <cstdlib>
44 #include <cstring>
45 
47 )
50 {
51  fFileName = "";
52  fFile = 0;
53  fViewport[0] = 0;
54  fViewport[1] = 0;
55  fViewport[2] = 0;
56  fViewport[3] = 0;
57  fBufferSize = 2048;
59  fExportImageFormat = GL2PS_PDF;
61 }
62 
65 )
68 {
69  fBufferSize = 2048;
70 }
71 
74  int width
75 )
78 {
79  gl2psLineWidth( width );
80 }
81 
84  int size
85 )
88 {
89  gl2psPointSize( size );
90 }
91 
94 int a
95 ,int b
96 ,int winSizeX
97 ,int winSizeY
98 )
101 {
102  fViewport[0] = a;
103  fViewport[1] = b;
104  fViewport[2] = winSizeX;
105  fViewport[3] = winSizeY;
106 }
107 
110  const char* aFileName
111 )
114 {
115  fFileName = (strncpy((char*)malloc((unsigned)strlen(aFileName) + 1), aFileName, (unsigned)strlen(aFileName) + 1));
116 }
119 )
122 {
123  fFile = ::fopen(fFileName,"wb");
124  if(!fFile) {
125  return false;
126  }
127 
128  // No buffering for output file
129  setvbuf ( fFile , NULL , _IONBF , 2048 );
130  return G4gl2psBegin();
131 }
134 )
137 {
138  int state = gl2psEndPage();
139  ::fclose(fFile);
140  if (state == GL2PS_OVERFLOW) {
141  return false;
142  }
143  fFile = 0;
144  return true;
145 }
148 )
151 {
152  // extend buffer size *2
153  if (fBufferSize < (fBufferSizeLimit/2)) {
155  return true;
156  }
157  return false;
158 }
161 ) const
164 {
165  return (fFile?true:false);
166 }
169 )
172 {
173  if(!fFile) return false;
174  int options =
175  GL2PS_BEST_ROOT | GL2PS_DRAW_BACKGROUND |GL2PS_USE_CURRENT_VIEWPORT;
176  int sort = GL2PS_BSP_SORT;
177 
178  glGetIntegerv(GL_VIEWPORT,fViewport);
179  GLint res = gl2psBeginPage("Geant4 output","Geant4",
180  fViewport,
182  sort,
183  options,
184  GL_RGBA,0, NULL,0,0,0,
185  fBufferSize,
186  fFile,fFileName);
187  if (res == GL2PS_ERROR) {
188  return false;
189  }
190  // enable blending for all
191  gl2psEnable(GL2PS_BLEND);
192 
193  return true;
194 }
195 
196 void G4OpenGL2PSAction::setExportImageFormat(unsigned int type){
197  if(!fFile) {
198  fExportImageFormat = type;
199  } else {
200  // Could not change the file type at this step. Please change it before enableFileWriting()
201  }
202 }
203 
204 
205 
206 
207 #endif
#define width
G4double a
Definition: TRTMaterials.hh:39
void setPointSize(int)
bool disableFileWriting()
void setFileName(const char *)
void setLineWidth(int)
unsigned int fExportImageFormat
bool enableFileWriting()
void setExportImageFormat(unsigned int)
void resetBufferSizeParameters()
void setViewport(int, int, int, int)
const char * fFileName
T max(const T t1, const T t2)
brief Return the largest of the two arguments
bool fileWritingEnabled() const