source: trunk/source/visualization/FukuiRenderer/src/G4DAWNFILEViewer.cc@ 1288

Last change on this file since 1288 was 944, checked in by garnier, 17 years ago

mise a jour des tags

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