Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4RayTracerViewer.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: G4RayTracerViewer.cc 104015 2017-05-08 07:28:08Z gcosmo $
28 
29 #include "G4RayTracerViewer.hh"
30 
31 #include "G4ios.hh"
32 #include <sstream>
33 #include <iomanip>
34 
35 #include "G4SystemOfUnits.hh"
36 
37 #include "G4VSceneHandler.hh"
38 #include "G4Scene.hh"
39 #include "G4TheRayTracer.hh"
40 #include "G4UImanager.hh"
41 
43 (G4VSceneHandler& sceneHandler,
44  const G4String& name,
45  G4TheRayTracer* aTracer)
46 : G4VViewer(sceneHandler, sceneHandler.IncrementViewCount(), name)
47 , fFileCount(0)
48 , theTracer(aTracer)
49 {
50  if (!theTracer) {
51  G4cerr << "G4RayTracerViewer::Initialise: No tracer" << G4endl;
52  fViewId = -1; // This flags an error.
53  return;
54  }
55 }
56 
58 
60 {
63 }
64 
66 {
67  // Get radius of scene, etc. (See G4OpenGLViewer::SetView().)
68  // Note that this procedure properly takes into account zoom, dolly and pan.
69  const G4Point3D& targetPoint
72  G4double radius = // See G4ViewParameters for following procedure.
74  if(radius<=0.) radius = 1.;
75  const G4double cameraDistance = fVP.GetCameraDistance(radius);
76  const G4Point3D cameraPosition =
77  targetPoint + cameraDistance * fVP.GetViewpointDirection().unit();
78  const G4double nearDistance = fVP.GetNearDistance(cameraDistance,radius);
79  const G4double frontHalfHeight = fVP.GetFrontHalfHeight(nearDistance,radius);
80  const G4double frontHalfAngle = std::atan(frontHalfHeight / nearDistance);
81 
82  // Calculate and set ray tracer parameters.
83  theTracer->
84  SetViewSpan(200. * frontHalfAngle / theTracer->GetNColumn());
85  theTracer->SetTargetPosition(targetPoint);
86  theTracer->SetEyePosition(cameraPosition);
88  const G4Vector3D
89  actualLightpointDirection(-fVP.GetActualLightpointDirection());
90  theTracer->SetLightDirection(actualLightpointDirection);
92 }
93 
94 
96 
98 {
99  // Trap recursive call
100  static G4bool called = false;
101  if (called) return;
102  called = true;
103 
104  if (fVP.GetFieldHalfAngle() == 0.) { // Orthogonal (parallel) projection.
105  G4double fieldHalfAngle = perMillion;
106  fVP.SetFieldHalfAngle(fieldHalfAngle);
107  G4cout <<
108  "WARNING: G4RayTracerViewer::DrawView: true orthogonal projection"
109  "\n not yet implemented. Doing a \"long shot\", i.e., a perspective"
110  "\n projection with a half field angle of "
111  << fieldHalfAngle <<
112  " radians."
113  << G4endl;
114  SetView(); // With this fieldHalfAngle
115  ProcessView();
117  }
118  else {
119  ProcessView();
120  }
121  std::ostringstream filename;
122  filename << "g4RayTracer." << fShortName << '_'
123  << std::setw(4) << std::setfill('0') << fFileCount++ << ".jpeg";
124  theTracer->Trace(filename.str());
125 
126  // Reset call flag
127  called = false;
128 }
const XML_Char * name
Definition: expat.h:151
G4Vector3D & GetActualLightpointDirection()
void SetFieldHalfAngle(G4double fieldHalfAngle)
void SetTargetPosition(const G4ThreeVector &val)
unsigned int GetWindowSizeHintY() const
G4String fShortName
Definition: G4VViewer.hh:219
G4TheRayTracer * theTracer
const G4Point3D & GetCurrentTargetPoint() const
BasicVector3D< T > unit() const
#define G4endl
Definition: G4ios.hh:61
G4double GetFrontHalfHeight(G4double nearDistance, G4double radius) const
void SetEyePosition(const G4ThreeVector &val)
const G4Vector3D & GetUpVector() const
static constexpr double perMillion
Definition: G4SIunits.hh:334
G4int GetNColumn() const
G4ViewParameters fVP
Definition: G4VViewer.hh:220
G4double GetCameraDistance(G4double radius) const
const G4Vector3D & GetViewpointDirection() const
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
virtual void Trace(const G4String &fileName)
void SetBackgroundColour(const G4Colour &val)
virtual ~G4RayTracerViewer()
G4double GetFieldHalfAngle() const
Double_t radius
G4int IncrementViewCount()
G4GLOB_DLL std::ostream G4cerr
void SetNColumn(G4int val)
G4RayTracerViewer(G4VSceneHandler &, const G4String &name, G4TheRayTracer *=0)
void ProcessView()
Definition: G4VViewer.cc:105
G4double GetExtentRadius() const
Definition: G4VisExtent.cc:71
const G4Colour & GetBackgroundColour() const
G4VSceneHandler & fSceneHandler
Definition: G4VViewer.hh:216
void SetLightDirection(const G4ThreeVector &val)
G4GLOB_DLL std::ostream G4cout
const G4VisExtent & GetExtent() const
void SetNRow(G4int val)
G4double GetNearDistance(G4double cameraDistance, G4double radius) const
const G4Point3D & GetStandardTargetPoint() const
void SetUpVector(const G4ThreeVector &val)
unsigned int GetWindowSizeHintX() const
G4Scene * GetScene() const