Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/visualization/OpenGL/src/G4OpenGLStoredViewer.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /visualization/OpenGL/src/G4OpenGLStoredViewer.cc (Version 11.3.0) and /visualization/OpenGL/src/G4OpenGLStoredViewer.cc (Version 11.1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 //                                                 26 //
 27 //                                                 27 //
 28 //                                                 28 //
 29 // Andrew Walkden  7th February 1997               29 // Andrew Walkden  7th February 1997
 30 // Class G4OpenGLStoredViewer : Encapsulates t     30 // Class G4OpenGLStoredViewer : Encapsulates the `storedness' of
 31 //                            an OpenGL view,      31 //                            an OpenGL view, for inheritance by
 32 //                            derived (X, Xm..     32 //                            derived (X, Xm...) classes.
 33                                                    33 
 34 #include "G4OpenGLStoredViewer.hh"                 34 #include "G4OpenGLStoredViewer.hh"
 35                                                    35 
 36 #include "G4PhysicalConstants.hh"                  36 #include "G4PhysicalConstants.hh"
 37 #include "G4OpenGLStoredSceneHandler.hh"           37 #include "G4OpenGLStoredSceneHandler.hh"
 38 #include "G4Text.hh"                               38 #include "G4Text.hh"
 39 #include "G4Circle.hh"                             39 #include "G4Circle.hh"
 40 #include "G4UnitsTable.hh"                         40 #include "G4UnitsTable.hh"
 41 #include "G4Scene.hh"                              41 #include "G4Scene.hh"
 42 #include "G4OpenGLTransform3D.hh"                  42 #include "G4OpenGLTransform3D.hh"
 43                                                    43 
 44 G4OpenGLStoredViewer::G4OpenGLStoredViewer         44 G4OpenGLStoredViewer::G4OpenGLStoredViewer
 45 (G4OpenGLStoredSceneHandler& sceneHandler):        45 (G4OpenGLStoredSceneHandler& sceneHandler):
 46 G4VViewer (sceneHandler, -1),                      46 G4VViewer (sceneHandler, -1),
 47 G4OpenGLViewer (sceneHandler),                     47 G4OpenGLViewer (sceneHandler),
 48 fG4OpenGLStoredSceneHandler (sceneHandler),        48 fG4OpenGLStoredSceneHandler (sceneHandler),
 49 fDepthTestEnable(true)                             49 fDepthTestEnable(true)
 50 {                                                  50 {
 51   fLastVP = fDefaultVP;  // Update in sub-clas     51   fLastVP = fDefaultVP;  // Update in sub-class after KernelVisitDecision
 52 }                                                  52 }
 53                                                    53 
 54 G4OpenGLStoredViewer::~G4OpenGLStoredViewer ()     54 G4OpenGLStoredViewer::~G4OpenGLStoredViewer () {}
 55                                                    55 
 56 void G4OpenGLStoredViewer::KernelVisitDecision     56 void G4OpenGLStoredViewer::KernelVisitDecision () {
 57                                                    57   
 58   // If there's a significant difference with      58   // If there's a significant difference with the last view parameters
 59   // of either the scene handler or this viewe     59   // of either the scene handler or this viewer, trigger a rebuild.
 60                                                    60   
 61   if (!fG4OpenGLStoredSceneHandler.fTopPODL ||     61   if (!fG4OpenGLStoredSceneHandler.fTopPODL ||
 62       CompareForKernelVisit(fLastVP)) {            62       CompareForKernelVisit(fLastVP)) {
 63     NeedKernelVisit ();                            63     NeedKernelVisit ();
 64   }                                                64   }
 65 }                                                  65 }
 66                                                    66 
 67 G4bool G4OpenGLStoredViewer::CompareForKernelV     67 G4bool G4OpenGLStoredViewer::CompareForKernelVisit(G4ViewParameters& lastVP) {
 68                                                    68   
 69   if (                                             69   if (
 70       (lastVP.GetDrawingStyle ()    != fVP.Get     70       (lastVP.GetDrawingStyle ()    != fVP.GetDrawingStyle ())    ||
 71       (lastVP.GetNumberOfCloudPoints()  != fVP     71       (lastVP.GetNumberOfCloudPoints()  != fVP.GetNumberOfCloudPoints())  ||
 72       (lastVP.IsAuxEdgeVisible ()   != fVP.IsA     72       (lastVP.IsAuxEdgeVisible ()   != fVP.IsAuxEdgeVisible ())   ||
 73       (lastVP.IsCulling ()          != fVP.IsC     73       (lastVP.IsCulling ()          != fVP.IsCulling ())          ||
 74       (lastVP.IsCullingInvisible () != fVP.IsC     74       (lastVP.IsCullingInvisible () != fVP.IsCullingInvisible ()) ||
 75       (lastVP.IsDensityCulling ()   != fVP.IsD     75       (lastVP.IsDensityCulling ()   != fVP.IsDensityCulling ())   ||
 76       (lastVP.IsCullingCovered ()   != fVP.IsC     76       (lastVP.IsCullingCovered ()   != fVP.IsCullingCovered ())   ||
 77       (lastVP.GetCBDAlgorithmNumber() !=           77       (lastVP.GetCBDAlgorithmNumber() !=
 78        fVP.GetCBDAlgorithmNumber())                78        fVP.GetCBDAlgorithmNumber())                               ||
 79       // Note: Section and Cutaway can reveal      79       // Note: Section and Cutaway can reveal back-facing faces. If
 80       // backface culling is implemented, the      80       // backface culling is implemented, the image can look strange because
 81       // the back-facing faces are not there.      81       // the back-facing faces are not there. For the moment, we have disabled
 82       // (commented out) backface culling (it      82       // (commented out) backface culling (it seems not to affect performance -
 83       // in fact, performance seems to improve     83       // in fact, performance seems to improve), so there is no problem.
 84       (lastVP.IsSection ()          != fVP.IsS     84       (lastVP.IsSection ()          != fVP.IsSection ())          ||
 85       // Section (DCUT) is NOT implemented loc     85       // Section (DCUT) is NOT implemented locally so we need to visit the kernel.
 86       // (lastVP.IsCutaway ()          != fVP.     86       // (lastVP.IsCutaway ()          != fVP.IsCutaway ())          ||
 87       // Cutaways are implemented locally so w     87       // Cutaways are implemented locally so we do not need to visit the kernel.
 88       (lastVP.IsExplode ()          != fVP.IsE     88       (lastVP.IsExplode ()          != fVP.IsExplode ())          ||
 89       (lastVP.GetNoOfSides ()       != fVP.Get     89       (lastVP.GetNoOfSides ()       != fVP.GetNoOfSides ())       ||
 90       (lastVP.GetGlobalMarkerScale()    != fVP     90       (lastVP.GetGlobalMarkerScale()    != fVP.GetGlobalMarkerScale())    ||
 91       (lastVP.GetGlobalLineWidthScale() != fVP     91       (lastVP.GetGlobalLineWidthScale() != fVP.GetGlobalLineWidthScale()) ||
 92       (lastVP.IsMarkerNotHidden ()  != fVP.IsM     92       (lastVP.IsMarkerNotHidden ()  != fVP.IsMarkerNotHidden ())  ||
 93       (lastVP.GetDefaultVisAttributes()->GetCo     93       (lastVP.GetDefaultVisAttributes()->GetColour() !=
 94        fVP.GetDefaultVisAttributes()->GetColou     94        fVP.GetDefaultVisAttributes()->GetColour())                ||
 95       (lastVP.GetDefaultTextVisAttributes()->G     95       (lastVP.GetDefaultTextVisAttributes()->GetColour() !=
 96        fVP.GetDefaultTextVisAttributes()->GetC     96        fVP.GetDefaultTextVisAttributes()->GetColour())            ||
 97       (lastVP.GetBackgroundColour ()!= fVP.Get     97       (lastVP.GetBackgroundColour ()!= fVP.GetBackgroundColour ())||
 98       (lastVP.IsPicking ()          != fVP.IsP     98       (lastVP.IsPicking ()          != fVP.IsPicking ())          ||
 99       (lastVP.GetVisAttributesModifiers() !=       99       (lastVP.GetVisAttributesModifiers() !=
100        fVP.GetVisAttributesModifiers())           100        fVP.GetVisAttributesModifiers())                           ||
101       (lastVP.IsSpecialMeshRendering() !=         101       (lastVP.IsSpecialMeshRendering() !=
102        fVP.IsSpecialMeshRendering())              102        fVP.IsSpecialMeshRendering())                              ||
103       (lastVP.GetSpecialMeshRenderingOption()     103       (lastVP.GetSpecialMeshRenderingOption() !=
104        fVP.GetSpecialMeshRenderingOption())       104        fVP.GetSpecialMeshRenderingOption())
105       )                                           105       )
106   return true;                                    106   return true;
107                                                   107   
108   if (lastVP.IsDensityCulling () &&               108   if (lastVP.IsDensityCulling () &&
109       (lastVP.GetVisibleDensity () != fVP.GetV    109       (lastVP.GetVisibleDensity () != fVP.GetVisibleDensity ()))
110   return true;                                    110   return true;
111                                                   111   
112 //  /*****************************************    112 //  /**************************************************************
113 //   If section (DCUT) is implemented locally,    113 //   If section (DCUT) is implemented locally, comment this out.
114   if (lastVP.IsSection () &&                      114   if (lastVP.IsSection () &&
115       (lastVP.GetSectionPlane () != fVP.GetSec    115       (lastVP.GetSectionPlane () != fVP.GetSectionPlane ()))
116     return true;                                  116     return true;
117 //   *****************************************    117 //   ***************************************************************/
118                                                   118   
119   /*******************************************    119   /**************************************************************
120    If cutaways are implemented locally, commen    120    If cutaways are implemented locally, comment this out.
121    if (lastVP.IsCutaway ()) {                     121    if (lastVP.IsCutaway ()) {
122    if (vp.GetCutawayMode() != fVP.GetCutawayMo    122    if (vp.GetCutawayMode() != fVP.GetCutawayMode()) return true;
123    if (lastVP.GetCutawayPlanes ().size () !=      123    if (lastVP.GetCutawayPlanes ().size () !=
124    fVP.GetCutawayPlanes ().size ()) return tru    124    fVP.GetCutawayPlanes ().size ()) return true;
125    for (size_t i = 0; i < lastVP.GetCutawayPla    125    for (size_t i = 0; i < lastVP.GetCutawayPlanes().size(); ++i)
126    if (lastVP.GetCutawayPlanes()[i] != fVP.Get    126    if (lastVP.GetCutawayPlanes()[i] != fVP.GetCutawayPlanes()[i])
127    return true;                                   127    return true;
128    }                                              128    }
129    *******************************************    129    ***************************************************************/
130                                                   130   
131   if (lastVP.GetCBDAlgorithmNumber() > 0) {       131   if (lastVP.GetCBDAlgorithmNumber() > 0) {
132     if (lastVP.GetCBDParameters().size() != fV    132     if (lastVP.GetCBDParameters().size() != fVP.GetCBDParameters().size()) return true;
133     else if (lastVP.GetCBDParameters() != fVP.    133     else if (lastVP.GetCBDParameters() != fVP.GetCBDParameters()) return true;
134   }                                               134   }
135                                                   135 
136   if (lastVP.IsExplode () &&                      136   if (lastVP.IsExplode () &&
137       (lastVP.GetExplodeFactor () != fVP.GetEx    137       (lastVP.GetExplodeFactor () != fVP.GetExplodeFactor ()))
138     return true;                                  138     return true;
139                                                   139 
140   if (lastVP.IsSpecialMeshRendering() &&          140   if (lastVP.IsSpecialMeshRendering() &&
141       (lastVP.GetSpecialMeshVolumes() != fVP.G    141       (lastVP.GetSpecialMeshVolumes() != fVP.GetSpecialMeshVolumes()))
142     return true;                                  142     return true;
143                                                   143 
144   // Time window parameters operate on the exi    144   // Time window parameters operate on the existing database so no need
145   // to rebuild even if they change.              145   // to rebuild even if they change.
146                                                   146   
147   return false;                                   147   return false;
148 }                                                 148 }
149                                                   149 
150 void G4OpenGLStoredViewer::DrawDisplayLists ()    150 void G4OpenGLStoredViewer::DrawDisplayLists () {
151                                                   151   
152   // We moved these from G4OpenGLViewer to G4V    152   // We moved these from G4OpenGLViewer to G4ViewParamaters. To avoid
153   // editing many lines below we introduce the    153   // editing many lines below we introduce these convenient aliases.
154 #define CONVENIENT_DOUBLE_ALIAS(q) const G4dou    154 #define CONVENIENT_DOUBLE_ALIAS(q) const G4double& f##q = fVP.Get##q();
155 #define CONVENIENT_BOOL_ALIAS(q) const G4bool&    155 #define CONVENIENT_BOOL_ALIAS(q) const G4bool& f##q = fVP.Is##q();
156   CONVENIENT_DOUBLE_ALIAS(StartTime)              156   CONVENIENT_DOUBLE_ALIAS(StartTime)
157   CONVENIENT_DOUBLE_ALIAS(EndTime)                157   CONVENIENT_DOUBLE_ALIAS(EndTime)
158   CONVENIENT_DOUBLE_ALIAS(FadeFactor)             158   CONVENIENT_DOUBLE_ALIAS(FadeFactor)
159   CONVENIENT_BOOL_ALIAS(DisplayHeadTime)          159   CONVENIENT_BOOL_ALIAS(DisplayHeadTime)
160   CONVENIENT_DOUBLE_ALIAS(DisplayHeadTimeX)       160   CONVENIENT_DOUBLE_ALIAS(DisplayHeadTimeX)
161   CONVENIENT_DOUBLE_ALIAS(DisplayHeadTimeY)       161   CONVENIENT_DOUBLE_ALIAS(DisplayHeadTimeY)
162   CONVENIENT_DOUBLE_ALIAS(DisplayHeadTimeSize)    162   CONVENIENT_DOUBLE_ALIAS(DisplayHeadTimeSize)
163   CONVENIENT_DOUBLE_ALIAS(DisplayHeadTimeRed)     163   CONVENIENT_DOUBLE_ALIAS(DisplayHeadTimeRed)
164   CONVENIENT_DOUBLE_ALIAS(DisplayHeadTimeGreen    164   CONVENIENT_DOUBLE_ALIAS(DisplayHeadTimeGreen)
165   CONVENIENT_DOUBLE_ALIAS(DisplayHeadTimeBlue)    165   CONVENIENT_DOUBLE_ALIAS(DisplayHeadTimeBlue)
166   CONVENIENT_BOOL_ALIAS(DisplayLightFront)        166   CONVENIENT_BOOL_ALIAS(DisplayLightFront)
167   CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontX)     167   CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontX)
168   CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontY)     168   CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontY)
169   CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontZ)     169   CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontZ)
170   CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontT)     170   CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontT)
171   CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontRed    171   CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontRed)
172   CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontGre    172   CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontGreen)
173   CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontBlu    173   CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontBlue)
174                                                   174 
175   const G4Planes& cutaways = fVP.GetCutawayPla    175   const G4Planes& cutaways = fVP.GetCutawayPlanes();
176   G4bool cutawayUnion = fVP.IsCutaway() &&        176   G4bool cutawayUnion = fVP.IsCutaway() &&
177   fVP.GetCutawayMode() == G4ViewParameters::cu    177   fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion;
178   const size_t nCutaways = cutawayUnion? cutaw    178   const size_t nCutaways = cutawayUnion? cutaways.size(): 1;
179   G4int iPass = 1;                                179   G4int iPass = 1;
180   G4bool secondPassForTransparencyRequested =     180   G4bool secondPassForTransparencyRequested = false;
181   G4bool thirdPassForNonHiddenMarkersRequested    181   G4bool thirdPassForNonHiddenMarkersRequested = false;
182   fDepthTestEnable = true;                        182   fDepthTestEnable = true;
183   glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LE    183   glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL);
184   do {                                            184   do {
185     for (size_t iCutaway = 0; iCutaway < nCuta    185     for (size_t iCutaway = 0; iCutaway < nCutaways; ++iCutaway) {
186                                                   186       
187       if (cutawayUnion) {                         187       if (cutawayUnion) {
188         double a[4];                              188         double a[4];
189         a[0] = cutaways[iCutaway].a();            189         a[0] = cutaways[iCutaway].a();
190         a[1] = cutaways[iCutaway].b();            190         a[1] = cutaways[iCutaway].b();
191         a[2] = cutaways[iCutaway].c();            191         a[2] = cutaways[iCutaway].c();
192         a[3] = cutaways[iCutaway].d();            192         a[3] = cutaways[iCutaway].d();
193         glClipPlane (GL_CLIP_PLANE2, a);          193         glClipPlane (GL_CLIP_PLANE2, a);
194         glEnable (GL_CLIP_PLANE2);                194         glEnable (GL_CLIP_PLANE2);
195       }                                           195       }
196                                                   196       
197       G4bool isPicking = fVP.IsPicking();         197       G4bool isPicking = fVP.IsPicking();
198                                                   198       
199       for (size_t iPO = 0;                        199       for (size_t iPO = 0;
200            iPO < fG4OpenGLStoredSceneHandler.f    200            iPO < fG4OpenGLStoredSceneHandler.fPOList.size(); ++iPO) {
201         if (POSelected(iPO)) {                    201         if (POSelected(iPO)) {
202           G4OpenGLStoredSceneHandler::PO& po =    202           G4OpenGLStoredSceneHandler::PO& po =
203           fG4OpenGLStoredSceneHandler.fPOList[    203           fG4OpenGLStoredSceneHandler.fPOList[iPO];
204           G4Colour c = po.fColour;                204           G4Colour c = po.fColour;
205           DisplayTimePOColourModification(c,iP    205           DisplayTimePOColourModification(c,iPO);
206           const G4bool isTransparent = c.GetAl    206           const G4bool isTransparent = c.GetAlpha() < 1.;
207           if ( iPass == 1) {                      207           if ( iPass == 1) {
208             if (isTransparent && transparency_    208             if (isTransparent && transparency_enabled) {
209               secondPassForTransparencyRequest    209               secondPassForTransparencyRequested = true;
210               continue;                           210               continue;
211             }                                     211             }
212             if (po.fMarkerOrPolyline && fVP.Is    212             if (po.fMarkerOrPolyline && fVP.IsMarkerNotHidden()) {
213               thirdPassForNonHiddenMarkersRequ    213               thirdPassForNonHiddenMarkersRequested = true;
214               continue;                           214               continue;
215             }                                     215             }
216           } else if (iPass == 2) {  // Second     216           } else if (iPass == 2) {  // Second pass for transparency.
217             if (!isTransparent) {                 217             if (!isTransparent) {
218               continue;                           218               continue;
219             }                                     219             }
220           } else {  // Third pass for non-hidd    220           } else {  // Third pass for non-hidden markers
221             if (!po.fMarkerOrPolyline) {          221             if (!po.fMarkerOrPolyline) {
222               continue;                           222               continue;
223             }                                     223             }
224           }                                       224           }
225           if (isPicking) glLoadName(po.fPickNa    225           if (isPicking) glLoadName(po.fPickName);
226           if (transparency_enabled) {             226           if (transparency_enabled) {
227             glColor4d(c.GetRed(),c.GetGreen(),    227             glColor4d(c.GetRed(),c.GetGreen(),c.GetBlue(),c.GetAlpha());
228           } else {                                228           } else {
229             glColor3d(c.GetRed(),c.GetGreen(),    229             glColor3d(c.GetRed(),c.GetGreen(),c.GetBlue());
230           }                                       230           }
231           if (po.fMarkerOrPolyline && fVP.IsMa    231           if (po.fMarkerOrPolyline && fVP.IsMarkerNotHidden()) {
232             if (fDepthTestEnable !=false) {       232             if (fDepthTestEnable !=false) {
233               glDisable (GL_DEPTH_TEST);          233               glDisable (GL_DEPTH_TEST);
234               fDepthTestEnable = false;           234               fDepthTestEnable = false;
235             }                                     235             }
236           } else {                                236           } else {
237             if (fDepthTestEnable !=true) {        237             if (fDepthTestEnable !=true) {
238               glEnable (GL_DEPTH_TEST); glDept    238               glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL);
239               fDepthTestEnable = true;            239               fDepthTestEnable = true;
240             }                                     240             }
241           }                                       241           }
242           if (po.fpG4TextPlus) {                  242           if (po.fpG4TextPlus) {
243             if (po.fpG4TextPlus->fProcessing2D    243             if (po.fpG4TextPlus->fProcessing2D) {
244               glMatrixMode (GL_PROJECTION);       244               glMatrixMode (GL_PROJECTION);
245               glPushMatrix();                     245               glPushMatrix();
246               glLoadIdentity();                   246               glLoadIdentity();
247               g4GlOrtho (-1., 1., -1., 1., -G4    247               g4GlOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
248               glMatrixMode (GL_MODELVIEW);        248               glMatrixMode (GL_MODELVIEW);
249               glPushMatrix();                     249               glPushMatrix();
250               glLoadIdentity();                   250               glLoadIdentity();
251               G4OpenGLTransform3D oglt (po.fTr    251               G4OpenGLTransform3D oglt (po.fTransform);
252               glMultMatrixd (oglt.GetGLMatrix     252               glMultMatrixd (oglt.GetGLMatrix ());
253               // This text is from a PODL. We     253               // This text is from a PODL. We don't want to create a new PODL.
254               AddPrimitiveForASingleFrame(po.f    254               AddPrimitiveForASingleFrame(po.fpG4TextPlus->fG4Text);
255             } else {                              255             } else {
256               glPushMatrix();                     256               glPushMatrix();
257               G4OpenGLTransform3D oglt (po.fTr    257               G4OpenGLTransform3D oglt (po.fTransform);
258               glMultMatrixd (oglt.GetGLMatrix     258               glMultMatrixd (oglt.GetGLMatrix ());
259               // This text is from a PODL. We     259               // This text is from a PODL. We don't want to create a new PODL.
260               AddPrimitiveForASingleFrame(po.f    260               AddPrimitiveForASingleFrame(po.fpG4TextPlus->fG4Text);
261               glPopMatrix();                      261               glPopMatrix();
262             }                                     262             }
263                                                   263             
264             if (po.fpG4TextPlus->fProcessing2D    264             if (po.fpG4TextPlus->fProcessing2D) {
265               glMatrixMode (GL_PROJECTION);       265               glMatrixMode (GL_PROJECTION);
266               glPopMatrix();                      266               glPopMatrix();
267               glMatrixMode (GL_MODELVIEW);        267               glMatrixMode (GL_MODELVIEW);
268               glPopMatrix();                      268               glPopMatrix();
269             }                                     269             }
270           } else {                                270           } else {
271             glPushMatrix();                       271             glPushMatrix();
272             G4OpenGLTransform3D oglt (po.fTran    272             G4OpenGLTransform3D oglt (po.fTransform);
273             glMultMatrixd (oglt.GetGLMatrix ()    273             glMultMatrixd (oglt.GetGLMatrix ());
274             glCallList (po.fDisplayListId);       274             glCallList (po.fDisplayListId);
275             glPopMatrix();                        275             glPopMatrix();
276           }                                       276           }
277         }                                         277         }
278       }                                           278       }
279                                                   279       
280       G4Transform3D lastMatrixTransform;          280       G4Transform3D lastMatrixTransform;
281       G4bool first = true;                        281       G4bool first = true;
282                                                   282 
283       for (size_t iTO = 0;                        283       for (size_t iTO = 0;
284            iTO < fG4OpenGLStoredSceneHandler.f    284            iTO < fG4OpenGLStoredSceneHandler.fTOList.size(); ++iTO) {
285         if (TOSelected(iTO)) {                    285         if (TOSelected(iTO)) {
286           G4OpenGLStoredSceneHandler::TO& to =    286           G4OpenGLStoredSceneHandler::TO& to =
287           fG4OpenGLStoredSceneHandler.fTOList[    287           fG4OpenGLStoredSceneHandler.fTOList[iTO];
288           const G4Colour& c = to.fColour;         288           const G4Colour& c = to.fColour;
289           const G4bool isTransparent = c.GetAl    289           const G4bool isTransparent = c.GetAlpha() < 1.;
290           if ( iPass == 1) {                      290           if ( iPass == 1) {
291             if (isTransparent && transparency_    291             if (isTransparent && transparency_enabled) {
292               secondPassForTransparencyRequest    292               secondPassForTransparencyRequested = true;
293               continue;                           293               continue;
294             }                                     294             }
295             if (to.fMarkerOrPolyline && fVP.Is    295             if (to.fMarkerOrPolyline && fVP.IsMarkerNotHidden()) {
296               thirdPassForNonHiddenMarkersRequ    296               thirdPassForNonHiddenMarkersRequested = true;
297               continue;                           297               continue;
298             }                                     298             }
299           } else if (iPass == 2) {  // Second     299           } else if (iPass == 2) {  // Second pass for transparency.
300             if (!isTransparent) {                 300             if (!isTransparent) {
301               continue;                           301               continue;
302             }                                     302             }
303           } else {  // Third pass for non-hidd    303           } else {  // Third pass for non-hidden markers
304             if (!to.fMarkerOrPolyline) {          304             if (!to.fMarkerOrPolyline) {
305               continue;                           305               continue;
306             }                                     306             }
307           }                                       307           }
308           if (to.fMarkerOrPolyline && fVP.IsMa    308           if (to.fMarkerOrPolyline && fVP.IsMarkerNotHidden()) {
309             if (fDepthTestEnable !=false) {       309             if (fDepthTestEnable !=false) {
310               glDisable (GL_DEPTH_TEST);          310               glDisable (GL_DEPTH_TEST);
311               fDepthTestEnable = false;           311               fDepthTestEnable = false;
312             }                                     312             }
313           } else {                                313           } else {
314             if (fDepthTestEnable !=true) {        314             if (fDepthTestEnable !=true) {
315               glEnable (GL_DEPTH_TEST); glDept    315               glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL);
316               fDepthTestEnable = true;            316               fDepthTestEnable = true;
317             }                                     317             }
318           }                                       318           }
319           if (to.fEndTime >= fStartTime && to.    319           if (to.fEndTime >= fStartTime && to.fStartTime <= fEndTime) {
320             if (fVP.IsPicking()) glLoadName(to    320             if (fVP.IsPicking()) glLoadName(to.fPickName);
321             if (to.fpG4TextPlus) {                321             if (to.fpG4TextPlus) {
322               if (to.fpG4TextPlus->fProcessing    322               if (to.fpG4TextPlus->fProcessing2D) {
323                 glMatrixMode (GL_PROJECTION);     323                 glMatrixMode (GL_PROJECTION);
324                 glPushMatrix();                   324                 glPushMatrix();
325                 glLoadIdentity();                 325                 glLoadIdentity();
326                 g4GlOrtho (-1., 1., -1., 1., -    326                 g4GlOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
327                 glMatrixMode (GL_MODELVIEW);      327                 glMatrixMode (GL_MODELVIEW);
328                 glPushMatrix();                   328                 glPushMatrix();
329                 glLoadIdentity();                 329                 glLoadIdentity();
330               }                                   330               }
331               G4OpenGLTransform3D oglt (to.fTr    331               G4OpenGLTransform3D oglt (to.fTransform);
332               glMultMatrixd (oglt.GetGLMatrix     332               glMultMatrixd (oglt.GetGLMatrix ());
333               // This text is from a TODL. We     333               // This text is from a TODL. We don't want to create a new TODL.
334               AddPrimitiveForASingleFrame(to.f    334               AddPrimitiveForASingleFrame(to.fpG4TextPlus->fG4Text);
335               if (to.fpG4TextPlus->fProcessing    335               if (to.fpG4TextPlus->fProcessing2D) {
336                 glMatrixMode (GL_PROJECTION);     336                 glMatrixMode (GL_PROJECTION);
337                 glPopMatrix();                    337                 glPopMatrix();
338                 glMatrixMode (GL_MODELVIEW);      338                 glMatrixMode (GL_MODELVIEW);
339                 glPopMatrix();                    339                 glPopMatrix();
340               }                                   340               }
341             } else {                              341             } else {
342               if (to.fTransform != lastMatrixT    342               if (to.fTransform != lastMatrixTransform) {
343                 if (! first) {                    343                 if (! first) {
344                   glPopMatrix();                  344                   glPopMatrix();
345                 }                                 345                 }
346                 first = false;                    346                 first = false;
347                 glPushMatrix();                   347                 glPushMatrix();
348                 G4OpenGLTransform3D oglt (to.f    348                 G4OpenGLTransform3D oglt (to.fTransform);
349                 glMultMatrixd (oglt.GetGLMatri    349                 glMultMatrixd (oglt.GetGLMatrix ());
350               }                                   350               }
351               const G4Colour& cc = to.fColour;    351               const G4Colour& cc = to.fColour;
352               if (fFadeFactor > 0. && to.fEndT    352               if (fFadeFactor > 0. && to.fEndTime < fEndTime) {
353                 // Brightness scaling factor      353                 // Brightness scaling factor
354                 G4double bsf = 1. - fFadeFacto    354                 G4double bsf = 1. - fFadeFactor *
355                 ((fEndTime - to.fEndTime) / (f    355                 ((fEndTime - to.fEndTime) / (fEndTime - fStartTime));
356                 const G4Colour& bg = fVP.GetBa    356                 const G4Colour& bg = fVP.GetBackgroundColour();
357                 if (transparency_enabled) {       357                 if (transparency_enabled) {
358                   glColor4d                       358                   glColor4d
359                   (bsf * cc.GetRed() + (1. - b    359                   (bsf * cc.GetRed() + (1. - bsf) * bg.GetRed(),
360                    bsf * cc.GetGreen() + (1. -    360                    bsf * cc.GetGreen() + (1. - bsf) * bg.GetGreen(),
361                    bsf * cc.GetBlue() + (1. -     361                    bsf * cc.GetBlue() + (1. - bsf) * bg.GetBlue(),
362                    bsf * cc.GetAlpha() + (1. -    362                    bsf * cc.GetAlpha() + (1. - bsf) * bg.GetAlpha());
363                 } else {                          363                 } else {
364                   glColor3d                       364                   glColor3d
365                   (bsf * cc.GetRed() + (1. - b    365                   (bsf * cc.GetRed() + (1. - bsf) * bg.GetRed(),
366                    bsf * cc.GetGreen() + (1. -    366                    bsf * cc.GetGreen() + (1. - bsf) * bg.GetGreen(),
367                    bsf * cc.GetBlue() + (1. -     367                    bsf * cc.GetBlue() + (1. - bsf) * bg.GetBlue());
368                 }                                 368                 }
369               } else {                            369               } else {
370                 if (transparency_enabled) {       370                 if (transparency_enabled) {
371                   glColor4d(cc.GetRed(),cc.Get    371                   glColor4d(cc.GetRed(),cc.GetGreen(),cc.GetBlue(),cc.GetAlpha());
372                 } else {                          372                 } else {
373                   glColor3d(cc.GetRed(),cc.Get    373                   glColor3d(cc.GetRed(),cc.GetGreen(),cc.GetBlue());
374                 }                                 374                 }
375               }                                   375               }
376               glCallList (to.fDisplayListId);     376               glCallList (to.fDisplayListId);
377             }                                     377             }
378             if (to.fTransform != lastMatrixTra    378             if (to.fTransform != lastMatrixTransform) {
379               lastMatrixTransform = to.fTransf    379               lastMatrixTransform = to.fTransform;
380             }                                     380             }
381           }                                       381           }
382         }                                         382         }
383       }                                           383       }
384       if (! first) {                              384       if (! first) {
385         glPopMatrix();                            385         glPopMatrix();
386       }                                           386       }
387                                                   387       
388       if (cutawayUnion) glDisable (GL_CLIP_PLA    388       if (cutawayUnion) glDisable (GL_CLIP_PLANE2);
389     }  // iCutaway                                389     }  // iCutaway
390                                                   390     
391     if (iPass == 2) secondPassForTransparencyR    391     if (iPass == 2) secondPassForTransparencyRequested = false;  // Done.
392     if (iPass == 3) thirdPassForNonHiddenMarke    392     if (iPass == 3) thirdPassForNonHiddenMarkersRequested = false;  // Done.
393                                                   393     
394     if (secondPassForTransparencyRequested) iP    394     if (secondPassForTransparencyRequested) iPass = 2;
395     else if (thirdPassForNonHiddenMarkersReque    395     else if (thirdPassForNonHiddenMarkersRequested) iPass = 3;
396     else break;                                   396     else break;
397                                                   397     
398   } while (true);                                 398   } while (true);
399                                                   399   
400   // Display time at "head" of time range, whi    400   // Display time at "head" of time range, which is fEndTime...
401   if (fDisplayHeadTime && fEndTime < G4VisAttr    401   if (fDisplayHeadTime && fEndTime < G4VisAttributes::fVeryLongTime) {
402     glMatrixMode (GL_PROJECTION);                 402     glMatrixMode (GL_PROJECTION);
403     glPushMatrix();                               403     glPushMatrix();
404     glLoadIdentity();                             404     glLoadIdentity();
405     g4GlOrtho (-1., 1., -1., 1., -G4OPENGL_FLT    405     g4GlOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
406     glMatrixMode (GL_MODELVIEW);                  406     glMatrixMode (GL_MODELVIEW);
407     glPushMatrix();                               407     glPushMatrix();
408     glLoadIdentity();                             408     glLoadIdentity();
409     G4Text headTimeText(G4BestUnit(fEndTime,"T    409     G4Text headTimeText(G4BestUnit(fEndTime,"Time"),
410                         G4Point3D(fDisplayHead    410                         G4Point3D(fDisplayHeadTimeX, fDisplayHeadTimeY, 0.));
411     headTimeText.SetScreenSize(fDisplayHeadTim    411     headTimeText.SetScreenSize(fDisplayHeadTimeSize);
412     G4VisAttributes visAtts (G4Colour             412     G4VisAttributes visAtts (G4Colour
413                              (fDisplayHeadTime    413                              (fDisplayHeadTimeRed,
414                               fDisplayHeadTime    414                               fDisplayHeadTimeGreen,
415                               fDisplayHeadTime    415                               fDisplayHeadTimeBlue));
416     headTimeText.SetVisAttributes(&visAtts);      416     headTimeText.SetVisAttributes(&visAtts);
417     AddPrimitiveForASingleFrame(headTimeText);    417     AddPrimitiveForASingleFrame(headTimeText);
418     glMatrixMode (GL_PROJECTION);                 418     glMatrixMode (GL_PROJECTION);
419     glPopMatrix();                                419     glPopMatrix();
420     glMatrixMode (GL_MODELVIEW);                  420     glMatrixMode (GL_MODELVIEW);
421     glPopMatrix();                                421     glPopMatrix();
422   }                                               422   }
423                                                   423   
424   // Display light front...                       424   // Display light front...
425   if (fDisplayLightFront && fEndTime < G4VisAt    425   if (fDisplayLightFront && fEndTime < G4VisAttributes::fVeryLongTime) {
426     G4double lightFrontRadius = (fEndTime - fD    426     G4double lightFrontRadius = (fEndTime - fDisplayLightFrontT) * c_light;
427     if (lightFrontRadius > 0.) {                  427     if (lightFrontRadius > 0.) {
428       G4Point3D lightFrontCentre(fDisplayLight    428       G4Point3D lightFrontCentre(fDisplayLightFrontX, fDisplayLightFrontY, fDisplayLightFrontZ);
429       G4Point3D circleCentre = lightFrontCentr    429       G4Point3D circleCentre = lightFrontCentre;
430       G4double circleRadius = lightFrontRadius    430       G4double circleRadius = lightFrontRadius;
431       if (fVP.GetFieldHalfAngle() > 0.) {         431       if (fVP.GetFieldHalfAngle() > 0.) {
432         // Perspective view.  Find horizon cen    432         // Perspective view.  Find horizon centre and radius...
433         G4Point3D targetPoint = fSceneHandler.    433         G4Point3D targetPoint = fSceneHandler.GetScene()->GetStandardTargetPoint() +
434         fVP.GetCurrentTargetPoint();              434         fVP.GetCurrentTargetPoint();
435         G4double sceneRadius = fSceneHandler.G    435         G4double sceneRadius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
436         if(sceneRadius <= 0.) sceneRadius = 1.    436         if(sceneRadius <= 0.) sceneRadius = 1.;
437         G4double cameraDistance = fVP.GetCamer    437         G4double cameraDistance = fVP.GetCameraDistance(sceneRadius);
438         G4Point3D cameraPosition = targetPoint    438         G4Point3D cameraPosition = targetPoint + cameraDistance * fVP.GetViewpointDirection().unit();
439         G4Vector3D lightFrontToCameraDirection    439         G4Vector3D lightFrontToCameraDirection = cameraPosition - lightFrontCentre;
440         G4double lightFrontCentreDistance = li    440         G4double lightFrontCentreDistance = lightFrontToCameraDirection.mag();
441         /*                                        441         /*
442          G4cout << "cameraPosition: " << camer    442          G4cout << "cameraPosition: " << cameraPosition
443          << ", lightFrontCentre: " << lightFro    443          << ", lightFrontCentre: " << lightFrontCentre
444          << ", lightFrontRadius: " << lightFro    444          << ", lightFrontRadius: " << lightFrontRadius
445          << ", lightFrontCentreDistance: " <<     445          << ", lightFrontCentreDistance: " << lightFrontCentreDistance
446          << ", dot: " << lightFrontToCameraDir    446          << ", dot: " << lightFrontToCameraDirection * fVP.GetViewpointDirection()
447          << G4endl;                               447          << G4endl;
448          */                                       448          */
449         if (lightFrontToCameraDirection * fVP.    449         if (lightFrontToCameraDirection * fVP.GetViewpointDirection() > 0. && lightFrontRadius < lightFrontCentreDistance) {
450           // Light front in front of camera...    450           // Light front in front of camera...
451           G4double sineHorizonAngle = lightFro    451           G4double sineHorizonAngle = lightFrontRadius / lightFrontCentreDistance;
452           circleCentre = lightFrontCentre + (l    452           circleCentre = lightFrontCentre + (lightFrontRadius * sineHorizonAngle) * lightFrontToCameraDirection.unit();
453           circleRadius = lightFrontRadius * st    453           circleRadius = lightFrontRadius * std::sqrt(1. - std::pow(sineHorizonAngle, 2));
454           /*                                      454           /*
455            G4cout << "sineHorizonAngle: " << s    455            G4cout << "sineHorizonAngle: " << sineHorizonAngle
456            << ", circleCentre: " << circleCent    456            << ", circleCentre: " << circleCentre
457            << ", circleRadius: " << circleRadi    457            << ", circleRadius: " << circleRadius
458            << G4endl;                             458            << G4endl;
459            */                                     459            */
460         } else {                                  460         } else {
461           circleRadius = -1.;                     461           circleRadius = -1.;
462         }                                         462         }
463       }                                           463       }
464       if (circleRadius > 0.) {                    464       if (circleRadius > 0.) {
465         G4Circle lightFront(circleCentre);        465         G4Circle lightFront(circleCentre);
466         lightFront.SetWorldRadius(circleRadius    466         lightFront.SetWorldRadius(circleRadius);
467         G4VisAttributes visAtts(G4Colour          467         G4VisAttributes visAtts(G4Colour
468          (fDisplayLightFrontRed,                  468          (fDisplayLightFrontRed,
469           fDisplayLightFrontGreen,                469           fDisplayLightFrontGreen,
470           fDisplayLightFrontBlue));               470           fDisplayLightFrontBlue));
471         lightFront.SetVisAttributes(visAtts);     471         lightFront.SetVisAttributes(visAtts);
472         AddPrimitiveForASingleFrame(lightFront    472         AddPrimitiveForASingleFrame(lightFront);
473       }                                           473       }
474     }                                             474     }
475   }                                               475   }
476 }                                                 476 }
477                                                   477 
478 void G4OpenGLStoredViewer::AddPrimitiveForASin    478 void G4OpenGLStoredViewer::AddPrimitiveForASingleFrame(const G4Text& text)
479 {                                                 479 {
480   // We don't want this to get into a display     480   // We don't want this to get into a display list or a TODL or a PODL so
481   // use the fMemoryForDisplayLists flag.         481   // use the fMemoryForDisplayLists flag.
482   fG4OpenGLStoredSceneHandler.fDoNotUseDisplay    482   fG4OpenGLStoredSceneHandler.fDoNotUseDisplayList = true;
483   fG4OpenGLStoredSceneHandler.G4OpenGLStoredSc    483   fG4OpenGLStoredSceneHandler.G4OpenGLStoredSceneHandler::AddPrimitive(text);
484   fG4OpenGLStoredSceneHandler.fDoNotUseDisplay    484   fG4OpenGLStoredSceneHandler.fDoNotUseDisplayList = false;
485 }                                                 485 }
486                                                   486 
487 void G4OpenGLStoredViewer::AddPrimitiveForASin    487 void G4OpenGLStoredViewer::AddPrimitiveForASingleFrame(const G4Circle& circle)
488 {                                                 488 {
489   // We don't want this to get into a display     489   // We don't want this to get into a display list or a TODL or a PODL so
490   // use the fMemoryForDisplayLists flag.         490   // use the fMemoryForDisplayLists flag.
491   fG4OpenGLStoredSceneHandler.fDoNotUseDisplay    491   fG4OpenGLStoredSceneHandler.fDoNotUseDisplayList = true;
492   fG4OpenGLStoredSceneHandler.G4OpenGLStoredSc    492   fG4OpenGLStoredSceneHandler.G4OpenGLStoredSceneHandler::AddPrimitive(circle);
493   fG4OpenGLStoredSceneHandler.fDoNotUseDisplay    493   fG4OpenGLStoredSceneHandler.fDoNotUseDisplayList = false;
494 }                                                 494 }
495                                                   495