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: G4VRML2FileViewer.cc,v 1.13 2006/06/29 21:26:13 gunter Exp $ |
---|
28 | // GEANT4 tag $Name: $ |
---|
29 | // |
---|
30 | // G4VRML2FileViewer.cc |
---|
31 | // Satoshi Tanaka & Yasuhide Sawada |
---|
32 | |
---|
33 | |
---|
34 | //#define DEBUG_FR_VIEW |
---|
35 | |
---|
36 | #include <cmath> |
---|
37 | |
---|
38 | #include "G4Scene.hh" |
---|
39 | #include "G4VRML2FileViewer.hh" |
---|
40 | #include "G4VRML2FileSceneHandler.hh" |
---|
41 | #include "G4VRML2File.hh" |
---|
42 | #include "G4ios.hh" |
---|
43 | |
---|
44 | G4VRML2FileViewer::G4VRML2FileViewer(G4VRML2FileSceneHandler& sceneHandler, |
---|
45 | const G4String& name) : |
---|
46 | G4VViewer(sceneHandler, |
---|
47 | sceneHandler.IncrementViewCount(), |
---|
48 | name), |
---|
49 | fSceneHandler(sceneHandler), |
---|
50 | fDest(sceneHandler.fDest) |
---|
51 | { |
---|
52 | fViewHalfAngle = 0.5 * 0.785398 ; // 0.5 * 45*deg |
---|
53 | fsin_VHA = std::sin ( fViewHalfAngle ) ; |
---|
54 | } |
---|
55 | |
---|
56 | G4VRML2FileViewer::~G4VRML2FileViewer() |
---|
57 | {} |
---|
58 | |
---|
59 | void G4VRML2FileViewer::SetView() |
---|
60 | { |
---|
61 | #if defined DEBUG_FR_VIEW |
---|
62 | G4cerr << "***** G4VRML2FileViewer::SetView(): No effects" << G4endl; |
---|
63 | #endif |
---|
64 | |
---|
65 | // Do nothing, since VRML a browser is running as a different process. |
---|
66 | // SendViewParameters () will do this job instead. |
---|
67 | |
---|
68 | } |
---|
69 | |
---|
70 | void G4VRML2FileViewer::DrawView() |
---|
71 | { |
---|
72 | #if defined DEBUG_FR_VIEW |
---|
73 | G4cerr << "***** G4VRML2FileViewer::DrawView()" << G4endl; |
---|
74 | #endif |
---|
75 | |
---|
76 | fSceneHandler.VRMLBeginModeling() ; |
---|
77 | |
---|
78 | // Viewpoint node |
---|
79 | SendViewParameters(); |
---|
80 | |
---|
81 | // Here is a minimal DrawView() function. |
---|
82 | NeedKernelVisit(); |
---|
83 | ProcessView(); |
---|
84 | FinishView(); |
---|
85 | } |
---|
86 | |
---|
87 | void G4VRML2FileViewer::ClearView(void) |
---|
88 | { |
---|
89 | #if defined DEBUG_FR_VIEW |
---|
90 | G4cerr << "***** G4VRML2File1View::ClearView()" << G4endl; |
---|
91 | #endif |
---|
92 | if(fSceneHandler.fFlagDestOpen) { |
---|
93 | fSceneHandler.fDest.close(); |
---|
94 | // Re-open with same filename... |
---|
95 | fSceneHandler.fDest.open(fSceneHandler.fVRMLFileName); |
---|
96 | fSceneHandler.fDest << "#VRML V2.0 utf8" << "\n"; |
---|
97 | fSceneHandler.fDest << "# Generated by VRML 2.0 driver of GEANT4\n" << "\n"; |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|
101 | void G4VRML2FileViewer::ShowView(void) |
---|
102 | { |
---|
103 | #if defined DEBUG_FR_VIEW |
---|
104 | G4cerr << "***** G4VRML2FileViewer::ShowView()" << G4endl; |
---|
105 | #endif |
---|
106 | fSceneHandler.VRMLEndModeling(); |
---|
107 | } |
---|
108 | |
---|
109 | void G4VRML2FileViewer::FinishView(void) |
---|
110 | { |
---|
111 | #if defined DEBUG_FR_VIEW |
---|
112 | G4cerr << "***** G4VRML2FileViewer::FinishView(): No effects" << G4endl; |
---|
113 | #endif |
---|
114 | } |
---|
115 | |
---|
116 | void G4VRML2FileViewer::SendViewParameters () |
---|
117 | { |
---|
118 | // Calculates view representation based on extent of object being |
---|
119 | // viewed and (initial) direction of camera. (Note: it can change |
---|
120 | // later due to user interaction via visualization system's GUI.) |
---|
121 | |
---|
122 | #if defined DEBUG_FR_VIEW |
---|
123 | G4cerr << "***** G4VRML2FileViewer::SendViewParameters()\n"; |
---|
124 | #endif |
---|
125 | |
---|
126 | // error recovery |
---|
127 | if ( fsin_VHA < 1.0e-6 ) { return ; } |
---|
128 | |
---|
129 | // camera distance |
---|
130 | G4double extent_radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius(); |
---|
131 | G4double camera_distance = extent_radius / fsin_VHA ; |
---|
132 | |
---|
133 | // camera position on Z axis |
---|
134 | const G4Point3D& target_point |
---|
135 | = fSceneHandler.GetScene()->GetStandardTargetPoint() |
---|
136 | + fVP.GetCurrentTargetPoint(); |
---|
137 | G4double E_z = target_point.z() + camera_distance; |
---|
138 | G4Point3D E(0.0, 0.0, E_z ); |
---|
139 | |
---|
140 | // VRML codes are generated below |
---|
141 | fDest << G4endl; |
---|
142 | fDest << "#---------- CAMERA" << G4endl; |
---|
143 | fDest << "Viewpoint {" << G4endl; |
---|
144 | fDest << "\t" << "position " ; |
---|
145 | fDest << E.x() << " " ; |
---|
146 | fDest << E.y() << " " ; |
---|
147 | fDest << E.z() << G4endl ; |
---|
148 | fDest << "}" << G4endl; |
---|
149 | fDest << G4endl; |
---|
150 | |
---|
151 | } |
---|