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