source: trunk/source/visualization/VRML/src/G4VRML2Viewer.cc

Last change on this file was 1347, checked in by garnier, 15 years ago

geant4 tag 9.4

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