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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 9.2.p4)


  1 //                                                  1 
  2 // *******************************************    
  3 // * License and Disclaimer                       
  4 // *                                              
  5 // * The  Geant4 software  is  copyright of th    
  6 // * the Geant4 Collaboration.  It is provided    
  7 // * conditions of the Geant4 Software License    
  8 // * LICENSE and available at  http://cern.ch/    
  9 // * include a list of copyright holders.         
 10 // *                                              
 11 // * Neither the authors of this software syst    
 12 // * institutes,nor the agencies providing fin    
 13 // * work  make  any representation or  warran    
 14 // * regarding  this  software system or assum    
 15 // * use.  Please see the license in the file     
 16 // * for the full disclaimer and the limitatio    
 17 // *                                              
 18 // * This  code  implementation is the result     
 19 // * technical work of the GEANT4 collaboratio    
 20 // * By using,  copying,  modifying or  distri    
 21 // * any work based  on the software)  you  ag    
 22 // * use  in  resulting  scientific  publicati    
 23 // * acceptance of all terms of the Geant4 Sof    
 24 // *******************************************    
 25 //                                                
 26 //                                                
 27 //                                                
 28 //                                                
 29 //                                                
 30                                                   
 31 ///////////////////////                           
 32 //G4RTRun.cc                                      
 33 ///////////////////////                           
 34                                                   
 35 #include "G4RTRun.hh"                             
 36 #include "G4TheMTRayTracer.hh"                    
 37                                                   
 38 #include "G4Colour.hh"                            
 39 #include "G4VisAttributes.hh"                     
 40 #include "G4Event.hh"                             
 41 #include "G4TrajectoryContainer.hh"               
 42                                                   
 43 #include "G4RayTrajectory.hh"                     
 44 #include "G4RayTrajectoryPoint.hh"                
 45                                                   
 46 G4RTRun::G4RTRun()                                
 47 {                                                 
 48   colorMap = new G4THitsMap<G4Colour>("G4RTRun    
 49                                                   
 50   backgroundColour = G4TheMTRayTracer::theInst    
 51   lightDirection = G4TheMTRayTracer::theInstan    
 52   attenuationLength = G4TheMTRayTracer::theIns    
 53 }                                                 
 54                                                   
 55 G4RTRun::~G4RTRun()                               
 56 {                                                 
 57   colorMap->clear();                              
 58   delete colorMap;                                
 59 }                                                 
 60                                                   
 61 void G4RTRun::RecordEvent(const G4Event* evt)     
 62 {                                                 
 63   G4TrajectoryContainer * trajectoryContainer     
 64   if(!trajectoryContainer) return;                
 65   G4RayTrajectory* trajectory = static_cast<G4    
 66   if(!trajectory) return;                         
 67                                                   
 68   G4int nPoint = trajectory->GetPointEntries()    
 69   if(nPoint==0) return;                           
 70                                                   
 71   G4int evId = evt->GetEventID();                 
 72   G4Colour initialCol(backgroundColour);          
 73   if( trajectory->GetPointC(nPoint-1)->GetPost    
 74   { initialCol = GetSurfaceColour(trajectory->    
 75   G4Colour rayColour = Attenuate(trajectory->G    
 76                                                   
 77   for(int i=nPoint-2;i>=0;i--)                    
 78   {                                               
 79     G4Colour surfaceCol = GetSurfaceColour(tra    
 80     G4double weight = 1.0 - surfaceCol.GetAlph    
 81     G4Colour mixedCol = GetMixedColour(rayColo    
 82     rayColour = Attenuate(trajectory->GetPoint    
 83   }                                               
 84                                                   
 85   colorMap->add(evId,rayColour);                  
 86 }                                                 
 87                                                   
 88 void G4RTRun::Merge(const G4Run* aLocalRun)       
 89 {                                                 
 90   const G4RTRun* theLocalRun = static_cast<con    
 91   if(theLocalRun) *(colorMap) += *(theLocalRun    
 92   G4Run::Merge(aLocalRun);                        
 93 }                                                 
 94                                                   
 95 G4Colour G4RTRun::GetSurfaceColour(G4RayTrajec    
 96 {                                                 
 97   const G4VisAttributes* preAtt = point->GetPr    
 98   const G4VisAttributes* postAtt = point->GetP    
 99                                                   
100   G4bool preVis = ValidColour(preAtt);            
101   G4bool postVis = ValidColour(postAtt);          
102                                                   
103   G4Colour transparent(1.,1.,1.,0.);              
104                                                   
105   if(!preVis&&!postVis) return transparent;       
106                                                   
107   G4ThreeVector normal = point->GetSurfaceNorm    
108                                                   
109   G4Colour preCol(1.,1.,1.);                      
110   G4Colour postCol(1.,1.,1.);                     
111                                                   
112   if(preVis)                                      
113   {                                               
114     G4double brill = (1.0-(-lightDirection).do    
115     G4double red   = preAtt->GetColour().GetRe    
116     G4double green = preAtt->GetColour().GetGr    
117     G4double blue  = preAtt->GetColour().GetBl    
118     preCol = G4Colour                             
119       (red*brill,green*brill,blue*brill,preAtt    
120   }                                               
121   else                                            
122   { preCol = transparent; }                       
123                                                   
124   if(postVis)                                     
125   {                                               
126     G4double brill = (1.0-(-lightDirection).do    
127     G4double red   = postAtt->GetColour().GetR    
128     G4double green = postAtt->GetColour().GetG    
129     G4double blue  = postAtt->GetColour().GetB    
130     postCol = G4Colour                            
131       (red*brill,green*brill,blue*brill,postAt    
132   }                                               
133   else                                            
134   { postCol = transparent; }                      
135                                                   
136   if(!preVis) return postCol;                     
137   if(!postVis) return preCol;                     
138                                                   
139   G4double weight = 0.5;                          
140   return GetMixedColour(preCol,postCol,weight)    
141 }                                                 
142                                                   
143 G4Colour G4RTRun::GetMixedColour(G4Colour surf    
144 {                                                 
145   G4double red   = weight*surfCol.GetRed() + (    
146   G4double green = weight*surfCol.GetGreen() +    
147   G4double blue  = weight*surfCol.GetBlue() +     
148   G4double alpha = weight*surfCol.GetAlpha() +    
149   return G4Colour(red,green,blue,alpha);          
150 }                                                 
151                                                   
152 G4Colour G4RTRun::Attenuate(G4RayTrajectoryPoi    
153 {                                                 
154   const G4VisAttributes* preAtt = point->GetPr    
155                                                   
156   G4bool visible = ValidColour(preAtt);           
157   if(!visible) return sourceCol;                  
158                                                   
159   G4Colour objCol = preAtt->GetColour();          
160   G4double stepRed = objCol.GetRed();             
161   G4double stepGreen = objCol.GetGreen();         
162   G4double stepBlue = objCol.GetBlue();           
163   G4double stepAlpha = objCol.GetAlpha();         
164   G4double stepLength = point->GetStepLength()    
165                                                   
166   G4double attenuationFuctor;                     
167   if(stepAlpha > 0.9999999){ stepAlpha = 0.999    
168     attenuationFuctor = -stepAlpha/(1.0-stepAl    
169                                                   
170   G4double KtRed = std::exp((1.0-stepRed)*atte    
171   G4double KtGreen = std::exp((1.0-stepGreen)*    
172   G4double KtBlue = std::exp((1.0-stepBlue)*at    
173   if(KtRed>1.0){KtRed=1.0;}                       
174   if(KtGreen>1.0){KtGreen=1.0;}                   
175   if(KtBlue>1.0){KtBlue=1.0;}                     
176   return G4Colour(sourceCol.GetRed()*KtRed,       
177     sourceCol.GetGreen()*KtGreen,sourceCol.Get    
178 }                                                 
179                                                   
180 G4bool G4RTRun::ValidColour(const G4VisAttribu    
181 {                                                 
182   G4bool val = true;                              
183   if(!visAtt)                                     
184   { val = false; }                                
185   else if(!(visAtt->IsVisible()))                 
186   { val = false; }                                
187   else if(visAtt->IsForceDrawingStyle()           
188     &&(visAtt->GetForcedDrawingStyle()==G4VisA    
189   { val = false; }                                
190   return val;                                     
191 }                                                 
192                                                   
193                                                   
194