Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4OpenGLViewer.hh
이 파일의 문서화 페이지로 가기
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 108131 2018-01-09 13:23:26Z 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  const 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  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
Float_t x
Definition: compare.C:6
const XML_Char * name
Definition: expat.h:151
void print(G4double elem)
Float_t y
Definition: compare.C:6
float G4float
Definition: G4Types.hh:77
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
#define width
Definition: G4Text.hh:73
virtual void ClearView()=0
G4String fName
Definition: G4AttUtils.hh:55
std::string getName(const ParticleType t)
Get the native INCL name of the particle.
int G4int
Definition: G4Types.hh:78
virtual void SetView()=0
Char_t n[5]
G4bool isInitialized()
virtual void ResetView()