Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4RTRun.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
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"
42
43#include "G4RayTrajectory.hh"
45
47{
48 colorMap = new G4THitsMap<G4Colour>("G4RTRun","ColorMap");
49
50 backgroundColour = G4TheMTRayTracer::theInstance->backgroundColour;
51 lightDirection = G4TheMTRayTracer::theInstance->lightDirection;
52 attenuationLength = G4TheMTRayTracer::theInstance->attenuationLength;
53}
54
56{
57 colorMap->clear();
58 delete colorMap;
59}
60
62{
63 G4TrajectoryContainer * trajectoryContainer = evt->GetTrajectoryContainer();
64 if(!trajectoryContainer) return;
65 G4RayTrajectory* trajectory = static_cast<G4RayTrajectory*>( (*trajectoryContainer)[0] );
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)->GetPostStepAtt() )
74 { initialCol = GetSurfaceColour(trajectory->GetPointC(nPoint-1)); }
75 G4Colour rayColour = Attenuate(trajectory->GetPointC(nPoint-1),initialCol);
76
77 for(int i=nPoint-2;i>=0;i--)
78 {
79 G4Colour surfaceCol = GetSurfaceColour(trajectory->GetPointC(i));
80 G4double weight = 1.0 - surfaceCol.GetAlpha();
81 G4Colour mixedCol = GetMixedColour(rayColour,surfaceCol,weight);
82 rayColour = Attenuate(trajectory->GetPointC(i),mixedCol);
83 }
84
85 colorMap->add(evId,rayColour);
86}
87
88void G4RTRun::Merge(const G4Run* aLocalRun)
89{
90 const G4RTRun* theLocalRun = static_cast<const G4RTRun*>(aLocalRun);
91 if(theLocalRun) *(colorMap) += *(theLocalRun->colorMap);
92 G4Run::Merge(aLocalRun);
93}
94
95G4Colour G4RTRun::GetSurfaceColour(G4RayTrajectoryPoint* point)
96{
97 const G4VisAttributes* preAtt = point->GetPreStepAtt();
98 const G4VisAttributes* postAtt = point->GetPostStepAtt();
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->GetSurfaceNormal();
108
109 G4Colour preCol(1.,1.,1.);
110 G4Colour postCol(1.,1.,1.);
111
112 if(preVis)
113 {
114 G4double brill = (1.0-(-lightDirection).dot(normal))/2.0;
115 G4double red = preAtt->GetColour().GetRed();
116 G4double green = preAtt->GetColour().GetGreen();
117 G4double blue = preAtt->GetColour().GetBlue();
118 preCol = G4Colour
119 (red*brill,green*brill,blue*brill,preAtt->GetColour().GetAlpha());
120 }
121 else
122 { preCol = transparent; }
123
124 if(postVis)
125 {
126 G4double brill = (1.0-(-lightDirection).dot(-normal))/2.0;
127 G4double red = postAtt->GetColour().GetRed();
128 G4double green = postAtt->GetColour().GetGreen();
129 G4double blue = postAtt->GetColour().GetBlue();
130 postCol = G4Colour
131 (red*brill,green*brill,blue*brill,postAtt->GetColour().GetAlpha());
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
143G4Colour G4RTRun::GetMixedColour(G4Colour surfCol,G4Colour transCol,G4double weight)
144{
145 G4double red = weight*surfCol.GetRed() + (1.-weight)*transCol.GetRed();
146 G4double green = weight*surfCol.GetGreen() + (1.-weight)*transCol.GetGreen();
147 G4double blue = weight*surfCol.GetBlue() + (1.-weight)*transCol.GetBlue();
148 G4double alpha = weight*surfCol.GetAlpha() + (1.-weight)*transCol.GetAlpha();
149 return G4Colour(red,green,blue,alpha);
150}
151
152G4Colour G4RTRun::Attenuate(G4RayTrajectoryPoint* point, G4Colour sourceCol)
153{
154 const G4VisAttributes* preAtt = point->GetPreStepAtt();
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.9999999; } // patch to the next line
168 attenuationFuctor = -stepAlpha/(1.0-stepAlpha)*stepLength/attenuationLength;
169
170 G4double KtRed = std::exp((1.0-stepRed)*attenuationFuctor);
171 G4double KtGreen = std::exp((1.0-stepGreen)*attenuationFuctor);
172 G4double KtBlue = std::exp((1.0-stepBlue)*attenuationFuctor);
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.GetBlue()*KtBlue);
178}
179
180G4bool G4RTRun::ValidColour(const G4VisAttributes* visAtt)
181{
182 G4bool val = true;
183 if(!visAtt)
184 { val = false; }
185 else if(!(visAtt->IsVisible()))
186 { val = false; }
187 else if(visAtt->IsForceDrawingStyle()
189 { val = false; }
190 return val;
191}
192
193
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
G4double GetBlue() const
Definition: G4Colour.hh:152
G4double GetAlpha() const
Definition: G4Colour.hh:153
G4double GetRed() const
Definition: G4Colour.hh:150
G4double GetGreen() const
Definition: G4Colour.hh:151
G4TrajectoryContainer * GetTrajectoryContainer() const
Definition: G4Event.hh:160
G4int GetEventID() const
Definition: G4Event.hh:118
virtual ~G4RTRun()
Definition: G4RTRun.cc:55
virtual void RecordEvent(const G4Event *)
Definition: G4RTRun.cc:61
virtual void Merge(const G4Run *)
Definition: G4RTRun.cc:88
G4RTRun()
Definition: G4RTRun.cc:46
G4ThreeVector GetSurfaceNormal() const
const G4VisAttributes * GetPostStepAtt() const
G4double GetStepLength() const
const G4VisAttributes * GetPreStepAtt() const
virtual int GetPointEntries() const
G4RayTrajectoryPoint * GetPointC(G4int i) const
Definition: G4Run.hh:49
virtual void Merge(const G4Run *)
Definition: G4Run.cc:64
G4ThreeVector lightDirection
G4Colour backgroundColour
G4double attenuationLength
void clear()
Definition: G4THitsMap.hh:537
size_t add(const G4int &key, U *&aHit) const
Definition: G4THitsMap.hh:177
const G4Colour & GetColour() const
G4bool IsVisible() const
ForcedDrawingStyle GetForcedDrawingStyle() const
G4bool IsForceDrawingStyle() const