Geant4 11.1.1
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#ifndef G4OPENGLVIEWER_HH
33#define G4OPENGLVIEWER_HH
34
35#include "G4VViewer.hh"
36#include "G4OpenGL.hh"
37#ifdef G4OPENGL_VERSION_2
38#include "G4OpenGLVboDrawer.hh"
39#endif
40
42class G4gl2ps;
43class G4Text;
44
46 public :
47 inline void setName(G4String n) {
48 fName = n;
49 }
50
51 inline void setHitNumber(G4int n) {
52 fHitNumber = n;
53 }
54
55 inline void setSubHitNumber(G4int n) {
56 fSubHitNumber = n;
57 }
58 inline void setPickName(G4int n) {
59 fPickName= n;
60 }
61
62 inline void addAttributes(G4String att) {
63 fAttributes.push_back(att);
64 }
65
66
67 inline G4String getName() {
68 return fName;
69 }
71 return fHitNumber;
72 }
73
75 return fSubHitNumber;
76 }
77
78 inline G4int getPickName() {
79 return fPickName;
80 }
81
82 inline std::vector <G4String > getAttributes() {
83 return fAttributes;
84 }
85
87
88 private :
89 G4String fName;
90 G4int fHitNumber;
91 G4int fSubHitNumber;
92 G4int fPickName;
93 std::vector <G4String > fAttributes;
94
95};
96
97// Base class for various OpenGLView classes.
98class G4OpenGLViewer: virtual public G4VViewer {
99
105
106public:
107 void ClearView ();
108 void ClearViewWithoutFlush ();
109
110 virtual bool exportImage(std::string name="", int width=-1, int height=-1);
111 bool setExportImageFormat(std::string format,bool quiet = false);
112
113#ifdef G4OPENGL_VERSION_2
114
115 void setVboDrawer(G4OpenGLVboDrawer* drawer);
116 G4OpenGLVboDrawer* fVboDrawer;
117
118 inline bool isInitialized() {
119 return fGlViewInitialized;
120 }
121#endif
122
123protected:
125 virtual ~G4OpenGLViewer ();
126
127private:
129 G4OpenGLViewer& operator= (const G4OpenGLViewer&);
130
131protected:
132 void SetView ();
133 void ResetView ();
134
135 virtual void DrawText(const G4Text&);
136 void ChangePointSize(G4double size);
137 void ChangeLineWidth(G4double width);
138 void HaloingFirstPass ();
139 void HaloingSecondPass ();
143 void InitializeGLView ();
144 void ResizeGLView();
145 void ResizeWindow(unsigned int, unsigned int);
146 virtual G4String Pick(GLdouble x, GLdouble y);
147 const std::vector < G4OpenGLViewerPickMap* > & GetPickDetails(GLdouble x, GLdouble y);
148 virtual void CreateFontLists () {}
149 void rotateScene (G4double dx, G4double dy);
150 void rotateSceneToggle (G4double dx, G4double dy);
151//////////////////////////////Vectored PostScript production functions///
152 // print EPS file. Depending of fVectoredPs, it will print Vectored or not
154 // set the new print size.
155 // -1 means 'print size' = 'window size'
156 // Setting size greater than max OpenGL viewport size will set the size to
157 // maximum
158 bool setExportFilename(G4String name,G4bool inc = true);
159 // set export filename.
160 // if inc, then the filename will be increment by one each time
161 // try to guesss the correct format according to the extention
162
163 std::string getRealPrintFilename();
164 unsigned int getWinWidth() const;
165 unsigned int getWinHeight() const;
167 // return true if size has change since last redraw
168 GLdouble getSceneNearWidth();
169 GLdouble getSceneFarWidth();
170 GLdouble getSceneDepth();
171 void addExportImageFormat(std::string format);
172 // add a image format to the available export format list
175
176 void g4GluPickMatrix(GLdouble x, GLdouble y, GLdouble width, GLdouble height,
177 GLint viewport[4]);
178 // MESA implementation of gluPickMatrix
179
180 void g4GluLookAt( GLdouble eyex, GLdouble eyey, GLdouble eyez,
181 GLdouble centerx, GLdouble centery, GLdouble
182 centerz,
183 GLdouble upx, GLdouble upy, GLdouble upz );
184 // MESA implementation of gluLookAt
185 void g4GlOrtho (GLdouble left, GLdouble right,
186 GLdouble bottom, GLdouble top,
187 GLdouble near, GLdouble far);
188 // Redefinition on glOrtho to solve precision issues
189 void g4GlFrustum (GLdouble left, GLdouble right,
190 GLdouble bottom, GLdouble top,
191 GLdouble near, GLdouble far);
192 // Redefinition on glFrustum to solve precision issues
193
196
198 G4Colour background; //the OpenGL clear colour
199 G4bool
200 transparency_enabled, //is alpha blending enabled?
201 antialiasing_enabled, //is antialiasing enabled?
202 haloing_enabled; //is haloing enabled for wireframe?
204
205 G4double fRot_sens; // Rotation sensibility in degrees
206 G4double fPan_sens; // Translation sensibility
207 unsigned int fWinSize_x;
208 unsigned int fWinSize_y;
209 std::vector < std::string > fExportImageFormatVector;
215
216
217private :
218 G4float fPointSize;
219 G4String fExportFilename;
220 G4String fDefaultExportFilename;
221 G4bool fSizeHasChanged;
222 int fGl2psDefaultLineWith;
223 int fGl2psDefaultPointSize;
224 bool fGlViewInitialized;
225
226 // size of the OpenGL frame
227 void rotateSceneThetaPhi(G4double dx, G4double dy);
228 void rotateSceneInViewDirection (G4double dx, G4double dy);
229 bool printGl2PS();
230 G4int getRealExportWidth();
231 G4int getRealExportHeight();
232 GLubyte* grabPixels (int inColor,
233 unsigned int width,
234 unsigned int height);
235 bool printNonVectoredEPS ();
236 // print non vectored EPS files
237
238 bool printVectoredEPS();
239 // print vectored EPS files
240
241 bool fIsGettingPickInfos;
242 // Block SetView() during picking
243
244#ifdef G4OPENGL_VERSION_2
245public:
246 inline GLuint getShaderProgram() {
247 return fShaderProgram;
248 }
249 inline GLuint getShaderProjectionMatrix() {
250 return fpMatrixUniform;
251 }
252 inline GLuint getShaderTransformMatrix() {
253 return ftMatrixUniform;
254 }
255 inline GLuint getShaderViewModelMatrix() {
256 return fmvMatrixUniform;
257 }
258
259protected :
260
261 // define the keyword shader to handle it in a better way for OpenGL and WebGL
262#define Shader GLuint
263
264 // define some attributes and variables for OpenGL and WebGL
265 GLuint fShaderProgram;
266
267 // Program and related variables
268 GLuint fVertexPositionAttribute;
269 GLuint fVertexNormalAttribute;
270 GLuint fpMatrixUniform;
271 GLuint fcMatrixUniform;
272 GLuint fmvMatrixUniform;
273 GLuint fnMatrixUniform;
274 GLuint ftMatrixUniform;
275
276#endif
277};
278
279#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 setSubHitNumber(G4int n)
void setName(G4String n)
std::vector< G4String > getAttributes()
void setHitNumber(G4int n)
void addAttributes(G4String att)
void setPickName(G4int n)
unsigned int fWinSize_y
void g4GluPickMatrix(GLdouble x, GLdouble y, GLdouble width, GLdouble height, GLint viewport[4])
void g4GlFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far)
std::vector< std::string > fExportImageFormatVector
void g4GluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx, GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy, GLdouble upz)
void rotateSceneToggle(G4double dx, G4double dy)
virtual void CreateFontLists()
bool setExportImageFormat(std::string format, bool quiet=false)
unsigned int getWinHeight() const
std::string fExportImageFormat
void HLRThirdPass()
void ClearViewWithoutFlush()
void ResizeWindow(unsigned int, unsigned int)
unsigned int getWinWidth() const
std::string fDefaultExportImageFormat
bool setExportFilename(G4String name, G4bool inc=true)
void addExportImageFormat(std::string format)
G4bool antialiasing_enabled
void ChangeLineWidth(G4double width)
virtual void DrawText(const G4Text &)
GLdouble getSceneFarWidth()
void setExportSize(G4int, G4int)
virtual G4String Pick(GLdouble x, GLdouble y)
void rotateScene(G4double dx, G4double dy)
void ChangePointSize(G4double size)
GLdouble getSceneDepth()
G4bool isFramebufferReady()
G4bool transparency_enabled
virtual bool exportImage(std::string name="", int width=-1, int height=-1)
void g4GlOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far)
G4gl2ps * fGL2PSAction
G4bool isGl2psWriting()
G4bool sizeHasChanged()
G4OpenGLSceneHandler & fOpenGLSceneHandler
virtual ~G4OpenGLViewer()
unsigned int fWinSize_x
void HLRFirstPass()
friend class G4OpenGLFileSceneHandler
void HaloingSecondPass()
std::string getRealPrintFilename()
void HLRSecondPass()
GLdouble getSceneNearWidth()
const std::vector< G4OpenGLViewerPickMap * > & GetPickDetails(GLdouble x, GLdouble y)
Definition: G4Text.hh:72