Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4RTRun.cc
이 파일의 문서화 페이지로 가기
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 // $Id: G4RTRun.cc 66264 2012-12-14 10:17:44Z allison $
28 //
29 //
30 //
31 
33 //G4RTRun.cc
35 
36 #include "G4RTRun.hh"
37 #include "G4TheMTRayTracer.hh"
38 
39 #include "G4Colour.hh"
40 #include "G4VisAttributes.hh"
41 #include "G4Event.hh"
42 #include "G4TrajectoryContainer.hh"
43 
44 #include "G4RayTrajectory.hh"
45 #include "G4RayTrajectoryPoint.hh"
46 
48 {
49  colorMap = new G4THitsMap<G4Colour>("G4RTRun","ColorMap");
50 
54 }
55 
57 {
58  colorMap->clear();
59  delete colorMap;
60 }
61 
62 void G4RTRun::RecordEvent(const G4Event* evt)
63 {
64  G4TrajectoryContainer * trajectoryContainer = evt->GetTrajectoryContainer();
65  if(!trajectoryContainer) return;
66  G4RayTrajectory* trajectory = static_cast<G4RayTrajectory*>( (*trajectoryContainer)[0] );
67  if(!trajectory) return;
68 
69  G4int nPoint = trajectory->GetPointEntries();
70  if(nPoint==0) return;
71 
72  G4int evId = evt->GetEventID();
73  G4Colour initialCol(backgroundColour);
74  if( trajectory->GetPointC(nPoint-1)->GetPostStepAtt() )
75  { initialCol = GetSurfaceColour(trajectory->GetPointC(nPoint-1)); }
76  G4Colour rayColour = Attenuate(trajectory->GetPointC(nPoint-1),initialCol);
77 
78  for(int i=nPoint-2;i>=0;i--)
79  {
80  G4Colour surfaceCol = GetSurfaceColour(trajectory->GetPointC(i));
81  G4double weight = 1.0 - surfaceCol.GetAlpha();
82  G4Colour mixedCol = GetMixedColour(rayColour,surfaceCol,weight);
83  rayColour = Attenuate(trajectory->GetPointC(i),mixedCol);
84  }
85 
86  colorMap->add(evId,rayColour);
87 }
88 
89 void G4RTRun::Merge(const G4Run* aLocalRun)
90 {
91  const G4RTRun* theLocalRun = static_cast<const G4RTRun*>(aLocalRun);
92  if(theLocalRun) *(colorMap) += *(theLocalRun->colorMap);
93  G4Run::Merge(aLocalRun);
94 }
95 
97 {
98  const G4VisAttributes* preAtt = point->GetPreStepAtt();
99  const G4VisAttributes* postAtt = point->GetPostStepAtt();
100 
101  G4bool preVis = ValidColour(preAtt);
102  G4bool postVis = ValidColour(postAtt);
103 
104  G4Colour transparent(1.,1.,1.,0.);
105 
106  if(!preVis&&!postVis) return transparent;
107 
109 
110  G4Colour preCol(1.,1.,1.);
111  G4Colour postCol(1.,1.,1.);
112 
113  if(preVis)
114  {
115  G4double brill = (1.0-(-lightDirection).dot(normal))/2.0;
116  G4double red = preAtt->GetColour().GetRed();
117  G4double green = preAtt->GetColour().GetGreen();
118  G4double blue = preAtt->GetColour().GetBlue();
119  preCol = G4Colour
120  (red*brill,green*brill,blue*brill,preAtt->GetColour().GetAlpha());
121  }
122  else
123  { preCol = transparent; }
124 
125  if(postVis)
126  {
127  G4double brill = (1.0-(-lightDirection).dot(-normal))/2.0;
128  G4double red = postAtt->GetColour().GetRed();
129  G4double green = postAtt->GetColour().GetGreen();
130  G4double blue = postAtt->GetColour().GetBlue();
131  postCol = G4Colour
132  (red*brill,green*brill,blue*brill,postAtt->GetColour().GetAlpha());
133  }
134  else
135  { postCol = transparent; }
136 
137  if(!preVis) return postCol;
138  if(!postVis) return preCol;
139 
140  G4double weight = 0.5;
141  return GetMixedColour(preCol,postCol,weight);
142 }
143 
145 {
146  G4double red = weight*surfCol.GetRed() + (1.-weight)*transCol.GetRed();
147  G4double green = weight*surfCol.GetGreen() + (1.-weight)*transCol.GetGreen();
148  G4double blue = weight*surfCol.GetBlue() + (1.-weight)*transCol.GetBlue();
149  G4double alpha = weight*surfCol.GetAlpha() + (1.-weight)*transCol.GetAlpha();
150  return G4Colour(red,green,blue,alpha);
151 }
152 
154 {
155  const G4VisAttributes* preAtt = point->GetPreStepAtt();
156 
157  G4bool visible = ValidColour(preAtt);
158  if(!visible) return sourceCol;
159 
160  G4Colour objCol = preAtt->GetColour();
161  G4double stepRed = objCol.GetRed();
162  G4double stepGreen = objCol.GetGreen();
163  G4double stepBlue = objCol.GetBlue();
164  G4double stepAlpha = objCol.GetAlpha();
165  G4double stepLength = point->GetStepLength();
166 
167  G4double attenuationFuctor;
168  if(stepAlpha > 0.9999999){ stepAlpha = 0.9999999; } // patch to the next line
169  attenuationFuctor = -stepAlpha/(1.0-stepAlpha)*stepLength/attenuationLength;
170 
171  G4double KtRed = std::exp((1.0-stepRed)*attenuationFuctor);
172  G4double KtGreen = std::exp((1.0-stepGreen)*attenuationFuctor);
173  G4double KtBlue = std::exp((1.0-stepBlue)*attenuationFuctor);
174  if(KtRed>1.0){KtRed=1.0;}
175  if(KtGreen>1.0){KtGreen=1.0;}
176  if(KtBlue>1.0){KtBlue=1.0;}
177  return G4Colour(sourceCol.GetRed()*KtRed,
178  sourceCol.GetGreen()*KtGreen,sourceCol.GetBlue()*KtBlue);
179 }
180 
182 {
183  G4bool val = true;
184  if(!visAtt)
185  { val = false; }
186  else if(!(visAtt->IsVisible()))
187  { val = false; }
188  else if(visAtt->IsForceDrawingStyle()
190  { val = false; }
191  return val;
192 }
193 
194 
G4THitsMap< G4Colour > * colorMap
Definition: G4RTRun.hh:61
G4ThreeVector lightDirection
G4bool ValidColour(const G4VisAttributes *)
Definition: G4RTRun.cc:181
Definition: test07.cc:36
G4int GetEventID() const
Definition: G4Event.hh:151
G4int add(const G4int &key, U *&aHit) const
Definition: G4THitsMap.hh:150
G4ThreeVector GetSurfaceNormal() const
ForcedDrawingStyle GetForcedDrawingStyle() const
static double normal(HepRandomEngine *eptr)
Definition: RandPoisson.cc:77
G4bool IsVisible() const
virtual void Merge(const G4Run *)
Definition: G4RTRun.cc:89
G4RayTrajectoryPoint * GetPointC(G4int i) const
G4ThreeVector lightDirection
Definition: G4RTRun.hh:68
G4double GetStepLength() const
Definition: test07.cc:36
virtual int GetPointEntries() const
G4RTRun()
Definition: G4RTRun.cc:47
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
G4double attenuationLength
Definition: G4RTRun.hh:69
G4Colour backgroundColour
G4TrajectoryContainer * GetTrajectoryContainer() const
Definition: G4Event.hh:189
static const G4double alpha
static G4TheMTRayTracer * theInstance
virtual void RecordEvent(const G4Event *)
Definition: G4RTRun.cc:62
void clear()
Definition: G4THitsMap.hh:510
virtual ~G4RTRun()
Definition: G4RTRun.cc:56
G4double GetRed() const
Definition: G4Colour.hh:151
G4double attenuationLength
Definition: G4Run.hh:46
const G4VisAttributes * GetPostStepAtt() const
double weight
Definition: plottest35.C:25
int G4int
Definition: G4Types.hh:78
G4bool IsForceDrawingStyle() const
G4Colour backgroundColour
Definition: G4RTRun.hh:67
const G4VisAttributes * GetPreStepAtt() const
G4double GetAlpha() const
Definition: G4Colour.hh:154
G4double GetBlue() const
Definition: G4Colour.hh:153
G4double GetGreen() const
Definition: G4Colour.hh:152
virtual void Merge(const G4Run *)
Definition: G4Run.cc:54
G4Colour GetSurfaceColour(G4RayTrajectoryPoint *)
Definition: G4RTRun.cc:96
G4Colour GetMixedColour(G4Colour, G4Colour, G4double)
Definition: G4RTRun.cc:144
const G4Colour & GetColour() const
G4Colour Attenuate(G4RayTrajectoryPoint *, G4Colour)
Definition: G4RTRun.cc:153