source: trunk/source/visualization/OpenGL/src/G4OpenGLStoredViewer.cc@ 1115

Last change on this file since 1115 was 1107, checked in by garnier, 16 years ago

modif mineure

  • Property svn:mime-type set to text/cpp
File size: 10.1 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: G4OpenGLStoredViewer.cc,v 1.26 2009/04/08 16:55:44 lgarnier Exp $
28// GEANT4 tag $Name: $
29//
30//
31// Andrew Walkden 7th February 1997
32// Class G4OpenGLStoredViewer : Encapsulates the `storedness' of
33// an OpenGL view, for inheritance by
34// derived (X, Xm...) classes.
35
36#ifdef G4VIS_BUILD_OPENGL_DRIVER
37
38#include "G4OpenGLStoredViewer.hh"
39
40#include "G4OpenGLStoredSceneHandler.hh"
41#include "G4Text.hh"
42#include "G4Circle.hh"
43#include "G4UnitsTable.hh" // for G4BestUnit
44#include "G4Scene.hh"
45
46G4OpenGLStoredViewer::G4OpenGLStoredViewer
47(G4OpenGLStoredSceneHandler& sceneHandler):
48G4VViewer (sceneHandler, -1),
49G4OpenGLViewer (sceneHandler),
50fG4OpenGLStoredSceneHandler (sceneHandler)
51{
52 fLastVP = fDefaultVP; // Not sure if this gets executed before or
53 // after G4VViewer::G4VViewer!! Doesn't matter much.
54}
55
56G4OpenGLStoredViewer::~G4OpenGLStoredViewer () {}
57
58void G4OpenGLStoredViewer::KernelVisitDecision () {
59
60 // If there's a significant difference with the last view parameters
61 // of either the scene handler or this viewer, trigger a rebuild.
62
63 if (!fG4OpenGLStoredSceneHandler.fTopPODL ||
64 CompareForKernelVisit(fLastVP)) {
65 NeedKernelVisit ();
66 }
67 fLastVP = fVP;
68}
69
70G4bool G4OpenGLStoredViewer::CompareForKernelVisit(G4ViewParameters& lastVP) {
71
72 if (
73 (lastVP.GetDrawingStyle () != fVP.GetDrawingStyle ()) ||
74 (lastVP.IsAuxEdgeVisible () != fVP.IsAuxEdgeVisible ()) ||
75 (lastVP.GetRepStyle () != fVP.GetRepStyle ()) ||
76 (lastVP.IsCulling () != fVP.IsCulling ()) ||
77 (lastVP.IsCullingInvisible () != fVP.IsCullingInvisible ()) ||
78 (lastVP.IsDensityCulling () != fVP.IsDensityCulling ()) ||
79 (lastVP.IsCullingCovered () != fVP.IsCullingCovered ()) ||
80 (lastVP.IsSection () != fVP.IsSection ()) ||
81 // Section (DCUT) implemented locally. But still need to visit
82 // kernel if status changes so that back plane culling can be
83 // switched.
84 (lastVP.IsCutaway () != fVP.IsCutaway ()) ||
85 // Cutaways implemented locally. But still need to visit kernel
86 // if status changes so that back plane culling can be switched.
87 (lastVP.IsExplode () != fVP.IsExplode ()) ||
88 (lastVP.GetNoOfSides () != fVP.GetNoOfSides ()) ||
89 (lastVP.IsMarkerNotHidden () != fVP.IsMarkerNotHidden ()) ||
90 (lastVP.GetBackgroundColour ()!= fVP.GetBackgroundColour ())||
91 (lastVP.IsPicking () != fVP.IsPicking ())
92 )
93 return true;
94
95 if (lastVP.IsDensityCulling () &&
96 (lastVP.GetVisibleDensity () != fVP.GetVisibleDensity ()))
97 return true;
98
99 /**************************************************************
100 Section (DCUT) implemented locally. No need to visit kernel if
101 section plane itself changes.
102 if (lastVP.IsSection () &&
103 (lastVP.GetSectionPlane () != fVP.GetSectionPlane ()))
104 return true;
105 ***************************************************************/
106
107 /**************************************************************
108 Cutaways implemented locally. No need to visit kernel if cutaway
109 planes themselves change.
110 if (lastVP.IsCutaway ()) {
111 if (lastVP.GetCutawayPlanes ().size () !=
112 fVP.GetCutawayPlanes ().size ()) return true;
113 for (size_t i = 0; i < lastVP.GetCutawayPlanes().size(); ++i)
114 if (lastVP.GetCutawayPlanes()[i] != fVP.GetCutawayPlanes()[i])
115 return true;
116 }
117 ***************************************************************/
118
119 if (lastVP.IsExplode () &&
120 (lastVP.GetExplodeFactor () != fVP.GetExplodeFactor ()))
121 return true;
122
123 return false;
124}
125
126void G4OpenGLStoredViewer::DrawDisplayLists () {
127#ifdef G4DEBUG_VIS_OGL
128 printf("G4OpenGLStoredViewer::DrawDisplayLists \n");
129#endif
130
131 const G4Planes& cutaways = fVP.GetCutawayPlanes();
132 G4bool cutawayUnion = fVP.IsCutaway() &&
133 fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion;
134 size_t nPasses = cutawayUnion? cutaways.size(): 1;
135#ifdef G4DEBUG_VIS_OGL
136 printf("G4OpenGLStoredViewer::DrawDisplayLists");
137#endif
138 for (size_t i = 0; i < nPasses; ++i) {
139#ifdef G4DEBUG_VIS_OGL
140 printf("+");
141#endif
142
143 if (cutawayUnion) {
144 double a[4];
145 a[0] = cutaways[i].a();
146 a[1] = cutaways[i].b();
147 a[2] = cutaways[i].c();
148 a[3] = cutaways[i].d();
149 glClipPlane (GL_CLIP_PLANE2, a);
150 glEnable (GL_CLIP_PLANE2);
151 }
152
153 if (fG4OpenGLStoredSceneHandler.fTopPODL)
154 glCallList (fG4OpenGLStoredSceneHandler.fTopPODL);
155
156 for (size_t i = 0; i < fG4OpenGLStoredSceneHandler.fTOList.size(); ++i) {
157#ifdef G4DEBUG_VIS_OGL
158 printf("-");
159#endif
160 G4OpenGLStoredSceneHandler::TO& to =
161 fG4OpenGLStoredSceneHandler.fTOList[i];
162 if (to.fEndTime >= fStartTime && to.fStartTime <= fEndTime) {
163 glPushMatrix();
164 G4OpenGLTransform3D oglt (to.fTransform);
165 glMultMatrixd (oglt.GetGLMatrix ());
166 if (fVP.IsPicking()) glLoadName(to.fPickName);
167 G4Colour& c = to.fColour;
168 G4double bsf = 1.; // Brightness scaling factor.
169 if (fFadeFactor > 0. && to.fEndTime < fEndTime)
170 bsf = 1. - fFadeFactor *
171 ((fEndTime - to.fEndTime) / (fEndTime - fStartTime));
172 glColor3d(bsf * c.GetRed (), bsf * c.GetGreen (), bsf * c.GetBlue ());
173 glCallList (to.fDisplayListId);
174 glPopMatrix();
175 }
176 }
177
178 if (cutawayUnion) glDisable (GL_CLIP_PLANE2);
179 }
180#ifdef G4DEBUG_VIS_OGL
181 printf("\n");
182#endif
183
184 // Display time at "head" of time range, which is fEndTime...
185 if (fDisplayHeadTime && fEndTime < DBL_MAX) {
186 glMatrixMode (GL_PROJECTION);
187 glPushMatrix();
188 glLoadIdentity();
189 glOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
190 glMatrixMode (GL_MODELVIEW);
191 glPushMatrix();
192 glLoadIdentity();
193 G4Text headTimeText(G4BestUnit(fEndTime,"Time"),
194 G4Point3D(fDisplayHeadTimeX, fDisplayHeadTimeY, 0.));
195 headTimeText.SetScreenSize(fDisplayHeadTimeSize);
196 G4VisAttributes visAtts (G4Colour
197 (fDisplayHeadTimeRed,
198 fDisplayHeadTimeGreen,
199 fDisplayHeadTimeBlue));
200 headTimeText.SetVisAttributes(&visAtts);
201 static_cast<G4OpenGLSceneHandler&>(fSceneHandler).
202 G4OpenGLSceneHandler::AddPrimitive(headTimeText);
203 glMatrixMode (GL_PROJECTION);
204 glPopMatrix();
205 glMatrixMode (GL_MODELVIEW);
206 glPopMatrix();
207 }
208
209 // Display light front...
210 if (fDisplayLightFront && fEndTime < DBL_MAX) {
211 G4double lightFrontRadius = (fEndTime - fDisplayLightFrontT) * c_light;
212 if (lightFrontRadius > 0.) {
213 G4Point3D lightFrontCentre(fDisplayLightFrontX, fDisplayLightFrontY, fDisplayLightFrontZ);
214 G4Point3D circleCentre = lightFrontCentre;
215 G4double circleRadius = lightFrontRadius;
216 if (fVP.GetFieldHalfAngle() > 0.) {
217 // Perspective view. Find horizon centre and radius...
218 G4Point3D targetPoint = fSceneHandler.GetScene()->GetStandardTargetPoint() +
219 fVP.GetCurrentTargetPoint();
220 G4double sceneRadius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
221 if(sceneRadius <= 0.) sceneRadius = 1.;
222 G4double cameraDistance = fVP.GetCameraDistance(sceneRadius);
223 G4Point3D cameraPosition = targetPoint + cameraDistance * fVP.GetViewpointDirection().unit();
224 G4Vector3D lightFrontToCameraDirection = cameraPosition - lightFrontCentre;
225 G4double lightFrontCentreDistance = lightFrontToCameraDirection.mag();
226 /*
227 G4cout << "cameraPosition: " << cameraPosition
228 << ", lightFrontCentre: " << lightFrontCentre
229 << ", lightFrontRadius: " << lightFrontRadius
230 << ", lightFrontCentreDistance: " << lightFrontCentreDistance
231 << ", dot: " << lightFrontToCameraDirection * fVP.GetViewpointDirection()
232 << G4endl;
233 */
234 if (lightFrontToCameraDirection * fVP.GetViewpointDirection() > 0. && lightFrontRadius < lightFrontCentreDistance) {
235 // Light front in front of camera...
236 G4double sineHorizonAngle = lightFrontRadius / lightFrontCentreDistance;
237 circleCentre = lightFrontCentre + (lightFrontRadius * sineHorizonAngle) * lightFrontToCameraDirection.unit();
238 circleRadius = lightFrontRadius * std::sqrt(1. - std::pow(sineHorizonAngle, 2));
239 /*
240 G4cout << "sineHorizonAngle: " << sineHorizonAngle
241 << ", circleCentre: " << circleCentre
242 << ", circleRadius: " << circleRadius
243 << G4endl;
244 */
245 } else {
246 circleRadius = -1.;
247 }
248 }
249 if (circleRadius > 0.) {
250 G4Circle lightFront(circleCentre);
251 lightFront.SetWorldRadius(circleRadius);
252 glColor3d(fDisplayLightFrontRed,
253 fDisplayLightFrontGreen,
254 fDisplayLightFrontBlue);
255 static_cast<G4OpenGLSceneHandler&>(fSceneHandler).
256 G4OpenGLSceneHandler::AddPrimitive(lightFront);
257 }
258 }
259 }
260}
261
262#endif
Note: See TracBrowser for help on using the repository browser.