Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4gl2ps.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//
28//
29
30#include "G4gl2ps.hh"
31
32#include <tools/gl2ps>
33
34#include <limits>
35#include <cstdlib>
36#include <cstring>
37
39 fContext = 0;
40 fOpenGLFuncs.m_glIsEnabled = tools_dummy_glIsEnabled;
41 fOpenGLFuncs.m_glBegin = tools_dummy_glBegin;
42 fOpenGLFuncs.m_glEnd = tools_dummy_glEnd;
43 fOpenGLFuncs.m_glGetFloatv = tools_dummy_glGetFloatv;
44 fOpenGLFuncs.m_glVertex3f = tools_dummy_glVertex3f;
45 fOpenGLFuncs.m_glGetBooleanv = tools_dummy_glGetBooleanv;
46 fOpenGLFuncs.m_glGetIntegerv = tools_dummy_glGetIntegerv;
47 fOpenGLFuncs.m_glRenderMode = tools_dummy_glRenderMode;
48 fOpenGLFuncs.m_glFeedbackBuffer = tools_dummy_glFeedbackBuffer;
49 fOpenGLFuncs.m_glPassThrough = tools_dummy_glPassThrough;
50
51 fFile = 0;
52 fViewport[0] = 0;
53 fViewport[1] = 0;
54 fViewport[2] = 0;
55 fViewport[3] = 0;
56 fBufferSize = 2048;
57 fBufferSizeLimit = (std::numeric_limits<int>::max)();
58 fExportImageFormat = TOOLS_GL2PS_PDF;
60}
61
63 if(fFile) {
64 ::fclose(fFile);
65 fFile = 0;
66 }
67 if(fContext) {
68 ::tools_gl2psDeleteContext(fContext);
69 fContext = 0;
70 }
71}
72
76 fOpenGLFuncs.m_glEnd = a_funcs->m_glEnd;
84}
85
87 fBufferSize = 2048;
88}
89
90void G4gl2ps::setLineWidth(int width) {
91 if(!fContext) return;
92 ::tools_gl2psLineWidth(fContext, width );
93}
94
95void G4gl2ps::setPointSize(int size) {
96 if(!fContext) return;
97 ::tools_gl2psPointSize(fContext, size );
98}
99
100void G4gl2ps::addTextOpt(const char *str, const char *fontname,
101 tools_GLshort fontsize, tools_GLint alignment,
102 tools_GLfloat angle) {
103 if(!fContext) return;
104 ::tools_gl2psTextOpt(fContext,str,fontname,fontsize,alignment,angle);
105}
106
107void G4gl2ps::setViewport(int a,int b,int winSizeX,int winSizeY) {
108 fViewport[0] = a;
109 fViewport[1] = b;
110 fViewport[2] = winSizeX;
111 fViewport[3] = winSizeY;
112}
113
114void G4gl2ps::setFileName(const char* aFileName) {
115 fFileName = aFileName;
116}
117
119 if(fFile) {
120 ::fclose(fFile);
121 fFile = 0;
122 }
123 if(fContext) {
124 ::tools_gl2psDeleteContext(fContext);
125 fContext = 0;
126 }
127
128 fContext = ::tools_gl2psCreateContext();
129 if(!fContext) return false;
130
131 ::tools_gl2ps_set_gl_funcs(fContext,&fOpenGLFuncs);
132
133 fFile = ::fopen(fFileName,"wb");
134 if(!fFile) {
135 ::tools_gl2psDeleteContext(fContext);
136 fContext = 0;
137 return false;
138 }
139
140 // No buffering for output file
141 setvbuf ( fFile , NULL , _IONBF , 2048 );
142
143 return true;
144}
145
147 if(fFile) {
148 ::fclose(fFile);
149 fFile = 0;
150 }
151 if(fContext) {
152 ::tools_gl2psDeleteContext(fContext);
153 fContext = 0;
154 }
155}
156
158 return (fContext && fFile?true:false);
159}
160
162 // extend buffer size *2
163 if (fBufferSize < (fBufferSizeLimit/2)) {
165 return true;
166 }
167 return false;
168}
169
170
171// FWJ
172void G4gl2ps::setBufferSize(int newSize)
173{
174 fBufferSize = (newSize < int(fBufferSizeLimit)) ? newSize : fBufferSizeLimit;
175}
176
177
179 if(!fContext) return false;
180 if(!fFile) return false;
181
182 if( (fViewport[2]<=0) || (fViewport[3]<=0) ) return false;
183
184 int options =
188 int sort = TOOLS_GL2PS_BSP_SORT;
189
190 tools_GLint res = ::tools_gl2psBeginPage(fContext,"Geant4 output","Geant4",
191 fViewport,
192 fExportImageFormat,
193 sort,
194 options,
195 TOOLS_GL_RGBA,0, NULL,0,0,0,
197 fFile,fFileName.c_str());
198 if (res == TOOLS_GL2PS_ERROR) return false;
199
200 // enable blending for all
201 ::tools_gl2psEnable(fContext,TOOLS_GL2PS_BLEND);
202
203 return true;
204}
205
207 int _status = 0;
208 if(fContext) {
209 _status = ::tools_gl2psEndPage(fContext);
210 }
211 if (_status == TOOLS_GL2PS_OVERFLOW) return false;
212 return true;
213}
214
215void G4gl2ps::setExportImageFormat(unsigned int type){
216 if(fFile) return;
217 fExportImageFormat = type;
218}
219
void setOpenGLFunctions(tools_gl2ps_gl_funcs_t *)
Definition: G4gl2ps.cc:73
void disableFileWriting()
Definition: G4gl2ps.cc:146
void setPointSize(int)
Definition: G4gl2ps.cc:95
int fViewport[4]
Definition: G4gl2ps.hh:74
tools_GL2PScontextPointer fContext
Definition: G4gl2ps.hh:71
G4String fFileName
Definition: G4gl2ps.hh:73
bool fileWritingEnabled() const
Definition: G4gl2ps.cc:157
void setBufferSize(int)
Definition: G4gl2ps.cc:172
G4gl2ps()
Definition: G4gl2ps.cc:38
bool extendBufferSize()
Definition: G4gl2ps.cc:161
void resetBufferSizeParameters()
Definition: G4gl2ps.cc:86
void setFileName(const char *)
Definition: G4gl2ps.cc:114
void setExportImageFormat(unsigned int)
Definition: G4gl2ps.cc:215
int fBufferSize
Definition: G4gl2ps.hh:75
void addTextOpt(const char *, const char *, tools_GLshort, tools_GLint, tools_GLfloat)
Definition: G4gl2ps.cc:100
void setLineWidth(int)
Definition: G4gl2ps.cc:90
FILE * fFile
Definition: G4gl2ps.hh:72
bool beginPage()
Definition: G4gl2ps.cc:178
tools_gl2ps_gl_funcs_t fOpenGLFuncs
Definition: G4gl2ps.hh:70
void setViewport(int, int, int, int)
Definition: G4gl2ps.cc:107
~G4gl2ps()
Definition: G4gl2ps.cc:62
int fBufferSizeLimit
Definition: G4gl2ps.hh:76
bool enableFileWriting()
Definition: G4gl2ps.cc:118
bool endPage()
Definition: G4gl2ps.cc:206
#define TOOLS_GL2PS_USE_CURRENT_VIEWPORT
Definition: gl2ps_def.h:69
#define TOOLS_GL2PS_ERROR
Definition: gl2ps_def.h:52
short tools_GLshort
Definition: gl2ps_def.h:11
float tools_GLfloat
Definition: gl2ps_def.h:9
#define TOOLS_GL2PS_BEST_ROOT
Definition: gl2ps_def.h:63
#define TOOLS_GL2PS_BSP_SORT
Definition: gl2ps_def.h:45
int tools_GLint
Definition: gl2ps_def.h:7
#define TOOLS_GL_RGBA
Definition: gl2ps_def.h:145
#define TOOLS_GL2PS_BLEND
Definition: gl2ps_def.h:82
#define TOOLS_GL2PS_PDF
Definition: gl2ps_def.h:37
#define TOOLS_GL2PS_OVERFLOW
Definition: gl2ps_def.h:54
#define TOOLS_GL2PS_DRAW_BACKGROUND
Definition: gl2ps_def.h:60
tools_glPassThrough_func m_glPassThrough
Definition: gl2ps_def.h:209
tools_glIsEnabled_func m_glIsEnabled
Definition: gl2ps_def.h:200
tools_glRenderMode_func m_glRenderMode
Definition: gl2ps_def.h:207
tools_glGetIntegerv_func m_glGetIntegerv
Definition: gl2ps_def.h:206
tools_glGetFloatv_func m_glGetFloatv
Definition: gl2ps_def.h:203
tools_glEnd_func m_glEnd
Definition: gl2ps_def.h:202
tools_glBegin_func m_glBegin
Definition: gl2ps_def.h:201
tools_glGetBooleanv_func m_glGetBooleanv
Definition: gl2ps_def.h:205
tools_glVertex3f_func m_glVertex3f
Definition: gl2ps_def.h:204
tools_glFeedbackBuffer_func m_glFeedbackBuffer
Definition: gl2ps_def.h:208