ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4VRML2FileViewer.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4VRML2FileViewer.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 //
28 // G4VRML2FileViewer.cc
29 // Satoshi Tanaka & Yasuhide Sawada
30 
31 
32 //#define DEBUG_FR_VIEW
33 
34 #include <cmath>
35 
36 #include "G4VisManager.hh"
37 #include "G4Scene.hh"
38 #include "G4VRML2FileViewer.hh"
40 #include "G4VRML2File.hh"
41 #include "G4SystemOfUnits.hh"
42 #include "G4ios.hh"
43 
45  const G4String& name) :
46  G4VViewer(sceneHandler,
47  sceneHandler.IncrementViewCount(),
48  name),
49  fSceneHandler(sceneHandler),
50  fDest(sceneHandler.fDest)
51 {
52  fViewHalfAngle = 30. * deg;
53  fsin_VHA = std::sin ( fViewHalfAngle ) ;
54 }
55 
57 {}
58 
60 {
61 #if defined DEBUG_FR_VIEW
63  G4cout << "***** G4VRML2FileViewer::SetView(): No effects" << G4endl;
64 #endif
65 
66 // Do nothing, since VRML a browser is running as a different process.
67 // SendViewParameters () will do this job instead.
68 
69 }
70 
72 {
73 #if defined DEBUG_FR_VIEW
75  G4cout << "***** G4VRML2FileViewer::DrawView()" << G4endl;
76 #endif
77 
79 
80  // Viewpoint node
82 
83  // Here is a minimal DrawView() function.
85  ProcessView();
86  FinishView();
87 }
88 
90 {
91 #if defined DEBUG_FR_VIEW
93  G4cout << "***** G4VRML2File1View::ClearView()" << G4endl;
94 #endif
96  fSceneHandler.fDest.close();
97  // Re-open with same filename...
99  fSceneHandler.fDest << "#VRML V2.0 utf8" << "\n";
100  fSceneHandler.fDest << "# Generated by VRML 2.0 driver of GEANT4\n" << "\n";
101  }
102 }
103 
105 {
106 #if defined DEBUG_FR_VIEW
108  G4cout << "***** G4VRML2FileViewer::ShowView()" << G4endl;
109 #endif
111 }
112 
114 {
115 #if defined DEBUG_FR_VIEW
117  G4cout << "***** G4VRML2FileViewer::FinishView(): No effects" << G4endl;
118 #endif
119 }
120 
122 {
123  // Calculates view representation based on extent of object being
124  // viewed and (initial) direction of camera. (Note: it can change
125  // later due to user interaction via visualization system's GUI.)
126 
127 #if defined DEBUG_FR_VIEW
129  G4cout << "***** G4VRML2FileViewer::SendViewParameters()\n";
130 #endif
131 
132  // error recovery
133  if ( fsin_VHA < 1.0e-6 ) { return ; }
134 
135  // camera distance
137  G4double camera_distance = extent_radius / fsin_VHA ;
138 
139  // camera position on Z axis
140  const G4Point3D& target_point
143  G4double E_z = target_point.z() + camera_distance;
144  G4Point3D E(0.0, 0.0, E_z );
145 
146  // VRML codes are generated below
147  fDest << G4endl;
148  fDest << "#---------- CAMERA" << G4endl;
149  fDest << "Viewpoint {" << G4endl;
150  fDest << "\t" << "position " ;
151  fDest << E.x() << " " ;
152  fDest << E.y() << " " ;
153  fDest << E.z() << G4endl ;
154  fDest << "}" << G4endl;
155  fDest << G4endl;
156 
157 }