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