Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 70646 2013-06-03 15:07:58Z 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 )
48 //////////////////////////////////////////////////////////////////////////////
49 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
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;
60 }
61 
62 //////////////////////////////////////////////////////////////////////////////
64 )
65 //////////////////////////////////////////////////////////////////////////////
66 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
67 {
68  fBufferSize = 2048;
69 }
70 
71 //////////////////////////////////////////////////////////////////////////////
73  int width
74 )
75 //////////////////////////////////////////////////////////////////////////////
76 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
77 {
78  gl2psLineWidth( width );
79 }
80 
81 //////////////////////////////////////////////////////////////////////////////
83  int size
84 )
85 //////////////////////////////////////////////////////////////////////////////
86 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
87 {
88  gl2psPointSize( size );
89 }
90 
91 //////////////////////////////////////////////////////////////////////////////
93 int a
94 ,int b
95 ,int winSizeX
96 ,int winSizeY
97 )
98 //////////////////////////////////////////////////////////////////////////////
99 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
100 {
101  fViewport[0] = a;
102  fViewport[1] = b;
103  fViewport[2] = winSizeX;
104  fViewport[3] = winSizeY;
105 }
106 
107 //////////////////////////////////////////////////////////////////////////////
109  const char* aFileName
110 )
111 //////////////////////////////////////////////////////////////////////////////
112 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
113 {
114  fFileName = (strncpy((char*)malloc((unsigned)strlen(aFileName) + 1), aFileName, (unsigned)strlen(aFileName) + 1));
115 }
116 //////////////////////////////////////////////////////////////////////////////
118 )
119 //////////////////////////////////////////////////////////////////////////////
120 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
121 {
122  fFile = ::fopen(fFileName,"wb");
123  if(!fFile) {
124  return false;
125  }
126 
127  // No buffering for output file
128  setvbuf ( fFile , NULL , _IONBF , 2048 );
129  return G4gl2psBegin();
130 }
131 //////////////////////////////////////////////////////////////////////////////
133 )
134 //////////////////////////////////////////////////////////////////////////////
135 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
136 {
137  int state = gl2psEndPage();
138  ::fclose(fFile);
139  if (state == GL2PS_OVERFLOW) {
140  return false;
141  }
142  fFile = 0;
143  return true;
144 }
145 //////////////////////////////////////////////////////////////////////////////
147 )
148 //////////////////////////////////////////////////////////////////////////////
149 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
150 {
151  // extend buffer size *2
152  if (fBufferSize < (fBufferSizeLimit/2)) {
154  return true;
155  }
156  return false;
157 }
158 //////////////////////////////////////////////////////////////////////////////
160 ) const
161 //////////////////////////////////////////////////////////////////////////////
162 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
163 {
164  return (fFile?true:false);
165 }
166 //////////////////////////////////////////////////////////////////////////////
168 )
169 //////////////////////////////////////////////////////////////////////////////
170 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
171 {
172  if(!fFile) return false;
173  int options = GL2PS_OCCLUSION_CULL |
175 // int options = GL2PS_OCCLUSION_CULL |
176 // GL2PS_BEST_ROOT | GL2PS_SILENT | GL2PS_DRAW_BACKGROUND;
177  int sort = GL2PS_BSP_SORT;
178  // int sort = GL2PS_SIMPLE_SORT;
179 
180  glGetIntegerv(GL_VIEWPORT,fViewport);
181 
182  GLint res = gl2psBeginPage("title","HEPVis::G4OpenGL2PSAction",
183  fViewport,
184  GL2PS_EPS,
185  sort,
186  options,
187  GL_RGBA,0, NULL,0,0,0,
188  fBufferSize,
189  fFile,fFileName);
190  if (res == GL2PS_ERROR) {
191  return false;
192  }
193  return true;
194 
195 }
196 
197 
198 
199 
200 #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
#define width
subroutine sort(A, N)
Definition: dpm25nuc7.f:4670
#define GL2PS_OCCLUSION_CULL
Definition: gl2ps.h:149
void setPointSize(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
void setLineWidth(int)
bool enableFileWriting()
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
GL2PSDLL_API GLint gl2psLineWidth(GLfloat value)
#define GL2PS_BEST_ROOT
Definition: gl2ps.h:148
void * malloc(size_t __size)
Definition: hjmalloc.cc:30
#define GL2PS_OVERFLOW
Definition: gl2ps.h:139
#define GL2PS_EPS
Definition: gl2ps.h:120