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