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