Geant4  10.00.p02
G4FukuiRendererViewer.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: G4FukuiRendererViewer.cc 66870 2013-01-14 23:38:59Z adotti $
28 //
29 //
30 // Satoshi TANAKA, Fri Jun 28 12:09:11 JST 1996
31 // FukuiRenderer view - opens window, hard copy, etc.
32 
33 
34 //=================//
35 #ifdef G4VIS_BUILD_DAWN_DRIVER
36 //=================//
37 
38 #define __G_ANSI_C__
39 #define G4FukuiRenderer_STRUCTURE_PRIORITY 1.
40 
41 // #define DEBUG_FR_VIEW
42 
43 #include "G4ios.hh"
44 #include <stdio.h>
45 #include <string.h>
46 #include <assert.h>
47 
48 #include "G4VisManager.hh"
49 #include "G4Scene.hh"
50 #include "G4Vector3D.hh"
51 #include "G4VisExtent.hh"
52 #include "G4LogicalVolume.hh"
53 #include "G4VSolid.hh"
54 #include "G4PhysicalConstants.hh"
55 
56 #include "G4FRConst.hh"
57 #include "G4FukuiRenderer.hh"
59 #include "G4FukuiRendererViewer.hh"
60 
61 
62 //----- Constructor
63 G4FukuiRendererViewer::G4FukuiRendererViewer (G4FukuiRendererSceneHandler& sceneHandler,
64  const G4String& name):
65  G4VViewer (sceneHandler,
66  sceneHandler.IncrementViewCount (),
67  name),
68  fSceneHandler (sceneHandler)
69 {}
70 
71 //----- Destructor
72 G4FukuiRendererViewer::~G4FukuiRendererViewer ()
73 {}
74 
75 //-----
76 void G4FukuiRendererViewer::SetView ()
77 {
78 #if defined DEBUG_FR_VIEW
80  G4cout << "***** G4FukuiRendererViewer::SetView(): No effects" << G4endl;
81 #endif
82 // Do nothing, since DAWN is running as a different process.
83 // SendViewParameters () will do this job instead.
84 }
85 
86 //-----
87 void
88 G4FukuiRendererViewer::ClearView( void )
89 {
90 #if defined DEBUG_FR_VIEW
92  G4cout << "***** G4FukuiRendererViewer::ClearView (): No effects " << G4endl;
93 #endif
94 
95 }
96 
97 
98 //-----
99 void G4FukuiRendererViewer::DrawView ()
100 {
101 #if defined DEBUG_FR_VIEW
103  G4cout << "***** G4FukuiRendererViewer::DrawView () " << G4endl;
104 #endif
105 
106  //----- Begin modeling 3D
107  fSceneHandler.FRBeginModeling();
108 
109  //----- Always visit G4 kernel
110  NeedKernelVisit ();
111 
112  //----- Draw
113  ProcessView () ;
114 
115 }
116 
117 
118 //-----
119 void G4FukuiRendererViewer::ShowView( void )
120 {
121 #if defined DEBUG_FR_VIEW
123  G4cout << "***** G4FukuiRendererViewer::ShowView () " << G4endl;
124 #endif
125 
126  if( fSceneHandler.FRIsInModeling() )
127  {
128  //----- End of modeling
129  // !EndModeling, !DrawAll, !CloseDevice,
130  // close g4.prim
131  fSceneHandler.FREndModeling();
132 
133  //----- Wait user clicks drawing Area
134  this->Wait();
135  }
136 
137 }
138 
139 
140 //-----
141 void G4FukuiRendererViewer::Wait()
142 {
143 #if defined DEBUG_FR_VIEW
145  G4cout << "***** G4FukuiRendererViewer::Wait () : Begin" << G4endl;
146 #endif
147  fSceneHandler.SendStr ( FR_WAIT );
148  fSceneHandler.GetPrimDest().WaitSendBack( FR_WAIT );
149 #if defined DEBUG_FR_VIEW
151  G4cout << "***** G4FukuiRendererViewer::Wait () : end" << G4endl;
152 #endif
153 
154 }
155 
156 
157 //-----
158 void
159 G4FukuiRendererViewer::SendDevice( FRDEV dev )
160 {
161 #if defined DEBUG_FR_VIEW
163  G4cout << "***** G4FukuiRendererViewer::SendDevice() " << G4endl;
164 #endif
165 
166  // enum {PS=1, XWIN=2, PS2=3, XWIN2=4, OPEN_GL=5, DEVICE_END=6};
167 
168  if( dev >= FRDEV_PS || dev < FRDEV_DEVICE_END ) {
169  fSceneHandler.SendStrInt ( FR_DEVICE, dev );
170  }
171 }
172 
173 
174 //-----
175 void G4FukuiRendererViewer::SendDrawingStyle()
176 {
177 #if defined DEBUG_FR_VIEW
179  G4cout << "***** G4FukuiRendererViewer::SendDrawingStyle() " << G4endl;
180 #endif
181 
182  G4int style = fVP.GetDrawingStyle();
183 
184  switch( style )
185  {
187  fSceneHandler.SendStr( FR_WIREFRAME );
188  break;
190  fSceneHandler.SendStr( FR_LINES );
191  break;
194  fSceneHandler.SendStr( FR_SURFACE );
195  break;
196  default:
197  fSceneHandler.SendStr( FR_WIREFRAME );
198  break;
199  }
200 
201 }
202 
203 
204 //-----
205 void G4FukuiRendererViewer::SendViewParameters ()
206 {
207  // Calculates view representation based on extent of object being
208  // viewed and (initial) direction of camera. (Note: it can change
209  // later due to user interaction via visualization system's GUI.)
210 
211 #if defined DEBUG_FR_VIEW
213  G4cout << "***** G4FukuiRendererViewer::SendViewParameters()" << G4endl;
214 #endif
215 
216  //----- Magic number to decide camera distance automatically
217  const G4double HOW_FAR = 1000.0 ; // to define "infinity"
218  const G4double MIN_HALF_ANGLE = 0.01 ;
219  const G4double MAX_HALF_ANGLE = 0.499 * pi ;
220 
221  //----- (2A) CALC camera distance
222  //..... Note: Camera cannot enter inside object
223  G4double camera_distance ;
224  G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
225 
226  G4double half_view_angle = std::fabs ( fVP.GetFieldHalfAngle () ) ;
227  if( half_view_angle > MAX_HALF_ANGLE ) {
228  half_view_angle = MAX_HALF_ANGLE ;
229  }
230 
231  if( half_view_angle < MIN_HALF_ANGLE ) {
232  //----- infinity (or ortho projection)
233  camera_distance = radius * HOW_FAR ;
234  } else {
235  //----- Calc camera distance from half view angle
236  camera_distance = radius / std::sin ( half_view_angle );
237  camera_distance -= fVP.GetDolly();
238  }
239 
240  if ( camera_distance < radius ) {
242  G4cout << "WARNING from FukuiRenderer (DAWN) driver:" << G4endl;
243  G4cout << " Camera cannot enter inside objects" << G4endl;
244  }
245  camera_distance = radius ;
246  }
247 
248  //----- (3A) CALC camera direction
249  const G4Vector3D& camera_direction \
250  = fVP.GetViewpointDirection().unit();
251  const G4double v_angle = (180.0 / pi) * camera_direction.theta() ;
252  const G4double h_angle = (180.0 / pi) * camera_direction.phi () ;
253 
254  //----- (2B), (3B) SEND camera position
255  fSceneHandler.SendStrDouble3( FR_CAMERA_POSITION,
256  camera_distance,
257  v_angle,
258  h_angle );
259 
260  //----- (4A) CALC target point
261  const G4Point3D& target_point
262  = fSceneHandler.GetScene()->GetStandardTargetPoint()
263  + fVP.GetCurrentTargetPoint();
264 
265  //----- (4B) SEND target point
266  fSceneHandler.SendStrDouble3( FR_TARGET_POINT,
267  target_point.x(),
268  target_point.y(),
269  target_point.z() );
270 
271  //----- (5A) CALC zoom factor
272  const G4double zoom_factor = fVP.GetZoomFactor();
273 
274  //----- (5B) SEND zoom factor or focal length
275  if( half_view_angle < MIN_HALF_ANGLE ) {
276 
277  const G4Point3D& std_target_point \
278  = fSceneHandler.GetScene()->GetStandardTargetPoint();
279 
280  fSceneHandler.SendStrDouble4( FR_ZOOM_FACTOR,
281  zoom_factor ,
282  std_target_point.x(),
283  std_target_point.y(),
284  std_target_point.z());
285  // Note that target point, camera position,
286  // and bounding box have already been sent above.
287  // The std_target_point is necessary to
288  // Calc focal distance from the zoom factor.
289  } else {
290  const G4double FR_HALF_SCREEN_SIZE = 0.5 ;
291  G4double focal_distance \
292  = FR_HALF_SCREEN_SIZE / std::tan( half_view_angle );
293  focal_distance *= zoom_factor ;
294  fSceneHandler.SendStrDouble ( FR_FOCAL_DISTANCE, focal_distance );
295  }
296 
297  //----- INVOKE GUI: not executed in the default setting
298  if( fSceneHandler.GetSystem().IsGUIMode() ) {
299  //----- send GUI command
300  fSceneHandler.SendStr( FR_GUI );
301 
302  //----- wait the same command is sent back:
303  //..... This avoids to send many data before
304  //..... GUI session is over.
305  fSceneHandler.GetPrimDest().WaitSendBack( FR_GUI );
306  }
307 
308 }
309 
310 #endif // G4VIS_BUILD_DAWN_DRIVER
311 
312 
const char FR_WAIT[]
Definition: G4FRConst.hh:55
const char FR_FOCAL_DISTANCE[]
Definition: G4FRConst.hh:91
G4String name
Definition: TRTMaterials.hh:40
const G4double pi
HepGeom::Point3D< G4double > G4Point3D
Definition: G4Point3D.hh:35
HepGeom::Vector3D< G4double > G4Vector3D
Definition: G4Vector3D.hh:35
const char FR_TARGET_POINT[]
Definition: G4FRConst.hh:88
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
const char FR_SURFACE[]
Definition: G4FRConst.hh:60
const char FR_LINES[]
Definition: G4FRConst.hh:61
const char FR_DEVICE[]
Definition: G4FRConst.hh:44
const char FR_ZOOM_FACTOR[]
Definition: G4FRConst.hh:89
static Verbosity GetVerbosity()
const char FR_CAMERA_POSITION[]
Definition: G4FRConst.hh:85
#define G4endl
Definition: G4ios.hh:61
const char FR_GUI[]
Definition: G4FRConst.hh:43
double G4double
Definition: G4Types.hh:76
const char FR_WIREFRAME[]
Definition: G4FRConst.hh:59