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] [ 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/RayTracer/src/G4RTRun.cc (Version 11.3.0) and /visualization/RayTracer/src/G4RTRun.cc (Version 10.0.p4)


  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 // $Id: G4RTRun.cc 66264 2012-12-14 10:17:44Z allison $
 27 //                                                 28 //
 28 //                                                 29 //
 29 //                                                 30 //
 30                                                    31 
 31 ///////////////////////                            32 ///////////////////////
 32 //G4RTRun.cc                                       33 //G4RTRun.cc
 33 ///////////////////////                            34 ///////////////////////
 34                                                    35 
                                                   >>  36 #include "G4RTRun.hh"
 35 #include "G4RTRun.hh"                              37 #include "G4RTRun.hh"
 36 #include "G4TheMTRayTracer.hh"                     38 #include "G4TheMTRayTracer.hh"
 37                                                    39 
 38 #include "G4Colour.hh"                             40 #include "G4Colour.hh"
 39 #include "G4VisAttributes.hh"                      41 #include "G4VisAttributes.hh"
 40 #include "G4Event.hh"                              42 #include "G4Event.hh"
 41 #include "G4TrajectoryContainer.hh"                43 #include "G4TrajectoryContainer.hh"
 42                                                    44 
 43 #include "G4RayTrajectory.hh"                      45 #include "G4RayTrajectory.hh"
 44 #include "G4RayTrajectoryPoint.hh"                 46 #include "G4RayTrajectoryPoint.hh"
 45                                                    47 
 46 G4RTRun::G4RTRun()                                 48 G4RTRun::G4RTRun()
 47 {                                                  49 {
 48   colorMap = new G4THitsMap<G4Colour>("G4RTRun     50   colorMap = new G4THitsMap<G4Colour>("G4RTRun","ColorMap");
 49                                                    51 
 50   backgroundColour = G4TheMTRayTracer::theInst     52   backgroundColour = G4TheMTRayTracer::theInstance->backgroundColour;
 51   lightDirection = G4TheMTRayTracer::theInstan     53   lightDirection = G4TheMTRayTracer::theInstance->lightDirection;
 52   attenuationLength = G4TheMTRayTracer::theIns     54   attenuationLength = G4TheMTRayTracer::theInstance->attenuationLength;
 53 }                                                  55 }
 54                                                    56 
 55 G4RTRun::~G4RTRun()                                57 G4RTRun::~G4RTRun()
 56 {                                                  58 { 
 57   colorMap->clear();                               59   colorMap->clear();
 58   delete colorMap;                                 60   delete colorMap;
 59 }                                                  61 }
 60                                                    62 
 61 void G4RTRun::RecordEvent(const G4Event* evt)      63 void G4RTRun::RecordEvent(const G4Event* evt)
 62 {                                                  64 {
 63   G4TrajectoryContainer * trajectoryContainer      65   G4TrajectoryContainer * trajectoryContainer = evt->GetTrajectoryContainer();
 64   if(!trajectoryContainer) return;                 66   if(!trajectoryContainer) return;
 65   G4RayTrajectory* trajectory = static_cast<G4     67   G4RayTrajectory* trajectory = static_cast<G4RayTrajectory*>( (*trajectoryContainer)[0] );
 66   if(!trajectory) return;                          68   if(!trajectory) return;
 67                                                    69 
 68   G4int nPoint = trajectory->GetPointEntries()     70   G4int nPoint = trajectory->GetPointEntries();
 69   if(nPoint==0) return;                            71   if(nPoint==0) return;
 70                                                    72 
 71   G4int evId = evt->GetEventID();                  73   G4int evId = evt->GetEventID();
 72   G4Colour initialCol(backgroundColour);           74   G4Colour initialCol(backgroundColour);
 73   if( trajectory->GetPointC(nPoint-1)->GetPost     75   if( trajectory->GetPointC(nPoint-1)->GetPostStepAtt() )
 74   { initialCol = GetSurfaceColour(trajectory->     76   { initialCol = GetSurfaceColour(trajectory->GetPointC(nPoint-1)); }
 75   G4Colour rayColour = Attenuate(trajectory->G     77   G4Colour rayColour = Attenuate(trajectory->GetPointC(nPoint-1),initialCol);
 76                                                    78 
 77   for(int i=nPoint-2;i>=0;i--)                     79   for(int i=nPoint-2;i>=0;i--)
 78   {                                                80   {
 79     G4Colour surfaceCol = GetSurfaceColour(tra     81     G4Colour surfaceCol = GetSurfaceColour(trajectory->GetPointC(i));
 80     G4double weight = 1.0 - surfaceCol.GetAlph     82     G4double weight = 1.0 - surfaceCol.GetAlpha();
 81     G4Colour mixedCol = GetMixedColour(rayColo     83     G4Colour mixedCol = GetMixedColour(rayColour,surfaceCol,weight);
 82     rayColour = Attenuate(trajectory->GetPoint     84     rayColour = Attenuate(trajectory->GetPointC(i),mixedCol);
 83   }                                                85   }
 84                                                    86 
 85   colorMap->add(evId,rayColour);                   87   colorMap->add(evId,rayColour);
 86 }                                                  88 }
 87                                                    89 
 88 void G4RTRun::Merge(const G4Run* aLocalRun)        90 void G4RTRun::Merge(const G4Run* aLocalRun)
 89 {                                                  91 {
 90   const G4RTRun* theLocalRun = static_cast<con     92   const G4RTRun* theLocalRun = static_cast<const G4RTRun*>(aLocalRun);
 91   if(theLocalRun) *(colorMap) += *(theLocalRun     93   if(theLocalRun) *(colorMap) += *(theLocalRun->colorMap);
 92   G4Run::Merge(aLocalRun);                         94   G4Run::Merge(aLocalRun);
 93 }                                                  95 }
 94                                                    96 
 95 G4Colour G4RTRun::GetSurfaceColour(G4RayTrajec     97 G4Colour G4RTRun::GetSurfaceColour(G4RayTrajectoryPoint* point)
 96 {                                                  98 {
 97   const G4VisAttributes* preAtt = point->GetPr     99   const G4VisAttributes* preAtt = point->GetPreStepAtt();
 98   const G4VisAttributes* postAtt = point->GetP    100   const G4VisAttributes* postAtt = point->GetPostStepAtt();
 99                                                   101 
100   G4bool preVis = ValidColour(preAtt);            102   G4bool preVis = ValidColour(preAtt);
101   G4bool postVis = ValidColour(postAtt);          103   G4bool postVis = ValidColour(postAtt);
102                                                   104 
103   G4Colour transparent(1.,1.,1.,0.);              105   G4Colour transparent(1.,1.,1.,0.);
104                                                   106 
105   if(!preVis&&!postVis) return transparent;       107   if(!preVis&&!postVis) return transparent;
106                                                   108 
107   G4ThreeVector normal = point->GetSurfaceNorm    109   G4ThreeVector normal = point->GetSurfaceNormal();
108                                                   110 
109   G4Colour preCol(1.,1.,1.);                      111   G4Colour preCol(1.,1.,1.);
110   G4Colour postCol(1.,1.,1.);                     112   G4Colour postCol(1.,1.,1.);
111                                                   113 
112   if(preVis)                                      114   if(preVis)
113   {                                               115   {
114     G4double brill = (1.0-(-lightDirection).do    116     G4double brill = (1.0-(-lightDirection).dot(normal))/2.0;
115     G4double red   = preAtt->GetColour().GetRe    117     G4double red   = preAtt->GetColour().GetRed();
116     G4double green = preAtt->GetColour().GetGr    118     G4double green = preAtt->GetColour().GetGreen();
117     G4double blue  = preAtt->GetColour().GetBl    119     G4double blue  = preAtt->GetColour().GetBlue();
118     preCol = G4Colour                             120     preCol = G4Colour
119       (red*brill,green*brill,blue*brill,preAtt    121       (red*brill,green*brill,blue*brill,preAtt->GetColour().GetAlpha());
120   }                                               122   }
121   else                                            123   else
122   { preCol = transparent; }                       124   { preCol = transparent; }
123                                                   125 
124   if(postVis)                                     126   if(postVis)
125   {                                               127   {
126     G4double brill = (1.0-(-lightDirection).do    128     G4double brill = (1.0-(-lightDirection).dot(-normal))/2.0;
127     G4double red   = postAtt->GetColour().GetR    129     G4double red   = postAtt->GetColour().GetRed();
128     G4double green = postAtt->GetColour().GetG    130     G4double green = postAtt->GetColour().GetGreen();
129     G4double blue  = postAtt->GetColour().GetB    131     G4double blue  = postAtt->GetColour().GetBlue();
130     postCol = G4Colour                            132     postCol = G4Colour
131       (red*brill,green*brill,blue*brill,postAt    133       (red*brill,green*brill,blue*brill,postAtt->GetColour().GetAlpha());
132   }                                               134   }
133   else                                            135   else
134   { postCol = transparent; }                      136   { postCol = transparent; }
135                                                   137 
136   if(!preVis) return postCol;                     138   if(!preVis) return postCol;
137   if(!postVis) return preCol;                     139   if(!postVis) return preCol;
138                                                   140 
139   G4double weight = 0.5;                          141   G4double weight = 0.5;
140   return GetMixedColour(preCol,postCol,weight)    142   return GetMixedColour(preCol,postCol,weight);
141 }                                                 143 }
142                                                   144 
143 G4Colour G4RTRun::GetMixedColour(G4Colour surf    145 G4Colour G4RTRun::GetMixedColour(G4Colour surfCol,G4Colour transCol,G4double weight)
144 {                                                 146 {
145   G4double red   = weight*surfCol.GetRed() + (    147   G4double red   = weight*surfCol.GetRed() + (1.-weight)*transCol.GetRed();
146   G4double green = weight*surfCol.GetGreen() +    148   G4double green = weight*surfCol.GetGreen() + (1.-weight)*transCol.GetGreen();
147   G4double blue  = weight*surfCol.GetBlue() +     149   G4double blue  = weight*surfCol.GetBlue() + (1.-weight)*transCol.GetBlue();
148   G4double alpha = weight*surfCol.GetAlpha() +    150   G4double alpha = weight*surfCol.GetAlpha() + (1.-weight)*transCol.GetAlpha();
149   return G4Colour(red,green,blue,alpha);          151   return G4Colour(red,green,blue,alpha);
150 }                                                 152 }
151                                                   153 
152 G4Colour G4RTRun::Attenuate(G4RayTrajectoryPoi    154 G4Colour G4RTRun::Attenuate(G4RayTrajectoryPoint* point, G4Colour sourceCol)
153 {                                                 155 {
154   const G4VisAttributes* preAtt = point->GetPr    156   const G4VisAttributes* preAtt = point->GetPreStepAtt();
155                                                   157 
156   G4bool visible = ValidColour(preAtt);           158   G4bool visible = ValidColour(preAtt);
157   if(!visible) return sourceCol;                  159   if(!visible) return sourceCol;
158                                                   160 
159   G4Colour objCol = preAtt->GetColour();          161   G4Colour objCol = preAtt->GetColour();
160   G4double stepRed = objCol.GetRed();             162   G4double stepRed = objCol.GetRed();
161   G4double stepGreen = objCol.GetGreen();         163   G4double stepGreen = objCol.GetGreen();
162   G4double stepBlue = objCol.GetBlue();           164   G4double stepBlue = objCol.GetBlue();
163   G4double stepAlpha = objCol.GetAlpha();         165   G4double stepAlpha = objCol.GetAlpha();
164   G4double stepLength = point->GetStepLength()    166   G4double stepLength = point->GetStepLength();
165                                                   167 
166   G4double attenuationFuctor;                     168   G4double attenuationFuctor;
167   if(stepAlpha > 0.9999999){ stepAlpha = 0.999    169   if(stepAlpha > 0.9999999){ stepAlpha = 0.9999999; } // patch to the next line
168     attenuationFuctor = -stepAlpha/(1.0-stepAl    170     attenuationFuctor = -stepAlpha/(1.0-stepAlpha)*stepLength/attenuationLength;
169                                                   171 
170   G4double KtRed = std::exp((1.0-stepRed)*atte    172   G4double KtRed = std::exp((1.0-stepRed)*attenuationFuctor);
171   G4double KtGreen = std::exp((1.0-stepGreen)*    173   G4double KtGreen = std::exp((1.0-stepGreen)*attenuationFuctor);
172   G4double KtBlue = std::exp((1.0-stepBlue)*at    174   G4double KtBlue = std::exp((1.0-stepBlue)*attenuationFuctor);
173   if(KtRed>1.0){KtRed=1.0;}                       175   if(KtRed>1.0){KtRed=1.0;}
174   if(KtGreen>1.0){KtGreen=1.0;}                   176   if(KtGreen>1.0){KtGreen=1.0;}
175   if(KtBlue>1.0){KtBlue=1.0;}                     177   if(KtBlue>1.0){KtBlue=1.0;}
176   return G4Colour(sourceCol.GetRed()*KtRed,       178   return G4Colour(sourceCol.GetRed()*KtRed,
177     sourceCol.GetGreen()*KtGreen,sourceCol.Get    179     sourceCol.GetGreen()*KtGreen,sourceCol.GetBlue()*KtBlue);
178 }                                                 180 }
179                                                   181 
180 G4bool G4RTRun::ValidColour(const G4VisAttribu    182 G4bool G4RTRun::ValidColour(const G4VisAttributes* visAtt)
181 {                                                 183 {
182   G4bool val = true;                              184   G4bool val = true;
183   if(!visAtt)                                     185   if(!visAtt)
184   { val = false; }                                186   { val = false; }
185   else if(!(visAtt->IsVisible()))                 187   else if(!(visAtt->IsVisible()))
186   { val = false; }                                188   { val = false; }
187   else if(visAtt->IsForceDrawingStyle()           189   else if(visAtt->IsForceDrawingStyle()
188     &&(visAtt->GetForcedDrawingStyle()==G4VisA    190     &&(visAtt->GetForcedDrawingStyle()==G4VisAttributes::wireframe))
189   { val = false; }                                191   { val = false; }
190   return val;                                     192   return val;
191 }                                                 193 }
192                                                   194 
193                                                   195 
194                                                   196