35#ifdef G4VIS_BUILD_OPENGL_DRIVER
47G4OpenGLStoredViewer::G4OpenGLStoredViewer
48(G4OpenGLStoredSceneHandler& sceneHandler):
50G4OpenGLViewer (sceneHandler),
51fG4OpenGLStoredSceneHandler (sceneHandler)
57G4OpenGLStoredViewer::~G4OpenGLStoredViewer () {}
59void G4OpenGLStoredViewer::KernelVisitDecision () {
64 if (!fG4OpenGLStoredSceneHandler.fTopPODL ||
65 CompareForKernelVisit(fLastVP)) {
77 (lastVP.
IsCulling () != fVP.IsCulling ()) ||
81 (lastVP.
IsSection () != fVP.IsSection ()) ||
85 (lastVP.
IsCutaway () != fVP.IsCutaway ()) ||
88 (lastVP.
IsExplode () != fVP.IsExplode ()) ||
91 fVP.GetDefaultVisAttributes()->
GetColour()) ||
93 fVP.GetDefaultTextVisAttributes()->
GetColour()) ||
95 (lastVP.
IsPicking () != fVP.IsPicking ()) ||
97 fVP.GetVisAttributesModifiers().size())
132void G4OpenGLStoredViewer::DrawDisplayLists () {
133#ifdef G4DEBUG_VIS_OGL
134 printf(
"G4OpenGLStoredViewer::DrawDisplayLists \n");
137 const G4Planes& cutaways = fVP.GetCutawayPlanes();
138 G4bool cutawayUnion = fVP.IsCutaway() &&
140 const size_t nCutaways = cutawayUnion? cutaways.size(): 1;
141#ifdef G4DEBUG_VIS_OGL
142 printf(
"G4OpenGLStoredViewer::DrawDisplayLists");
145 G4bool secondPassForTransparencyRequested =
false;
146 G4bool thirdPassForNonHiddenMarkersRequested =
false;
148 for (
size_t iCutaway = 0; iCutaway < nCutaways; ++iCutaway) {
152 a[0] = cutaways[iCutaway].a();
153 a[1] = cutaways[iCutaway].b();
154 a[2] = cutaways[iCutaway].c();
155 a[3] = cutaways[iCutaway].d();
156 glClipPlane (GL_CLIP_PLANE2, a);
157 glEnable (GL_CLIP_PLANE2);
160 G4bool isPicking = fVP.IsPicking();
163 iPO < fG4OpenGLStoredSceneHandler.fPOList.size(); ++iPO) {
164 if (POSelected(iPO)) {
165 G4OpenGLStoredSceneHandler::PO& po =
166 fG4OpenGLStoredSceneHandler.fPOList[iPO];
168 DisplayTimePOColourModification(c,iPO);
171 if (isTransparent && transparency_enabled) {
172 secondPassForTransparencyRequested =
true;
175 if (po.fMarkerOrPolyline && fVP.IsMarkerNotHidden()) {
176 thirdPassForNonHiddenMarkersRequested =
true;
179 }
else if (iPass == 2) {
180 if (!isTransparent) {
184 if (!po.fMarkerOrPolyline) {
188 if (isPicking) glLoadName(po.fPickName);
189 if (transparency_enabled) {
194 if (po.fMarkerOrPolyline && fVP.IsMarkerNotHidden())
195 glDisable (GL_DEPTH_TEST);
196 else {glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL);}
197 if (po.fpG4TextPlus) {
198 if (po.fpG4TextPlus->fProcessing2D) {
199 glMatrixMode (GL_PROJECTION);
202 glOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
203 glMatrixMode (GL_MODELVIEW);
207 G4OpenGLTransform3D oglt (po.fTransform);
208 glMultMatrixd (oglt.GetGLMatrix ());
209 fOpenGLSceneHandler.G4OpenGLSceneHandler::AddPrimitive
210 (po.fpG4TextPlus->fG4Text);
211 if (po.fpG4TextPlus->fProcessing2D) {
212 glMatrixMode (GL_PROJECTION);
214 glMatrixMode (GL_MODELVIEW);
219 G4OpenGLTransform3D oglt (po.fTransform);
220 glMultMatrixd (oglt.GetGLMatrix ());
221 glCallList (po.fDisplayListId);
231 iTO < fG4OpenGLStoredSceneHandler.fTOList.size(); ++iTO) {
232 if (TOSelected(iTO)) {
233 G4OpenGLStoredSceneHandler::TO& to =
234 fG4OpenGLStoredSceneHandler.fTOList[iTO];
238 if (isTransparent && transparency_enabled) {
239 secondPassForTransparencyRequested =
true;
242 if (to.fMarkerOrPolyline && fVP.IsMarkerNotHidden()) {
243 thirdPassForNonHiddenMarkersRequested =
true;
246 }
else if (iPass == 2) {
247 if (!isTransparent) {
251 if (!to.fMarkerOrPolyline) {
255 if (to.fMarkerOrPolyline && fVP.IsMarkerNotHidden())
256 glDisable (GL_DEPTH_TEST);
257 else {glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL);}
258 if (to.fEndTime >= fStartTime && to.fStartTime <= fEndTime) {
259 if (fVP.IsPicking()) glLoadName(to.fPickName);
260 if (to.fpG4TextPlus) {
261 if (to.fpG4TextPlus->fProcessing2D) {
262 glMatrixMode (GL_PROJECTION);
265 glOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
266 glMatrixMode (GL_MODELVIEW);
270 G4OpenGLTransform3D oglt (to.fTransform);
271 glMultMatrixd (oglt.GetGLMatrix ());
272 if (transparency_enabled) {
277 fOpenGLSceneHandler.G4OpenGLSceneHandler::AddPrimitive
278 (to.fpG4TextPlus->fG4Text);
279 if (to.fpG4TextPlus->fProcessing2D) {
280 glMatrixMode (GL_PROJECTION);
282 glMatrixMode (GL_MODELVIEW);
286 if (to.fTransform != lastMatrixTransform) {
292 G4OpenGLTransform3D oglt (to.fTransform);
293 glMultMatrixd (oglt.GetGLMatrix ());
296 if (fFadeFactor > 0. && to.fEndTime < fEndTime) {
299 ((fEndTime - to.fEndTime) / (fEndTime - fStartTime));
300 const G4Colour& bg = fVP.GetBackgroundColour();
301 if (transparency_enabled) {
303 (bsf * cc.
GetRed() + (1. - bsf) * bg.GetRed(),
304 bsf * cc.
GetGreen() + (1. - bsf) * bg.GetGreen(),
305 bsf * cc.
GetBlue() + (1. - bsf) * bg.GetBlue(),
306 bsf * cc.
GetAlpha() + (1. - bsf) * bg.GetAlpha());
309 (bsf * cc.
GetRed() + (1. - bsf) * bg.GetRed(),
310 bsf * cc.
GetGreen() + (1. - bsf) * bg.GetGreen(),
311 bsf * cc.
GetBlue() + (1. - bsf) * bg.GetBlue());
314 if (transparency_enabled) {
320 glCallList (to.fDisplayListId);
322 if (to.fTransform != lastMatrixTransform) {
323 lastMatrixTransform = to.fTransform;
332 if (cutawayUnion) glDisable (GL_CLIP_PLANE2);
335 if (iPass == 2) secondPassForTransparencyRequested =
false;
336 if (iPass == 3) thirdPassForNonHiddenMarkersRequested =
false;
338 if (secondPassForTransparencyRequested) iPass = 2;
339 else if (thirdPassForNonHiddenMarkersRequested) iPass = 3;
345 if (fDisplayHeadTime && fEndTime <
DBL_MAX) {
346 glMatrixMode (GL_PROJECTION);
349 glOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
350 glMatrixMode (GL_MODELVIEW);
354 G4Point3D(fDisplayHeadTimeX, fDisplayHeadTimeY, 0.));
355 headTimeText.SetScreenSize(fDisplayHeadTimeSize);
357 (fDisplayHeadTimeRed,
358 fDisplayHeadTimeGreen,
359 fDisplayHeadTimeBlue));
360 headTimeText.SetVisAttributes(&visAtts);
361 fOpenGLSceneHandler.G4OpenGLSceneHandler::AddPrimitive(headTimeText);
362 glMatrixMode (GL_PROJECTION);
364 glMatrixMode (GL_MODELVIEW);
369 if (fDisplayLightFront && fEndTime <
DBL_MAX) {
370 G4double lightFrontRadius = (fEndTime - fDisplayLightFrontT) * c_light;
371 if (lightFrontRadius > 0.) {
372 G4Point3D lightFrontCentre(fDisplayLightFrontX, fDisplayLightFrontY, fDisplayLightFrontZ);
373 G4Point3D circleCentre = lightFrontCentre;
374 G4double circleRadius = lightFrontRadius;
375 if (fVP.GetFieldHalfAngle() > 0.) {
377 G4Point3D targetPoint = fSceneHandler.GetScene()->GetStandardTargetPoint() +
378 fVP.GetCurrentTargetPoint();
379 G4double sceneRadius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
380 if(sceneRadius <= 0.) sceneRadius = 1.;
381 G4double cameraDistance = fVP.GetCameraDistance(sceneRadius);
382 G4Point3D cameraPosition = targetPoint + cameraDistance * fVP.GetViewpointDirection().
unit();
383 G4Vector3D lightFrontToCameraDirection = cameraPosition - lightFrontCentre;
384 G4double lightFrontCentreDistance = lightFrontToCameraDirection.
mag();
393 if (lightFrontToCameraDirection * fVP.GetViewpointDirection() > 0. && lightFrontRadius < lightFrontCentreDistance) {
395 G4double sineHorizonAngle = lightFrontRadius / lightFrontCentreDistance;
396 circleCentre = lightFrontCentre + (lightFrontRadius * sineHorizonAngle) * lightFrontToCameraDirection.
unit();
397 circleRadius = lightFrontRadius * std::sqrt(1. - std::pow(sineHorizonAngle, 2));
408 if (circleRadius > 0.) {
410 lightFront.SetWorldRadius(circleRadius);
411 glColor3d(fDisplayLightFrontRed,
412 fDisplayLightFrontGreen,
413 fDisplayLightFrontBlue);
414 fOpenGLSceneHandler.G4OpenGLSceneHandler::AddPrimitive(lightFront);
HepGeom::Point3D< G4double > G4Point3D
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
std::vector< G4Plane3D > G4Planes
G4double GetAlpha() const
static G4bool GetColour(const G4String &key, G4Colour &result)
G4double GetGreen() const
const std::vector< G4ModelingParameters::VisAttributesModifier > & GetVisAttributesModifiers() const
G4int GetNoOfSides() const
G4double GetExplodeFactor() const
const G4Colour & GetBackgroundColour() const
const G4VisAttributes * GetDefaultTextVisAttributes() const
G4bool IsCullingInvisible() const
RepStyle GetRepStyle() const
const G4VisAttributes * GetDefaultVisAttributes() const
G4bool IsDensityCulling() const
G4double GetVisibleDensity() const
G4bool IsCullingCovered() const
DrawingStyle GetDrawingStyle() const
G4bool IsAuxEdgeVisible() const
const G4Colour & GetColour() const
BasicVector3D< T > unit() const