source: trunk/geant4/visualization/OpenGL/old-src/G4OpenGLViewer.cc@ 565

Last change on this file since 565 was 562, checked in by garnier, 18 years ago

r565@mac-90108: laurentgarnier | 2007-08-14 14:18:03 +0200
mise a jour suite au plantage de svk (cheksum error) suite au crash du DD en juin

  • Property svn:mime-type set to text/cpp
File size: 9.3 KB
Line 
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.cc,v 1.29 2006/09/19 16:13:15 allison Exp $
28// GEANT4 tag $Name: geant4-08-02-patch-01 $
29//
30//
31// Andrew Walkden 27th March 1996
32// OpenGL view - opens window, hard copy, etc.
33
34#ifdef G4VIS_BUILD_OPENGL_DRIVER
35
36#include "G4ios.hh"
37#include "G4OpenGLViewer.hh"
38#include "G4OpenGLSceneHandler.hh"
39#include "G4OpenGLTransform3D.hh"
40
41#include "G4Scene.hh"
42#include "G4VisExtent.hh"
43#include "G4LogicalVolume.hh"
44#include "G4VSolid.hh"
45#include "G4Point3D.hh"
46#include "G4Normal3D.hh"
47#include "G4Plane3D.hh"
48
49G4OpenGLViewer::G4OpenGLViewer (G4OpenGLSceneHandler& scene):
50G4VViewer (scene, -1),
51background (G4Colour(0.,0.,0.)),
52transparency_enabled (true),
53antialiasing_enabled (false),
54haloing_enabled (false),
55fStartTime(-DBL_MAX),
56fEndTime(DBL_MAX),
57fFadeFactor(0.),
58fDisplayHeadTime(false),
59fDisplayHeadTimeX(-0.9),
60fDisplayHeadTimeY(-0.9),
61fDisplayHeadTimeSize(24.),
62fDisplayHeadTimeRed(0.),
63fDisplayHeadTimeGreen(1.),
64fDisplayHeadTimeBlue(1.),
65fDisplayLightFront(false),
66fDisplayLightFrontX(0.),
67fDisplayLightFrontY(0.),
68fDisplayLightFrontZ(0.),
69fDisplayLightFrontT(0.),
70fDisplayLightFrontRed(0.),
71fDisplayLightFrontGreen(1.),
72fDisplayLightFrontBlue(0.)
73{
74 // Make changes to view parameters for OpenGL...
75 fVP.SetAutoRefresh(true);
76 fDefaultVP.SetAutoRefresh(true);
77
78 // glClearColor (0.0, 0.0, 0.0, 0.0);
79 // glClearDepth (1.0);
80 // glDisable (GL_BLEND);
81 // glDisable (GL_LINE_SMOOTH);
82 // glDisable (GL_POLYGON_SMOOTH);
83
84}
85
86G4OpenGLViewer::~G4OpenGLViewer () {}
87
88void G4OpenGLViewer::InitializeGLView ()
89{
90 printf("G4OpenGLViewer::InitializeGLView () VVVVVVVVVVVVVVVVVVVVV \n");
91 glClearColor (0.0, 0.0, 0.0, 0.0);
92 glClearDepth (1.0);
93 glDisable (GL_BLEND);
94 glDisable (GL_LINE_SMOOTH);
95 glDisable (GL_POLYGON_SMOOTH);
96 printf("G4OpenGLViewer::InitializeGLView () ^^^^^^^^^^^^^^^^^^^^ \n");
97}
98
99void G4OpenGLViewer::ClearView () {
100 glClearColor (background.GetRed(),
101 background.GetGreen(),
102 background.GetBlue(),
103 1.);
104 glClearDepth (1.0);
105 //Below line does not compile with Mesa includes.
106 //glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
107 glClear (GL_COLOR_BUFFER_BIT);
108 glClear (GL_DEPTH_BUFFER_BIT);
109 glClear (GL_STENCIL_BUFFER_BIT);
110 glFlush ();
111}
112
113void G4OpenGLViewer::SetView () {
114
115 // Calculates view representation based on extent of object being
116 // viewed and (initial) viewpoint. (Note: it can change later due
117 // to user interaction via visualization system's GUI.)
118
119 // Lighting.
120 GLfloat lightPosition [4];
121 lightPosition [0] = fVP.GetActualLightpointDirection().x();
122 lightPosition [1] = fVP.GetActualLightpointDirection().y();
123 lightPosition [2] = fVP.GetActualLightpointDirection().z();
124 lightPosition [3] = 0.;
125 // Light position is "true" light direction, so must come after gluLookAt.
126 GLfloat ambient [] = { 0.2, 0.2, 0.2, 1.};
127 GLfloat diffuse [] = { 0.8, 0.8, 0.8, 1.};
128 glEnable (GL_LIGHT0);
129 glLightfv (GL_LIGHT0, GL_AMBIENT, ambient);
130 glLightfv (GL_LIGHT0, GL_DIFFUSE, diffuse);
131
132 // Get radius of scene, etc.
133 // Note that this procedure properly takes into account zoom, dolly and pan.
134 const G4Point3D targetPoint
135 = fSceneHandler.GetScene()->GetStandardTargetPoint()
136 + fVP.GetCurrentTargetPoint ();
137 G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
138 if(radius<=0.) radius = 1.;
139 const G4double cameraDistance = fVP.GetCameraDistance (radius);
140 const G4Point3D cameraPosition =
141 targetPoint + cameraDistance * fVP.GetViewpointDirection().unit();
142 const GLdouble pnear = fVP.GetNearDistance (cameraDistance, radius);
143 const GLdouble pfar = fVP.GetFarDistance (cameraDistance, pnear, radius);
144 const GLdouble right = fVP.GetFrontHalfHeight (pnear, radius);
145 const GLdouble left = -right;
146 const GLdouble bottom = left;
147 const GLdouble top = right;
148
149 glMatrixMode (GL_PROJECTION); // set up Frustum.
150 glLoadIdentity();
151
152 const G4Vector3D scale = fVP.GetScaleFactor();
153 glScaled(scale.x(),scale.y(),scale.z());
154
155 if (fVP.GetFieldHalfAngle() == 0.) {
156 glOrtho (left, right, bottom, top, pnear, pfar);
157 }
158 else {
159 glFrustum (left, right, bottom, top, pnear, pfar);
160 }
161
162 glMatrixMode (GL_MODELVIEW); // apply further transformations to scene.
163 glLoadIdentity();
164
165 const G4Normal3D& upVector = fVP.GetUpVector ();
166 G4Point3D gltarget;
167 if (cameraDistance > 1.e-6 * radius) {
168 gltarget = targetPoint;
169 }
170 else {
171 gltarget = targetPoint - radius * fVP.GetViewpointDirection().unit();
172 }
173
174 const G4Point3D& pCamera = cameraPosition; // An alias for brevity.
175 gluLookAt (pCamera.x(), pCamera.y(), pCamera.z(), // Viewpoint.
176 gltarget.x(), gltarget.y(), gltarget.z(), // Target point.
177 upVector.x(), upVector.y(), upVector.z()); // Up vector.
178
179 // Light position is "true" light direction, so must come after gluLookAt.
180 glLightfv (GL_LIGHT0, GL_POSITION, lightPosition);
181
182 // OpenGL no longer seems to reconstruct clipped edges, so, when the
183 // BooleanProcessor is up to it, abandon this and use generic
184 // clipping in G4OpenGLSceneHandler::CreateSectionPolyhedron. Also,
185 // force kernel visit on change of clipping plane in
186 // G4OpenGLStoredViewer::CompareForKernelVisit.
187 if (fVP.IsSection () ) { // pair of back to back clip planes.
188 const G4Plane3D& s = fVP.GetSectionPlane ();
189 double sArray[4];
190 sArray[0] = s.a();
191 sArray[1] = s.b();
192 sArray[2] = s.c();
193 sArray[3] = s.d() + radius * 1.e-05;
194 glClipPlane (GL_CLIP_PLANE0, sArray);
195 glEnable (GL_CLIP_PLANE0);
196 sArray[0] = -s.a();
197 sArray[1] = -s.b();
198 sArray[2] = -s.c();
199 sArray[3] = -s.d() + radius * 1.e-05;
200 glClipPlane (GL_CLIP_PLANE1, sArray);
201 glEnable (GL_CLIP_PLANE1);
202 } else {
203 glDisable (GL_CLIP_PLANE0);
204 glDisable (GL_CLIP_PLANE1);
205 }
206
207 const G4Planes& cutaways = fVP.GetCutawayPlanes();
208 size_t nPlanes = cutaways.size();
209 if (fVP.IsCutaway() &&
210 fVP.GetCutawayMode() == G4ViewParameters::cutawayIntersection &&
211 nPlanes > 0) {
212 double a[4];
213 a[0] = cutaways[0].a();
214 a[1] = cutaways[0].b();
215 a[2] = cutaways[0].c();
216 a[3] = cutaways[0].d();
217 glClipPlane (GL_CLIP_PLANE2, a);
218 glEnable (GL_CLIP_PLANE2);
219 if (nPlanes > 1) {
220 a[0] = cutaways[1].a();
221 a[1] = cutaways[1].b();
222 a[2] = cutaways[1].c();
223 a[3] = cutaways[1].d();
224 glClipPlane (GL_CLIP_PLANE3, a);
225 glEnable (GL_CLIP_PLANE3);
226 }
227 if (nPlanes > 2) {
228 a[0] = cutaways[2].a();
229 a[1] = cutaways[2].b();
230 a[2] = cutaways[2].c();
231 a[3] = cutaways[2].d();
232 glClipPlane (GL_CLIP_PLANE4, a);
233 glEnable (GL_CLIP_PLANE4);
234 }
235 } else {
236 glDisable (GL_CLIP_PLANE2);
237 glDisable (GL_CLIP_PLANE3);
238 glDisable (GL_CLIP_PLANE4);
239 }
240
241 // Background.
242 background = fVP.GetBackgroundColour ();
243
244}
245
246void G4OpenGLViewer::HaloingFirstPass () {
247
248 //To perform haloing, first Draw all information to the depth buffer
249 //alone, using a chunky line width, and then Draw all info again, to
250 //the colour buffer, setting a thinner line width an the depth testing
251 //function to less than or equal, so if two lines cross, the one
252 //passing behind the other will not pass the depth test, and so not
253 //get rendered either side of the infront line for a short distance.
254
255 //First, disable writing to the colo(u)r buffer...
256 glColorMask (GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
257
258 //Now enable writing to the depth buffer...
259 glDepthMask (GL_TRUE);
260 glDepthFunc (GL_LESS);
261 glClearDepth (1.0);
262
263 //Finally, set the line width to something wide...
264 glLineWidth (3.0);
265
266}
267
268void G4OpenGLViewer::HaloingSecondPass () {
269
270 //And finally, turn the colour buffer back on with a sesible line width...
271 glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
272 glDepthFunc (GL_LEQUAL);
273 glLineWidth (1.0);
274
275}
276
277#endif
Note: See TracBrowser for help on using the repository browser.