Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4DAWNFILEViewer.cc
Go to the documentation of this file.
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$
28//
29// Satoshi TANAKA
30// DAWNFILE view - opens window, hard copy, etc.
31
32
33#define __G_ANSI_C__
34#define G4DAWNFILE_STRUCTURE_PRIORITY 1.
35
36// #define DEBUG_FR_VIEW
37
38#include "G4ios.hh"
39#include <stdio.h>
40#include <string.h>
41#include <assert.h>
42
43#include "G4VisManager.hh"
44#include "G4Scene.hh"
45#include "G4Vector3D.hh"
46#include "G4VisExtent.hh"
47#include "G4LogicalVolume.hh"
48#include "G4VSolid.hh"
50
51#include "G4FRConst.hh"
52#include "G4DAWNFILE.hh"
54#include "G4DAWNFILEViewer.hh"
55
56
57
58 //----- constants
59const char FR_ENV_MULTI_WINDOW [] = "G4DAWN_MULTI_WINDOW" ;
60const char FR_ENV_MULTI_WINDOW2[] = "G4DAWNFILE_MULTI_WINDOW" ;
61
62 //----- G4DAWNFILEViewer, constructor
64 const G4String& name):
65 G4VViewer (sceneHandler,
66 sceneHandler.IncrementViewCount (),
67 name),
68 fSceneHandler (sceneHandler)
69{
70 // Set a g4.prim-file viewer
71 strcpy( fG4PrimViewer, "dawn" );
72 if( getenv( "G4DAWNFILE_VIEWER" ) != NULL ) {
73 strcpy( fG4PrimViewer, getenv( "G4DAWNFILE_VIEWER" ) ) ;
74 }
75
76 // string for viewer invocation
77 if ( !strcmp( fG4PrimViewer, "NONE" ) ) {
78
79 strcpy( fG4PrimViewerInvocation, "" );
80 } else {
81
82 strcpy( fG4PrimViewerInvocation, fG4PrimViewer );
83 strcat( fG4PrimViewerInvocation, " ");
84 strcat( fG4PrimViewerInvocation, fSceneHandler.GetG4PrimFileName() );
85 }
86
87 // Set a PostScript Viewer
88// strcpy( fPSViewer, "ghostview" );
89 strcpy( fPSViewer, "gv" );
90 if( getenv( "G4DAWNFILE_PS_VIEWER" ) != NULL ) {
91 strcpy( fPSViewer, getenv( "G4DAWNFILE_PS_VIEWER" ) ) ;
92 }
93
94}
95
96 //----- G4DAWNFILEViewer, destructor
98{}
99
100 //----- G4DAWNFILEViewer::SetView ()
102{
103#if defined DEBUG_FR_VIEW
105 G4cout << "***** G4DAWNFILEViewer::SetView(): No effects" << G4endl;
106#endif
107// Do nothing, since DAWN is running as a different process.
108// SendViewParameters () will do this job instead.
109}
110
111
112 //----- G4DAWNFILEViewer::ClearView()
113void
115{
116#if defined DEBUG_FR_VIEW
118 G4cout << "***** G4DAWNFILEViewer::ClearView (): No effects " << G4endl;
119#endif
120 if (fSceneHandler.fPrimDest.IsOpen()) {
121 fSceneHandler.fPrimDest.Close();
122 // Re-open with same filename...
123 fSceneHandler.fPrimDest.Open(fSceneHandler.fG4PrimFileName);
124 fSceneHandler.SendStr( FR_G4_PRIM_HEADER );
125 fSceneHandler.FRflag_in_modeling = false;
126 fSceneHandler.FRBeginModeling();
127 }
128}
129
130
131 //----- G4DAWNFILEViewer::DrawView ()
133{
134#if defined DEBUG_FR_VIEW
136 G4cout << "***** G4DAWNFILEViewer::DrawView () " << G4endl;
137#endif
138 //-----
139 fSceneHandler.FRBeginModeling() ;
140
141 //----- Always visit G4 kernel
143
144 //----- Draw
145 ProcessView () ;
146
147} // G4DAWNFILEViewer::DrawView ()
148
149
150
151 //----- G4DAWNFILEViewer::ShowView()
153{
154#if defined DEBUG_FR_VIEW
156 G4cout << "***** G4DAWNFILEViewer::ShowView () " << G4endl;
157#endif
158
159 if( fSceneHandler.FRIsInModeling() )
160 {
161 //----- End of modeling
162 // !EndModeling, !DrawAll, !CloseDevice,
163 // close g4.prim
164 fSceneHandler.FREndModeling();
165
166 //----- Output DAWN GUI file
168
169 //----- string for viewer invocation
170 if ( !strcmp( fG4PrimViewer, "NONE" ) ) {
171
172 strcpy( fG4PrimViewerInvocation, "" );
173 } else {
174
175 strcpy( fG4PrimViewerInvocation, fG4PrimViewer );
176 strcat( fG4PrimViewerInvocation, " ");
177 strcat( fG4PrimViewerInvocation, fSceneHandler.GetG4PrimFileName() );
178 }
179
180
181 //----- Invoke DAWN
182 G4cout << G4endl ;
183 if( false == G4FRofstream::DoesFileExist( fSceneHandler.GetG4PrimFileName() ) )
184 {
185 G4cout << "ERROR: Failed to generate file ";
186 G4cout << fSceneHandler.GetG4PrimFileName() << G4endl;
187
188 } else if( strcmp( GetG4PrimViewerInvocation(), "" ) )
189 {
190 G4cout << "File " << fSceneHandler.GetG4PrimFileName() ;
191 G4cout << " is generated." << G4endl;
193 (void) system( GetG4PrimViewerInvocation() );
194
195 } else { // no view, i.e., only file generation
196 G4cout << "File " << fSceneHandler.GetG4PrimFileName() ;
197 G4cout << " is generated." << G4endl;
198 G4cout << "No viewer is invoked." << G4endl;
199 }
200
201 }
202
203} // G4DAWNFILEViewer::ShowView()
204
205
206 //----- G4DAWNFILEViewer::SendDrawingStyleToDAWNGUI( std::ostream& out )
208{
209///////////////////////
210//#if defined DEBUG_FR_VIEW
211// G4cout << "***** G4DAWNFILEViewer::SendDrawingStyleToDAWNGUI()" << G4endl;
212//#endif
213//////////////////////
214
215 G4int style = fVP.GetDrawingStyle();
216
217 enum { FR_WIREFRAME_STYLE = 1, FR_WF_STORED_STYLE = 2,
218 FR_HID_STYLE = 3, FR_HID2_STYLE = 4,
219 FR_HID3_STYLE = 5, FR_DRAWING_MODE_END_STYLE = 6 };
220
221 switch( style )
222 {
224 out << FR_WIREFRAME_STYLE << G4endl;
225 break;
227 out << FR_HID2_STYLE << G4endl; // LINE
228 break;
231 out << FR_HID_STYLE << G4endl; // SURFACE
232 break;
233 default:
234 out << FR_WIREFRAME_STYLE << G4endl;
235 break;
236 }
237
238} // G4DAWNFILEViewer::SendDrawingStyle()
239
240
241
242//-----
244{
245 // Calculates view representation based on extent of object being
246 // viewed and (initial) direction of camera. (Note: it can change
247 // later due to user interaction via visualization system's GUI.)
248
249#if defined DEBUG_FR_VIEW
251 G4cout << "***** G4DAWNFILEViewer::SendViewParameters() ";
252 G4cout << "(GUI parameters)" << G4endl;
253 }
254#endif
255
256 //----- Magic number to decide camera distance automatically
257 const G4double HOW_FAR = 1000.0 ; // to define "infinity"
258 const G4double MIN_HALF_ANGLE = 0.01 ;
259 const G4double MAX_HALF_ANGLE = 0.499 * pi ;
260
261 //----- CALC camera distance
262 //..... Note: Camera cannot enter inside object
263 G4double camera_distance ;
264 G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
265
266 G4double half_view_angle = std::fabs ( fVP.GetFieldHalfAngle () ) ;
267 if( half_view_angle > MAX_HALF_ANGLE ) {
268 half_view_angle = MAX_HALF_ANGLE ;
269 }
270
271 if( half_view_angle < MIN_HALF_ANGLE ) {
272 //----- infinity (or ortho projection)
273 camera_distance = radius * HOW_FAR ;
274 } else {
275 //----- Calc camera distance from half view angle
276 camera_distance = radius / std::sin ( half_view_angle );
277 camera_distance -= fVP.GetDolly();
278 }
279
280 if ( camera_distance < radius ) {
282 G4cout << "WARNING from DAWNFILE driver:" << G4endl;
283 G4cout << " Camera cannot enter inside objects" << G4endl;
284 }
285 camera_distance = radius ;
286 }
287
288 //----- CALC camera direction
289 const G4Vector3D& camera_direction \
291 const G4double v_angle = (180.0 / pi) * camera_direction.theta() ;
292 const G4double h_angle = (180.0 / pi) * camera_direction.phi () ;
293
294
295 //########### Generation of the file .DAWN.history for DAWN GUI
296 //-----
297 std::ofstream gui_out (".DAWN_1.history") ;
298
299 // ######### P1
300
301 //----- camera position
302 gui_out << camera_distance << G4endl;
303 gui_out << v_angle << G4endl ;
304 gui_out << h_angle << G4endl ;
305 gui_out << "0" << G4endl ; // auto target
306
307 //----- target point
308 const G4Point3D& target_point
309 = fSceneHandler.GetScene()->GetStandardTargetPoint()
311 gui_out << target_point.x() << G4endl ;
312 gui_out << target_point.y() << G4endl ;
313 gui_out << target_point.z() << G4endl ;
314
315 //----- Magnification
316 const G4double zoom_factor = fVP.GetZoomFactor();
317 if( half_view_angle < MIN_HALF_ANGLE ) {
318
319 gui_out << zoom_factor << G4endl;
320
321 } else {
322 const G4double FR_HALF_SCREEN_SIZE = 0.5 ;
323 G4double focal_distance \
324 = FR_HALF_SCREEN_SIZE / std::tan( half_view_angle );
325 focal_distance *= zoom_factor ;
326
327 gui_out << "fd" << focal_distance << G4endl;
328
329 }
330 SendDrawingStyleToDAWNGUI( gui_out ) ; // gui_out, viewing mode
331 gui_out << "0.001" << G4endl ; // 3D Tolerance
332 gui_out << "0" << G4endl ; // not display parameters
333
334
335 // ######### P2
336 gui_out << 1 << G4endl; // Source light
337 gui_out << 1 << G4endl;
338 gui_out << 1 << G4endl;
339 gui_out << 0.5 << G4endl; // Ambient light
340 gui_out << 0.5 << G4endl;
341 gui_out << 0.5 << G4endl;
342 gui_out << 19.0 << G4endl; // Light direction (Polar)
343 gui_out << 71.0 << G4endl; // Light direction (Azimuthal)
344
345 // ######### P3
346 gui_out << 0.1 << G4endl; // Real edge width
347 gui_out << 0.1 << G4endl; // outline width
348 gui_out << 0.1 << G4endl; // aux edge width
349 gui_out << 3 << G4endl; // aux edge style
350 gui_out << 70.0<< G4endl; // aux-edge threshold angle
351 gui_out << 0.1 << G4endl; // line width
352 gui_out << 0 << G4endl; // haloing
353 gui_out << 1 << G4endl; // Dashed edged for back faces
354
355 //######### P4
356 //----- drawing device
357 // enum {PS=1, XWIN=2, PS2=3, XWIN2=4, OPEN_GL=5, DEVICE_END=6};
358 if( ( ( getenv( FR_ENV_MULTI_WINDOW ) != NULL ) && \
359 ( strcmp( getenv( FR_ENV_MULTI_WINDOW ),"0" ) ) ) || \
360 ( ( getenv( FR_ENV_MULTI_WINDOW2 ) != NULL ) && \
361 ( strcmp( getenv( FR_ENV_MULTI_WINDOW2 ),"0" ) ) ) )
362 {
363 gui_out << 2 << G4endl; // OpenWindow
364 } else {
365 gui_out << 1 << G4endl; // Invoke PS viewer
366 }
367
368 gui_out << GetPSViewer() << G4endl; // PS viewer
369 gui_out << 1 << G4endl ; // Do not add showpage
370 gui_out << 0 << G4endl ; // Non-append mode
371
372 gui_out.close();
373 //########### end of generating file .DAWN.history
374
375
376}
const char FR_ENV_MULTI_WINDOW2[]
const char FR_ENV_MULTI_WINDOW[]
const char FR_G4_PRIM_HEADER[]
Definition: G4FRConst.hh:38
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
void SendStr(const char *char_string)
G4DAWNFILEViewer(G4DAWNFILESceneHandler &scene, const G4String &name="")
virtual ~G4DAWNFILEViewer()
const char * GetG4PrimViewerInvocation()
void SendDrawingStyleToDAWNGUI(std::ostream &out)
const char * GetPSViewer()
void Open(const char *filename)
Definition: G4FRofstream.hh:74
G4bool IsOpen()
Definition: G4FRofstream.hh:60
static G4bool DoesFileExist(const char *filename)
Definition: G4FRofstream.hh:99
const G4VisExtent & GetExtent() const
const G4Point3D & GetStandardTargetPoint() const
G4Scene * GetScene() const
void ProcessView()
Definition: G4VViewer.cc:115
void NeedKernelVisit()
Definition: G4VViewer.cc:86
G4ViewParameters fVP
Definition: G4VViewer.hh:137
const G4Vector3D & GetViewpointDirection() const
const G4Point3D & GetCurrentTargetPoint() const
G4double GetFieldHalfAngle() const
G4double GetZoomFactor() const
DrawingStyle GetDrawingStyle() const
G4double GetDolly() const
G4double GetExtentRadius() const
Definition: G4VisExtent.cc:73
static Verbosity GetVerbosity()
BasicVector3D< T > unit() const