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