Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4OpenGLViewer.hh
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// Andrew Walkden 27th March 1996
30// OpenGL viewer - opens window, hard copy, etc.
31
32#if defined (G4VIS_BUILD_OPENGL_DRIVER) || defined (G4VIS_USE_OPENGL)
33
34#ifndef G4OPENGLVIEWER_HH
35#define G4OPENGLVIEWER_HH
36
37#include "G4VViewer.hh"
38#include "G4OpenGL.hh"
39#ifdef G4OPENGL_VERSION_2
40#include "G4OpenGLVboDrawer.hh"
41#endif
42
43class G4OpenGLSceneHandler;
45class G4Text;
46
47class G4OpenGLViewerPickMap {
48 public :
49 inline void setName(G4String n) {
50 fName = n;
51 }
52
53 inline void setHitNumber(G4int n) {
54 fHitNumber = n;
55 }
56
57 inline void setSubHitNumber(G4int n) {
58 fSubHitNumber = n;
59 }
60 inline void setPickName(G4int n) {
61 fPickName= n;
62 }
63
64 inline void addAttributes(G4String att) {
65 fAttributes.push_back(att);
66 }
67
68
69 inline G4String getName() {
70 return fName;
71 }
72 inline G4int getHitNumber() {
73 return fHitNumber;
74 }
75
76 inline G4int getSubHitNumber() {
77 return fSubHitNumber;
78 }
79
80 inline G4int getPickName() {
81 return fPickName;
82 }
83
84 inline std::vector <G4String > getAttributes() {
85 return fAttributes;
86 }
87
89
90 private :
91 G4String fName;
92 G4int fHitNumber;
93 G4int fSubHitNumber;
94 G4int fPickName;
95 std::vector <G4String > fAttributes;
96
97};
98
99// Base class for various OpenGLView classes.
100class G4OpenGLViewer: virtual public G4VViewer {
101
102 friend class G4OpenGLSceneHandler;
103 friend class G4OpenGLImmediateSceneHandler;
104 friend class G4OpenGLStoredSceneHandler;
105 friend class G4OpenGLFileSceneHandler;
106 friend class G4OpenGLViewerMessenger;
107
108public:
109 void ClearView ();
110 void ClearViewWithoutFlush ();
111//////////////////////////////Vectored PostScript production functions///
112 bool printEPS();
113 virtual bool exportImage(std::string name="", int width=-1, int height=-1);
114
115 bool setExportImageFormat(std::string format,bool quiet = false);
116 // change the export image format according to thoses available for the current viewer
117
118 // Special case for Wt, we want to have acces to the drawer
119#ifdef G4OPENGL_VERSION_2
120 inline G4OpenGLVboDrawer* getWtDrawer() {return fVboDrawer;}
121
122 // Associate the Wt drawer to the OpenGLViewer and the OpenGLSceneHandler
123 void setVboDrawer(G4OpenGLVboDrawer* drawer);
124 G4OpenGLVboDrawer* fVboDrawer;
125
126 inline bool isInitialized() {
127 return fGlViewInitialized;
128 }
129#endif
130
131protected:
132 G4OpenGLViewer (G4OpenGLSceneHandler& scene);
133 virtual ~G4OpenGLViewer ();
134
135private:
136 G4OpenGLViewer(const G4OpenGLViewer&);
137 G4OpenGLViewer& operator= (const G4OpenGLViewer&);
138
139protected:
140 void SetView ();
141 void ResetView ();
142
143 virtual void DrawText(const G4Text&);
144 void ChangePointSize(G4double size);
145 void ChangeLineWidth(G4double width);
146 void HaloingFirstPass ();
147 void HaloingSecondPass ();
148 void HLRFirstPass ();
149 void HLRSecondPass ();
150 void HLRThirdPass ();
151 void InitializeGLView ();
152 void ResizeGLView();
153 void ResizeWindow(unsigned int, unsigned int);
154 virtual G4String Pick(GLdouble x, GLdouble y);
155 const std::vector < G4OpenGLViewerPickMap* > & GetPickDetails(GLdouble x, GLdouble y);
156 virtual void CreateFontLists () {}
157 void rotateScene (G4double dx, G4double dy);
158 void rotateSceneToggle (G4double dx, G4double dy);
159//////////////////////////////Vectored PostScript production functions///
160 // print EPS file. Depending of fVectoredPs, it will print Vectored or not
161 void setExportSize(G4int,G4int);
162 // set the new print size.
163 // -1 means 'print size' = 'window size'
164 // Setting size greater than max OpenGL viewport size will set the size to
165 // maximum
166 bool setExportFilename(G4String name,G4bool inc = true);
167 // set export filename.
168 // if inc, then the filename will be increment by one each time
169 // try to guesss the correct format according to the extention
170
171 std::string getRealPrintFilename();
172 unsigned int getWinWidth() const;
173 unsigned int getWinHeight() const;
174 G4bool sizeHasChanged();
175 // return true if size has change since last redraw
176 GLdouble getSceneNearWidth();
177 GLdouble getSceneFarWidth();
178 GLdouble getSceneDepth();
179 void addExportImageFormat(std::string format);
180 // add a image format to the available export format list
181 G4bool isGl2psWriting();
182 G4bool isFramebufferReady();
183
184 void g4GluPickMatrix(GLdouble x, GLdouble y, GLdouble width, GLdouble height,
185 GLint viewport[4]);
186 // MESA implementation of gluPickMatrix
187
188 void g4GluLookAt( GLdouble eyex, GLdouble eyey, GLdouble eyez,
189 GLdouble centerx, GLdouble centery, GLdouble
190 centerz,
191 GLdouble upx, GLdouble upy, GLdouble upz );
192 // MESA implementation of gluLookAt
193 void g4GlOrtho (GLdouble left, GLdouble right,
194 GLdouble bottom, GLdouble top,
195 GLdouble near, GLdouble far);
196 // Redefinition on glOrtho to solve precision issues
197 void g4GlFrustum (GLdouble left, GLdouble right,
198 GLdouble bottom, GLdouble top,
199 GLdouble near, GLdouble far);
200 // Redefinition on glFrustum to solve precision issues
201
202 G4bool fPrintColour;
203 G4bool fVectoredPs;
204
205 G4OpenGLSceneHandler& fOpenGLSceneHandler;
206 G4Colour background; //the OpenGL clear colour
207 G4bool
208 transparency_enabled, //is alpha blending enabled?
209 antialiasing_enabled, //is antialiasing enabled?
210 haloing_enabled; //is haloing enabled for wireframe?
211 G4OpenGL2PSAction* fGL2PSAction;
212
213 G4double fRot_sens; // Rotation sensibility in degrees
214 G4double fPan_sens; // Translation sensibility
215 unsigned int fWinSize_x;
216 unsigned int fWinSize_y;
217 std::vector < std::string > fExportImageFormatVector;
218 std::string fDefaultExportImageFormat;
219 std::string fExportImageFormat;
220 int fExportFilenameIndex;
221 G4int fPrintSizeX;
222 G4int fPrintSizeY;
223
224
225private :
226 G4float fPointSize;
227 G4String fExportFilename;
228 G4String fDefaultExportFilename;
229 G4bool fSizeHasChanged;
230 int fGl2psDefaultLineWith;
231 int fGl2psDefaultPointSize;
232 bool fGlViewInitialized;
233
234 // size of the OpenGL frame
235 void rotateSceneThetaPhi(G4double dx, G4double dy);
236 void rotateSceneInViewDirection (G4double dx, G4double dy);
237 bool printGl2PS();
238 G4int getRealExportWidth();
239 G4int getRealExportHeight();
240 GLubyte* grabPixels (int inColor,
241 unsigned int width,
242 unsigned int height);
243 bool printNonVectoredEPS ();
244 // print non vectored EPS files
245
246 bool printVectoredEPS();
247 // print vectored EPS files
248
249 bool fIsGettingPickInfos;
250 // Block SetView() during picking
251
252#ifdef G4OPENGL_VERSION_2
253public:
254#if defined (G4VIS_BUILD_OPENGLWT_DRIVER) || defined (G4VIS_USE_OPENGLWT)
255 inline Wt::WGLWidget::Program getShaderProgram() {
256 return fShaderProgram;
257 }
258 inline Wt::WGLWidget::UniformLocation getShaderProjectionMatrix() {
259 return fpMatrixUniform;
260 }
261 inline Wt::WGLWidget::UniformLocation getShaderTransformMatrix() {
262 return ftMatrixUniform;
263 }
264#else
265 inline GLuint getShaderProgram() {
266 return fShaderProgram;
267 }
268 inline GLuint getShaderProjectionMatrix() {
269 return fpMatrixUniform;
270 }
271 inline GLuint getShaderTransformMatrix() {
272 return ftMatrixUniform;
273 }
274 inline GLuint getShaderViewModelMatrix() {
275 return fmvMatrixUniform;
276 }
277#endif // G4VIS_BUILD_OPENGLWT_DRIVER
278
279protected :
280
281 // define the keyword shader to handle it in a better way for OpenGL and WebGL
282#if defined (G4VIS_BUILD_OPENGLWT_DRIVER) || defined (G4VIS_USE_OPENGLWT)
283#define Shader Wt::WGLWidget::Shader
284#else
285#define Shader GLuint
286#endif // G4VIS_BUILD_OPENGLWT_DRIVER
287
288 // define some attributes and variables for OpenGL and WebGL
289#if defined (G4VIS_BUILD_OPENGLWT_DRIVER) || defined (G4VIS_USE_OPENGLWT)
290 Wt::WGLWidget::Program fShaderProgram;
291
292 // Program and related variables
293 Wt::WGLWidget::AttribLocation fVertexPositionAttribute;
294 Wt::WGLWidget::AttribLocation fVertexNormalAttribute;
295 Wt::WGLWidget::UniformLocation fpMatrixUniform;
296 Wt::WGLWidget::UniformLocation fcMatrixUniform;
297 Wt::WGLWidget::UniformLocation fmvMatrixUniform;
298 Wt::WGLWidget::UniformLocation fnMatrixUniform;
299 Wt::WGLWidget::UniformLocation ftMatrixUniform;
300#else
301 GLuint fShaderProgram;
302
303 // Program and related variables
304 GLuint fVertexPositionAttribute;
305 GLuint fVertexNormalAttribute;
306 GLuint fpMatrixUniform;
307 GLuint fcMatrixUniform;
308 GLuint fmvMatrixUniform;
309 GLuint fnMatrixUniform;
310 GLuint ftMatrixUniform;
311#endif // G4VIS_BUILD_OPENGLWT_DRIVER
312
313#endif
314};
315
316#endif
317
318#endif
float G4float
Definition: G4Types.hh:84
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
void print(G4double elem)
Definition: G4Text.hh:72
virtual void ClearView()=0
std::string getName(const ParticleType t)
Get the native INCL name of the particle.
G4bool isInitialized()