Geant4  10.01.p01
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 86360 2014-11-10 08:34:16Z 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  void g4GluPickMatrix(GLdouble x, GLdouble y, GLdouble width, GLdouble height,
184  GLint viewport[4]);
185  // MESA implementation of gluPickMatrix
186 
187  void g4GluLookAt( GLdouble eyex, GLdouble eyey, GLdouble eyez,
188  GLdouble centerx, GLdouble centery, GLdouble
189  centerz,
190  GLdouble upx, GLdouble upy, GLdouble upz );
191  // MESA implementation of gluLookAt
192 
193  G4bool fPrintColour;
194  G4bool fVectoredPs;
195 
196  G4OpenGLSceneHandler& fOpenGLSceneHandler;
197  G4Colour background; //the OpenGL clear colour
198  G4bool
199  transparency_enabled, //is alpha blending enabled?
200  antialiasing_enabled, //is antialiasing enabled?
201  haloing_enabled; //is haloing enabled for wireframe?
202  G4double fStartTime, fEndTime; // Time range (e.g., for trajectory steps).
203  G4double fFadeFactor; // 0: no fade; 1: maximum fade with time within range.
204  G4bool fDisplayHeadTime; // Display head time (fEndTime) in 2D text.
205  G4double fDisplayHeadTimeX, fDisplayHeadTimeY; // 2D screen coords.
206  G4double fDisplayHeadTimeSize; // Screen size.
207  G4double fDisplayHeadTimeRed, fDisplayHeadTimeGreen, fDisplayHeadTimeBlue;
208  G4bool fDisplayLightFront;// Display light front at head time originating at
209  G4double fDisplayLightFrontX, fDisplayLightFrontY, fDisplayLightFrontZ,
210  fDisplayLightFrontT;
211  G4double fDisplayLightFrontRed, fDisplayLightFrontGreen, fDisplayLightFrontBlue;
212  G4OpenGL2PSAction* fGL2PSAction;
213 
214  G4double fRot_sens; // Rotation sensibility in degrees
215  G4double fPan_sens; // Translation sensibility
216  unsigned int fWinSize_x;
217  unsigned int fWinSize_y;
218  std::vector < std::string > fExportImageFormatVector;
219  std::string fDefaultExportImageFormat;
220  std::string fExportImageFormat;
221  int fExportFilenameIndex;
222  G4int fPrintSizeX;
223  G4int fPrintSizeY;
224 
225 
226 private :
227  G4float fPointSize;
228  G4String fExportFilename;
229  G4String fDefaultExportFilename;
230  G4bool fSizeHasChanged;
231  int fGl2psDefaultLineWith;
232  int fGl2psDefaultPointSize;
233  bool fGlViewInitialized;
234 
235  // size of the OpenGL frame
236  void rotateSceneThetaPhi(G4double dx, G4double dy);
237  void rotateSceneInViewDirection (G4double dx, G4double dy);
238  bool printGl2PS();
239  G4int getRealExportWidth();
240  G4int getRealExportHeight();
241  GLubyte* grabPixels (int inColor,
242  unsigned int width,
243  unsigned int height);
244  bool printNonVectoredEPS ();
245  // print non vectored EPS files
246 
247  bool printVectoredEPS();
248  // print vectored EPS files
249 
250  bool fIsGettingPickInfos;
251  // Block SetView() during picking
252 
253 #ifdef G4OPENGL_VERSION_2
254 public:
255 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
256  inline Wt::WGLWidget::Program getShaderProgram() {
257  return fShaderProgram;
258  }
259  inline Wt::WGLWidget::UniformLocation getShaderProjectionMatrix() {
260  return fpMatrixUniform;
261  }
262  inline Wt::WGLWidget::UniformLocation getShaderTransformMatrix() {
263  return ftMatrixUniform;
264  }
265 #else
266  inline GLuint getShaderProgram() {
267  return fShaderProgram;
268  }
269  inline GLuint getShaderProjectionMatrix() {
270  return fpMatrixUniform;
271  }
272  inline GLuint getShaderTransformMatrix() {
273  return ftMatrixUniform;
274  }
275  inline GLuint getShaderViewModelMatrix() {
276  return fmvMatrixUniform;
277  }
278 #endif
279 
280 protected :
281 
282  // define the keyword shader to handle it in a better way for OpenGL and WebGL
283 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
284 #define Shader Wt::WGLWidget::Shader
285 #else
286 #define Shader GLuint
287 #endif
288 
289  // define some attributes and variables for OpenGL and WebGL
290 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
291  Wt::WGLWidget::Program fShaderProgram;
292 
293  // Program and related variables
294  Wt::WGLWidget::AttribLocation fVertexPositionAttribute;
295  Wt::WGLWidget::AttribLocation fVertexNormalAttribute;
296  Wt::WGLWidget::UniformLocation fpMatrixUniform;
297  Wt::WGLWidget::UniformLocation fcMatrixUniform;
298  Wt::WGLWidget::UniformLocation fmvMatrixUniform;
299  Wt::WGLWidget::UniformLocation fnMatrixUniform;
300  Wt::WGLWidget::UniformLocation ftMatrixUniform;
301 #else
302  GLuint fShaderProgram;
303 
304  // Program and related variables
305  GLuint fVertexPositionAttribute;
306  GLuint fVertexNormalAttribute;
307  GLuint fpMatrixUniform;
308  GLuint fcMatrixUniform;
309  GLuint fmvMatrixUniform;
310  GLuint fnMatrixUniform;
311  GLuint ftMatrixUniform;
312 #endif
313 
314 #endif
315 };
316 
317 #endif
318 
319 #endif
Definition: G4Text.hh:73
virtual void SetView()=0
G4String fName
Definition: G4AttUtils.hh:55
virtual void ClearView()=0
G4String name
Definition: TRTMaterials.hh:40
float G4float
Definition: G4Types.hh:77
#define width
int G4int
Definition: G4Types.hh:78
virtual void ResetView()
bool G4bool
Definition: G4Types.hh:79
const G4int n
double G4double
Definition: G4Types.hh:76
void print(const std::vector< T > &data)
Definition: DicomRun.hh:109
G4bool isInitialized()
Check if the generator is initialized.
std::string getName(const ParticleType t)
Get the native INCL name of the particle.