Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 88206 2015-02-03 13:01:27Z 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 }
159 
160 
161 // FWJ
162 void G4OpenGL2PSAction::setBufferSize(int newSize)
163 {
164  fBufferSize = (newSize < int(fBufferSizeLimit))
165  ? GLint(newSize) : fBufferSizeLimit;
166 }
167 
168 
170 ) const
173 {
174  return (fFile?true:false);
175 }
178 )
181 {
182  if(!fFile) return false;
183  int options =
185  int sort = GL2PS_BSP_SORT;
186 
187  glGetIntegerv(GL_VIEWPORT,fViewport);
188  GLint res = gl2psBeginPage("Geant4 output","Geant4",
189  fViewport,
190  fExportImageFormat,
191  sort,
192  options,
193  GL_RGBA,0, NULL,0,0,0,
194  fBufferSize,
195  fFile,fFileName);
196  if (res == GL2PS_ERROR) {
197  return false;
198  }
199  // enable blending for all
201 
202  return true;
203 }
204 
205 void G4OpenGL2PSAction::setExportImageFormat(unsigned int type){
206  if(!fFile) {
207  fExportImageFormat = type;
208  } else {
209  // Could not change the file type at this step. Please change it before enableFileWriting()
210  }
211 }
212 
213 
214 
215 
216 #endif
GL2PSDLL_API GLint gl2psBeginPage(const char *title, const char *producer, GLint viewport[4], GLint format, GLint sort, GLint options, GLint colormode, GLint colorsize, GL2PSrgba *colormap, GLint nr, GLint ng, GLint nb, GLint buffersize, FILE *stream, const char *filename)
#define GL2PS_DRAW_BACKGROUND
Definition: gl2ps.h:145
void setPointSize(int)
void setBufferSize(int)
bool disableFileWriting()
void setFileName(const char *)
GL2PSDLL_API GLint gl2psEndPage(void)
#define GL2PS_ERROR
Definition: gl2ps.h:137
#define GL2PS_USE_CURRENT_VIEWPORT
Definition: gl2ps.h:154
GL2PSDLL_API GLint gl2psPointSize(GLfloat value)
#define GL2PS_BSP_SORT
Definition: gl2ps.h:130
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
void setLineWidth(int)
bool enableFileWriting()
void setExportImageFormat(unsigned int)
void resetBufferSizeParameters()
#define GL2PS_BLEND
Definition: gl2ps.h:164
void setViewport(int, int, int, int)
#define GL2PS_PDF
Definition: gl2ps.h:122
const char * fFileName
T max(const T t1, const T t2)
brief Return the largest of the two arguments
bool fileWritingEnabled() const
GL2PSDLL_API GLint gl2psLineWidth(GLfloat value)
#define GL2PS_BEST_ROOT
Definition: gl2ps.h:148
#define GL2PS_OVERFLOW
Definition: gl2ps.h:139
GL2PSDLL_API GLint gl2psEnable(GLint mode)