Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // >> 27 // $Id: G4OpenGLXmRotationCallbacks.cc 66373 2012-12-18 09:41:34Z gcosmo $ 27 // 28 // 28 // 29 // 29 // Andrew Walkden 16th April 1997 30 // Andrew Walkden 16th April 1997 30 // G4OpenGLXmRotationCallbacks : 31 // G4OpenGLXmRotationCallbacks : 31 // Several callback func 32 // Several callback functions used by 32 // elements of the contr 33 // elements of the control panel to 33 // rotate the view. 34 // rotate the view. 34 35 >> 36 #ifdef G4VIS_BUILD_OPENGLXM_DRIVER >> 37 35 #include "G4OpenGLXmViewer.hh" 38 #include "G4OpenGLXmViewer.hh" 36 39 37 #include "G4PhysicalConstants.hh" 40 #include "G4PhysicalConstants.hh" 38 #include "G4Scene.hh" 41 #include "G4Scene.hh" 39 #include "G4UImanager.hh" 42 #include "G4UImanager.hh" 40 #include "G4ios.hh" 43 #include "G4ios.hh" 41 44 42 void G4OpenGLXmViewer::theta_rotation_callback 45 void G4OpenGLXmViewer::theta_rotation_callback (Widget w, 43 XtPointer clientData, 46 XtPointer clientData, 44 XtPointer callData) 47 XtPointer callData) 45 { 48 { 46 XmArrowButtonCallbackStruct *cbs = (XmArrowB 49 XmArrowButtonCallbackStruct *cbs = (XmArrowButtonCallbackStruct*) callData; 47 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer* 50 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData; 48 51 49 pView->rotate_right = get_boolean_userData ( 52 pView->rotate_right = get_boolean_userData (w); 50 53 51 if (cbs->reason == XmCR_ARM) { 54 if (cbs->reason == XmCR_ARM) { 52 rotate_in_theta (pView, NULL); 55 rotate_in_theta (pView, NULL); 53 } else if (cbs->reason == XmCR_DISARM) { 56 } else if (cbs->reason == XmCR_DISARM) { 54 XtRemoveTimeOut (pView->rotation_timer); 57 XtRemoveTimeOut (pView->rotation_timer); 55 } 58 } 56 } 59 } 57 60 58 void G4OpenGLXmViewer::rotate_in_theta (XtPoin 61 void G4OpenGLXmViewer::rotate_in_theta (XtPointer clientData, 59 XtIntervalId* timer_id) 62 XtIntervalId* timer_id) 60 { 63 { 61 //theta spin stuff here 64 //theta spin stuff here 62 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer* 65 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData; 63 66 64 if (pView->rotate_right) { 67 if (pView->rotate_right) { 65 pView->rotateScene(1,0); 68 pView->rotateScene(1,0); 66 } else { 69 } else { 67 pView->rotateScene(-1,0); 70 pView->rotateScene(-1,0); 68 } 71 } 69 /* 72 /* 70 G4double delta_theta; 73 G4double delta_theta; 71 74 72 if (pView->fVP.GetLightsMoveWithCamera()) { 75 if (pView->fVP.GetLightsMoveWithCamera()) { 73 if (pView->rotate_right) { 76 if (pView->rotate_right) { 74 delta_theta = -(pView->fRot_sens); 77 delta_theta = -(pView->fRot_sens); 75 } else { 78 } else { 76 delta_theta = pView->fRot_sens; 79 delta_theta = pView->fRot_sens; 77 } 80 } 78 } else { 81 } else { 79 if (pView->rotate_right) { 82 if (pView->rotate_right) { 80 delta_theta = pView->fRot_sens; 83 delta_theta = pView->fRot_sens; 81 } else { 84 } else { 82 delta_theta = -(pView->fRot_sens); 85 delta_theta = -(pView->fRot_sens); 83 } 86 } 84 } 87 } 85 delta_theta *= deg; 88 delta_theta *= deg; 86 // Rotates by fixed azimuthal angle delta_th 89 // Rotates by fixed azimuthal angle delta_theta. 87 90 88 const G4Vector3D& vp = pView->fVP.GetViewpoi 91 const G4Vector3D& vp = pView->fVP.GetViewpointDirection ().unit (); 89 const G4Vector3D& up = pView->fVP.GetUpVecto 92 const G4Vector3D& up = pView->fVP.GetUpVector ().unit (); 90 const G4Vector3D& zprime = up; 93 const G4Vector3D& zprime = up; 91 G4double cosalpha = up.dot (vp); 94 G4double cosalpha = up.dot (vp); 92 G4double sinalpha = std::sqrt (1. - std::pow 95 G4double sinalpha = std::sqrt (1. - std::pow (cosalpha, 2)); 93 G4Vector3D yprime = (zprime.cross (vp)).unit 96 G4Vector3D yprime = (zprime.cross (vp)).unit (); 94 G4Vector3D xprime = yprime.cross (zprime); 97 G4Vector3D xprime = yprime.cross (zprime); 95 // Projection of vp on plane perpendicular t 98 // Projection of vp on plane perpendicular to up... 96 G4Vector3D a1 = sinalpha * xprime; 99 G4Vector3D a1 = sinalpha * xprime; 97 // Required new projection... 100 // Required new projection... 98 G4Vector3D a2 = 101 G4Vector3D a2 = 99 sinalpha * (std::cos (delta_theta) * xprim 102 sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime); 100 // Required Increment vector... 103 // Required Increment vector... 101 G4Vector3D delta = a2 - a1; 104 G4Vector3D delta = a2 - a1; 102 // So new viewpoint is... 105 // So new viewpoint is... 103 G4Vector3D viewPoint = vp + delta; 106 G4Vector3D viewPoint = vp + delta; 104 107 105 pView->fVP.SetViewAndLights (viewPoint); 108 pView->fVP.SetViewAndLights (viewPoint); 106 */ 109 */ 107 110 108 pView->SetView (); 111 pView->SetView (); 109 pView->ClearView (); 112 pView->ClearView (); 110 pView->DrawView (); 113 pView->DrawView (); 111 114 112 pView->rotation_timer = XtAppAddTimeOut 115 pView->rotation_timer = XtAppAddTimeOut 113 (pView->app, 116 (pView->app, 114 timer_id == NULL ? 500 : 1, 117 timer_id == NULL ? 500 : 1, 115 rotate_in_theta, 118 rotate_in_theta, 116 pView); 119 pView); 117 } 120 } 118 121 119 void G4OpenGLXmViewer::phi_rotation_callback ( 122 void G4OpenGLXmViewer::phi_rotation_callback (Widget w, 120 XtPointer clientData, 123 XtPointer clientData, 121 XtPointer callData) 124 XtPointer callData) 122 { 125 { 123 XmArrowButtonCallbackStruct *cbs = (XmArrowB 126 XmArrowButtonCallbackStruct *cbs = (XmArrowButtonCallbackStruct*) callData; 124 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer* 127 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData; 125 128 126 pView->rotate_up = get_boolean_userData (w); 129 pView->rotate_up = get_boolean_userData (w); 127 130 128 if (cbs->reason == XmCR_ARM) { 131 if (cbs->reason == XmCR_ARM) { 129 rotate_in_phi (pView, NULL); 132 rotate_in_phi (pView, NULL); 130 } else if (cbs->reason == XmCR_DISARM) { 133 } else if (cbs->reason == XmCR_DISARM) { 131 XtRemoveTimeOut (pView->rotation_timer); 134 XtRemoveTimeOut (pView->rotation_timer); 132 } 135 } 133 } 136 } 134 137 135 void G4OpenGLXmViewer::rotate_in_phi (XtPointe 138 void G4OpenGLXmViewer::rotate_in_phi (XtPointer clientData, 136 XtIntervalId* timer_id) 139 XtIntervalId* timer_id) 137 { 140 { 138 //phi spin stuff here 141 //phi spin stuff here 139 // G4double delta_alpha; 142 // G4double delta_alpha; 140 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer* 143 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData; 141 144 142 if (pView -> rotate_up) { 145 if (pView -> rotate_up) { 143 pView->rotateScene(0,-1); 146 pView->rotateScene(0,-1); 144 } else { 147 } else { 145 pView->rotateScene(0,1); 148 pView->rotateScene(0,1); 146 } 149 } 147 /* 150 /* 148 if (pView->fVP.GetLightsMoveWithCamera()) { 151 if (pView->fVP.GetLightsMoveWithCamera()) { 149 if (pView -> rotate_up) { 152 if (pView -> rotate_up) { 150 delta_alpha = -(pView->fRot_sens); 153 delta_alpha = -(pView->fRot_sens); 151 } else { 154 } else { 152 delta_alpha = pView->fRot_sens; 155 delta_alpha = pView->fRot_sens; 153 } 156 } 154 } else { 157 } else { 155 if (pView -> rotate_up) { 158 if (pView -> rotate_up) { 156 delta_alpha = pView->fRot_sens; 159 delta_alpha = pView->fRot_sens; 157 } else { 160 } else { 158 delta_alpha = -(pView->fRot_sens); 161 delta_alpha = -(pView->fRot_sens); 159 } 162 } 160 } 163 } 161 164 162 delta_alpha *= deg; 165 delta_alpha *= deg; 163 166 164 const G4Vector3D& vp = pView->fVP.GetViewpoi 167 const G4Vector3D& vp = pView->fVP.GetViewpointDirection ().unit (); 165 const G4Vector3D& up = pView->fVP.GetUpVecto 168 const G4Vector3D& up = pView->fVP.GetUpVector ().unit (); 166 169 167 const G4Vector3D& xprime = vp; 170 const G4Vector3D& xprime = vp; 168 G4Vector3D yprime = (up.cross(xprime)).unit( 171 G4Vector3D yprime = (up.cross(xprime)).unit(); 169 G4Vector3D zprime = (xprime.cross(yprime)).u 172 G4Vector3D zprime = (xprime.cross(yprime)).unit(); 170 173 171 G4Vector3D new_vp = std::cos(delta_alpha) * 174 G4Vector3D new_vp = std::cos(delta_alpha) * xprime + std::sin(delta_alpha) * zprime; 172 175 173 pView->fVP.SetViewAndLights (new_vp.unit()); 176 pView->fVP.SetViewAndLights (new_vp.unit()); 174 177 175 if (pView->fVP.GetLightsMoveWithCamera()) { 178 if (pView->fVP.GetLightsMoveWithCamera()) { 176 G4Vector3D new_up = (new_vp.cross(yprime)) 179 G4Vector3D new_up = (new_vp.cross(yprime)).unit(); 177 pView->fVP.SetUpVector(new_up); 180 pView->fVP.SetUpVector(new_up); 178 } 181 } 179 182 180 */ 183 */ 181 pView->SetView (); 184 pView->SetView (); 182 pView->ClearView (); 185 pView->ClearView (); 183 pView->DrawView (); 186 pView->DrawView (); 184 187 185 pView->rotation_timer = XtAppAddTimeOut 188 pView->rotation_timer = XtAppAddTimeOut 186 (pView->app, 189 (pView->app, 187 timer_id == NULL ? 500 : 1, 190 timer_id == NULL ? 500 : 1, 188 rotate_in_phi, 191 rotate_in_phi, 189 pView); 192 pView); 190 } 193 } 191 194 192 void G4OpenGLXmViewer::set_rot_sens_callback ( 195 void G4OpenGLXmViewer::set_rot_sens_callback (Widget w, 193 XtPointer clientData, 196 XtPointer clientData, 194 XtPointer callData) 197 XtPointer callData) 195 { 198 { 196 XmScaleCallbackStruct *cbs = (XmScaleCallbac 199 XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*) callData; 197 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer* 200 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData; 198 short dp = -1; 201 short dp = -1; 199 G4float ten_to_the_dp = 10.; 202 G4float ten_to_the_dp = 10.; 200 203 201 XtVaGetValues (w, 204 XtVaGetValues (w, 202 XmNdecimalPoints, &dp, 205 XmNdecimalPoints, &dp, 203 NULL); 206 NULL); 204 207 205 if (dp == 0) { 208 if (dp == 0) { 206 ten_to_the_dp = 1.; 209 ten_to_the_dp = 1.; 207 } else if ( dp > 0) { 210 } else if ( dp > 0) { 208 for (G4int i = 1; i < (G4int)dp; i++) { 211 for (G4int i = 1; i < (G4int)dp; i++) { 209 ten_to_the_dp *= 10.; 212 ten_to_the_dp *= 10.; 210 } 213 } 211 } else { 214 } else { 212 G4Exception 215 G4Exception 213 ("G4OpenGLXmViewer::set_rot_sens_callbac 216 ("G4OpenGLXmViewer::set_rot_sens_callback", 214 "opengl2004", FatalException, 217 "opengl2004", FatalException, 215 "Bad value returned for dp in set_rot_s 218 "Bad value returned for dp in set_rot_sens_callback"); 216 } 219 } 217 220 218 pView->fRot_sens = (G4float)(cbs->value) / t 221 pView->fRot_sens = (G4float)(cbs->value) / ten_to_the_dp; 219 } 222 } 220 223 221 void G4OpenGLXmViewer::set_rot_subject_callbac 224 void G4OpenGLXmViewer::set_rot_subject_callback (Widget w, 222 XtPointer clientData, 225 XtPointer clientData, 223 XtPointer) 226 XtPointer) 224 { 227 { 225 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer* 228 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*)clientData; 226 229 227 G4int choice = get_int_userData (w); 230 G4int choice = get_int_userData (w); 228 231 229 switch (choice) { 232 switch (choice) { 230 case 0: 233 case 0: 231 { 234 { 232 pView->fVP.SetLightsMoveWithCamera (true 235 pView->fVP.SetLightsMoveWithCamera (true); 233 break; 236 break; 234 } 237 } 235 case 1: 238 case 1: 236 { 239 { 237 pView->fVP.SetLightsMoveWithCamera (fals 240 pView->fVP.SetLightsMoveWithCamera (false); 238 break; 241 break; 239 } 242 } 240 default: 243 default: 241 { 244 { 242 G4Exception 245 G4Exception 243 ("G4OpenGLXmViewer::set_rot_subject_callback 246 ("G4OpenGLXmViewer::set_rot_subject_callback", 244 "opengl2005", FatalException, 247 "opengl2005", FatalException, 245 "Unrecognised choice made in set_rot_subjec 248 "Unrecognised choice made in set_rot_subject_callback"); 246 } 249 } 247 } 250 } 248 } 251 } 249 252 250 void G4OpenGLXmViewer::wobble_callback (Widget 253 void G4OpenGLXmViewer::wobble_callback (Widget w, 251 XtPointer, 254 XtPointer, 252 XtPointer) 255 XtPointer) 253 { 256 { 254 G4OpenGLXmViewer* pView; 257 G4OpenGLXmViewer* pView; 255 258 256 XtVaGetValues (w, 259 XtVaGetValues (w, 257 XmNuserData, &pView, 260 XmNuserData, &pView, 258 NULL); 261 NULL); 259 262 260 pView->original_vp = pView->fVP.GetViewpoint 263 pView->original_vp = pView->fVP.GetViewpointDirection(); 261 pView->wobble_timer = XtAppAddTimeOut 264 pView->wobble_timer = XtAppAddTimeOut 262 (pView->app, 265 (pView->app, 263 (long unsigned int) (1000. * (1. / pView- 266 (long unsigned int) (1000. * (1. / pView->wob_sens)), 264 wobble_timer_callback, 267 wobble_timer_callback, 265 pView); 268 pView); 266 } 269 } 267 270 268 void G4OpenGLXmViewer::wobble_timer_callback ( 271 void G4OpenGLXmViewer::wobble_timer_callback (XtPointer clientData, 269 XtIntervalId*) 272 XtIntervalId*) 270 { 273 { 271 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer* 274 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*)clientData; 272 const G4Vector3D& up = pView->fVP.GetUpVecto 275 const G4Vector3D& up = pView->fVP.GetUpVector(); 273 G4Vector3D third_axis = up.cross(pView->orig 276 G4Vector3D third_axis = up.cross(pView->original_vp); 274 G4double pi_div_by_ten = pi / 10.0; 277 G4double pi_div_by_ten = pi / 10.0; 275 G4Vector3D d_up = 0.1 * (std::sin ((G4double 278 G4Vector3D d_up = 0.1 * (std::sin ((G4double)pView->frameNo * pi_div_by_ten * 2.)) * up; 276 G4Vector3D d_third_axis = 0.1 * (std::sin (( 279 G4Vector3D d_third_axis = 0.1 * (std::sin ((G4double)pView->frameNo * (pi_div_by_ten))) * third_axis; 277 280 278 pView->fVP.SetViewAndLights (pView->original 281 pView->fVP.SetViewAndLights (pView->original_vp + d_up + d_third_axis); 279 282 280 pView->SetView (); 283 pView->SetView (); 281 pView->ClearView (); 284 pView->ClearView (); 282 pView->DrawView (); 285 pView->DrawView (); 283 286 284 if (pView->frameNo++ == 20) { 287 if (pView->frameNo++ == 20) { 285 if (pView->wobble_timer) { 288 if (pView->wobble_timer) { 286 XtRemoveTimeOut (pView->wobble_timer); 289 XtRemoveTimeOut (pView->wobble_timer); 287 pView->frameNo = 0; 290 pView->frameNo = 0; 288 pView->fVP.SetViewAndLights (pView->orig 291 pView->fVP.SetViewAndLights (pView->original_vp); 289 pView->SetView (); 292 pView->SetView (); 290 pView->ClearView (); 293 pView->ClearView (); 291 pView->DrawView (); 294 pView->DrawView (); 292 } 295 } 293 } else { 296 } else { 294 pView->wobble_timer = XtAppAddTimeOut 297 pView->wobble_timer = XtAppAddTimeOut 295 (pView->app, 298 (pView->app, 296 (long unsigned int) (1000. * (1. / pVie 299 (long unsigned int) (1000. * (1. / pView->wob_sens)), 297 wobble_timer_callback, 300 wobble_timer_callback, 298 pView); 301 pView); 299 } 302 } 300 } 303 } 301 304 302 void G4OpenGLXmViewer::reset_callback (Widget 305 void G4OpenGLXmViewer::reset_callback (Widget w, 303 XtPointer, 306 XtPointer, 304 XtPointer) 307 XtPointer) 305 { 308 { 306 309 307 G4OpenGLXmViewer* pView; 310 G4OpenGLXmViewer* pView; 308 311 309 XtVaGetValues (w, 312 XtVaGetValues (w, 310 XmNuserData, &pView, 313 XmNuserData, &pView, 311 NULL); 314 NULL); 312 315 313 pView->fVP.SetCurrentTargetPoint(G4Point3D() 316 pView->fVP.SetCurrentTargetPoint(G4Point3D()); 314 pView->fVP.SetZoomFactor(1.0); 317 pView->fVP.SetZoomFactor(1.0); 315 pView->fVP.SetDolly(0.0); 318 pView->fVP.SetDolly(0.0); 316 pView->SetView (); 319 pView->SetView (); 317 pView->ClearView (); 320 pView->ClearView (); 318 pView->DrawView (); 321 pView->DrawView (); 319 pView->zoom_low = 0.1; 322 pView->zoom_low = 0.1; 320 pView->zoom_high = 10.0; 323 pView->zoom_high = 10.0; 321 324 322 } 325 } >> 326 #endif 323 327