source: trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredViewer.cc@ 635

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

modif pour les formats d export

  • Property svn:mime-type set to text/cpp
File size: 10.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: G4OpenGLStoredViewer.cc,v 1.23 2007/04/04 16:50:27 allison 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"
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
128 printf("*************************** CASE AA ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
129 const G4Planes& cutaways = fVP.GetCutawayPlanes();
130 G4bool cutawayUnion = fVP.IsCutaway() &&
131 fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion;
132 size_t nPasses = cutawayUnion? cutaways.size(): 1;
133 for (size_t i = 0; i < nPasses; ++i) {
134 printf("*************************** CASE A ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
135
136 if (cutawayUnion) {
137 double a[4];
138 a[0] = cutaways[i].a();
139 a[1] = cutaways[i].b();
140 a[2] = cutaways[i].c();
141 a[3] = cutaways[i].d();
142 glClipPlane (GL_CLIP_PLANE2, a);
143 glEnable (GL_CLIP_PLANE2);
144 }
145
146 if (fG4OpenGLStoredSceneHandler.fTopPODL) {
147 glCallList (fG4OpenGLStoredSceneHandler.fTopPODL);
148 printf("*************************** CASE A1 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
149 }
150 for (size_t i = 0; i < fG4OpenGLStoredSceneHandler.fTOList.size(); ++i) {
151 printf("*************************** CASE B1 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
152 G4OpenGLStoredSceneHandler::TO& to =
153 fG4OpenGLStoredSceneHandler.fTOList[i];
154 if (to.fEndTime >= fStartTime && to.fStartTime <= fEndTime) {
155 printf("*************************** CASE B2 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
156 glPushMatrix();
157 G4OpenGLTransform3D oglt (to.fTransform);
158 glMultMatrixd (oglt.GetGLMatrix ());
159 if (fVP.IsPicking()) glLoadName(to.fPickName);
160 G4Colour& c = to.fColour;
161 G4double bsf = 1.; // Brightness scaling factor.
162 if (fFadeFactor > 0. && to.fEndTime < fEndTime)
163 bsf = 1. - fFadeFactor *
164 ((fEndTime - to.fEndTime) / (fEndTime - fStartTime));
165 glColor3d(bsf * c.GetRed (), bsf * c.GetGreen (), bsf * c.GetBlue ());
166 glCallList (to.fDisplayListId);
167 glPopMatrix();
168 printf("*************************** CASE B3 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
169 }
170 }
171
172 if (cutawayUnion) glDisable (GL_CLIP_PLANE2);
173 }
174
175 // Display time at "head" of time range, which is fEndTime...
176 if (fDisplayHeadTime && fEndTime < G4OPENGL_DBL_MAX) {
177 glMatrixMode (GL_PROJECTION);
178 glPushMatrix();
179 glLoadIdentity();
180 glOrtho (-1., 1., -1., 1., -G4OPENGL_DBL_MAX, G4OPENGL_DBL_MAX);
181 glMatrixMode (GL_MODELVIEW);
182 glPushMatrix();
183 glLoadIdentity();
184 G4Text headTimeText(G4BestUnit(fEndTime,"Time"),
185 G4Point3D(fDisplayHeadTimeX, fDisplayHeadTimeY, 0.));
186 headTimeText.SetScreenSize(fDisplayHeadTimeSize);
187 G4VisAttributes visAtts (G4Colour
188 (fDisplayHeadTimeRed,
189 fDisplayHeadTimeGreen,
190 fDisplayHeadTimeBlue));
191 headTimeText.SetVisAttributes(&visAtts);
192 static_cast<G4OpenGLSceneHandler&>(fSceneHandler).
193 G4OpenGLSceneHandler::AddPrimitive(headTimeText);
194 glMatrixMode (GL_PROJECTION);
195 glPopMatrix();
196 glMatrixMode (GL_MODELVIEW);
197 glPopMatrix();
198 }
199
200 // Display light front...
201 if (fDisplayLightFront && fEndTime < G4OPENGL_DBL_MAX) {
202 G4double lightFrontRadius = (fEndTime - fDisplayLightFrontT) * c_light;
203 if (lightFrontRadius > 0.) {
204 G4Point3D lightFrontCentre(fDisplayLightFrontX, fDisplayLightFrontY, fDisplayLightFrontZ);
205 G4Point3D circleCentre = lightFrontCentre;
206 G4double circleRadius = lightFrontRadius;
207 if (fVP.GetFieldHalfAngle() > 0.) {
208 // Perspective view. Find horizon centre and radius...
209 G4Point3D targetPoint = fSceneHandler.GetScene()->GetStandardTargetPoint() +
210 fVP.GetCurrentTargetPoint();
211 G4double sceneRadius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
212 if(sceneRadius <= 0.) sceneRadius = 1.;
213 G4double cameraDistance = fVP.GetCameraDistance(sceneRadius);
214 G4Point3D cameraPosition = targetPoint + cameraDistance * fVP.GetViewpointDirection().unit();
215 G4Vector3D lightFrontToCameraDirection = cameraPosition - lightFrontCentre;
216 G4double lightFrontCentreDistance = lightFrontToCameraDirection.mag();
217 /*
218 G4cout << "cameraPosition: " << cameraPosition
219 << ", lightFrontCentre: " << lightFrontCentre
220 << ", lightFrontRadius: " << lightFrontRadius
221 << ", lightFrontCentreDistance: " << lightFrontCentreDistance
222 << ", dot: " << lightFrontToCameraDirection * fVP.GetViewpointDirection()
223 << G4endl;
224 */
225 if (lightFrontToCameraDirection * fVP.GetViewpointDirection() > 0. && lightFrontRadius < lightFrontCentreDistance) {
226 // Light front in front of camera...
227 G4double sineHorizonAngle = lightFrontRadius / lightFrontCentreDistance;
228 circleCentre = lightFrontCentre + (lightFrontRadius * sineHorizonAngle) * lightFrontToCameraDirection.unit();
229 circleRadius = lightFrontRadius * std::sqrt(1. - std::pow(sineHorizonAngle, 2));
230 /*
231 G4cout << "sineHorizonAngle: " << sineHorizonAngle
232 << ", circleCentre: " << circleCentre
233 << ", circleRadius: " << circleRadius
234 << G4endl;
235 */
236 } else {
237 circleRadius = -1.;
238 }
239 }
240 if (circleRadius > 0.) {
241 G4Circle lightFront(circleCentre);
242 lightFront.SetWorldRadius(circleRadius);
243 glColor3d(fDisplayLightFrontRed,
244 fDisplayLightFrontGreen,
245 fDisplayLightFrontBlue);
246 static_cast<G4OpenGLSceneHandler&>(fSceneHandler).
247 G4OpenGLSceneHandler::AddPrimitive(lightFront);
248 }
249 }
250 }
251}
252
253#endif
Note: See TracBrowser for help on using the repository browser.