Geant4.10
 All Data Structures 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 75567 2013-11-04 11:35:11Z 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 
41 class G4OpenGLSceneHandler;
42 class G4OpenGL2PSAction;
43 class G4Text;
44 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
45 #include "G4OpenGLWtDrawer.hh"
46 #endif
47 
48 // Base class for various OpenGLView classes.
49 class G4OpenGLViewer: virtual public G4VViewer {
50 
51  friend class G4OpenGLSceneHandler;
52  friend class G4OpenGLImmediateSceneHandler;
53  friend class G4OpenGLStoredSceneHandler;
54  friend class G4OpenGLFileSceneHandler;
55  friend class G4OpenGLViewerMessenger;
56 
57 public:
58  void ClearView ();
59 //////////////////////////////Vectored PostScript production functions///
60  void printEPS();
61 
62  // Special case for Wt, we want to have acces to the drawer
63 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
64  inline G4OpenGLWtDrawer* getWtDrawer() {return fWtDrawer;}
65 
66  // Associate the Wt drawer to the OpenGLViewer and the OpenGLSceneHandler
67  void setWtDrawer(G4OpenGLWtDrawer* drawer);
68  G4OpenGLWtDrawer* fWtDrawer;
69 #endif
70 
71 protected:
72  G4OpenGLViewer (G4OpenGLSceneHandler& scene);
73  virtual ~G4OpenGLViewer ();
74 
75 private:
76  G4OpenGLViewer(const G4OpenGLViewer&);
77  G4OpenGLViewer& operator= (const G4OpenGLViewer&);
78 
79 protected:
80  void SetView ();
81  void ResetView ();
82 
83  virtual void DrawText(const G4Text&);
84  void ChangePointSize(G4double size);
85  void ChangeLineWidth(G4double width);
86  void HaloingFirstPass ();
87  void HaloingSecondPass ();
88  void HLRFirstPass ();
89  void HLRSecondPass ();
90  void HLRThirdPass ();
91  void InitializeGLView ();
92  void ResizeGLView();
93  void ResizeWindow(unsigned int, unsigned int);
94  void Pick(GLdouble x, GLdouble y);
95  virtual void CreateFontLists () {}
96  void rotateScene (G4double dx, G4double dy);
97  void rotateSceneToggle (G4double dx, G4double dy);
98 //////////////////////////////Vectored PostScript production functions///
99  // print EPS file. Depending of fVectoredPs, it will print Vectored or not
100  void setPrintSize(G4int,G4int);
101  // set the new print size.
102  // -1 means 'print size' = 'window size'
103  // Setting size greater than max OpenGL viewport size will set the size to
104  // maximum
105  void setPrintFilename(G4String name,G4bool inc);
106  // set print filename.
107  // if inc, then the filename will be increment by one each time
108  std::string getRealPrintFilename();
109  unsigned int getWinWidth() const;
110  unsigned int getWinHeight() const;
111  G4bool sizeHasChanged();
112  // return true if size has change since last redraw
113  GLdouble getSceneNearWidth();
114  GLdouble getSceneFarWidth();
115  GLdouble getSceneDepth();
116  G4bool isGl2psWriting();
117  G4bool fPrintColour;
118  G4bool fVectoredPs;
119 
120  G4OpenGLSceneHandler& fOpenGLSceneHandler;
121  G4Colour background; //the OpenGL clear colour
122  G4bool
123  transparency_enabled, //is alpha blending enabled?
124  antialiasing_enabled, //is antialiasing enabled?
125  haloing_enabled; //is haloing enabled for wireframe?
126  G4double fStartTime, fEndTime; // Time range (e.g., for trajectory steps).
127  G4double fFadeFactor; // 0: no fade; 1: maximum fade with time within range.
128  G4bool fDisplayHeadTime; // Display head time (fEndTime) in 2D text.
129  G4double fDisplayHeadTimeX, fDisplayHeadTimeY; // 2D screen coords.
130  G4double fDisplayHeadTimeSize; // Screen size.
131  G4double fDisplayHeadTimeRed, fDisplayHeadTimeGreen, fDisplayHeadTimeBlue;
132  G4bool fDisplayLightFront;// Display light front at head time originating at
133  G4double fDisplayLightFrontX, fDisplayLightFrontY, fDisplayLightFrontZ,
134  fDisplayLightFrontT;
135  G4double fDisplayLightFrontRed, fDisplayLightFrontGreen, fDisplayLightFrontBlue;
136  G4OpenGL2PSAction* fGL2PSAction;
137 
138  G4double fRot_sens; // Rotation sensibility in degrees
139  G4double fPan_sens; // Translation sensibility
140 
141 public :
142 #ifdef G4OPENGL_VERSION_2
143  // define the shaders for vertex and fragment in plain text format
144  std::string vertexShader_;
145  std::string fragmentShader_;
146 
147 
148  // define the keyword shader to handle it in a better way for OpenGL and WebGL
149 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
150  #define Shader Wt::WGLWidget::Shader
151 #else
152  #define Shader GLuint
153 #endif
154 
155  // define some attributes and variables for OpenGL and WebGL
156 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
157  Wt::WGLWidget::Program shaderProgram_;
158 
159  // Program and related variables
160  Wt::WGLWidget::AttribLocation vertexPositionAttribute_;
161  Wt::WGLWidget::AttribLocation vertexNormalAttribute_;
162  Wt::WGLWidget::UniformLocation pMatrixUniform_;
163  Wt::WGLWidget::UniformLocation cMatrixUniform_;
164  Wt::WGLWidget::UniformLocation mvMatrixUniform_;
165  Wt::WGLWidget::UniformLocation nMatrixUniform_;
166  Wt::WGLWidget::UniformLocation tMatrixUniform_;
167 #else
168  GLuint shaderProgram_;
169 
170  // Program and related variables
171  GLuint vertexPositionAttribute_;
172  GLuint vertexNormalAttribute_;
173  GLuint pMatrixUniform_;
174  GLuint cMatrixUniform_;
175  GLuint mvMatrixUniform_;
176  GLuint nMatrixUniform_;
177  GLuint tMatrixUniform_;
178 #endif
179 
180 #endif
181 
182 private :
183  static G4int fPrintSizeX;
184  static G4int fPrintSizeY;
185  static G4String fPrintFilename;
186  static int fPrintFilenameIndex;
187  unsigned int fWinSize_x, fWinSize_y;
188  G4float fPointSize;
189  G4bool fSizeHasChanged;
190  int fGl2psDefaultLineWith;
191  int fGl2psDefaultPointSize;
192 
193  // size of the OpenGL frame
194  void rotateSceneThetaPhi(G4double dx, G4double dy);
195  void rotateSceneInViewDirection (G4double dx, G4double dy);
196  bool printGl2PS();
197  G4int getRealPrintSizeX();
198  G4int getRealPrintSizeY();
199  GLubyte* grabPixels (int inColor,
200  unsigned int width,
201  unsigned int height);
202  bool printNonVectoredEPS ();
203  // print non vectored EPS files
204 
205  bool printVectoredEPS();
206  // print vectored EPS files
207 };
208 
209 #endif
210 
211 #endif
Definition: G4Text.hh:73
virtual void SetView()=0
virtual void ClearView()=0
float G4float
Definition: G4Types.hh:77
#define width
const XML_Char * name
int G4int
Definition: G4Types.hh:78
virtual void ResetView()
bool G4bool
Definition: G4Types.hh:79
double G4double
Definition: G4Types.hh:76