Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 << 23 #ifdef G4VIS_BUILD_OI_DRIVER 27 // 03-MAY-2021 F.W. Jones: removed the camera << 28 // since the group node sensor receives all ca << 29 // can update the view parameters, irrespectiv << 30 // camera type. << 31 24 32 // this : 25 // this : 33 #include "G4OpenInventorViewer.hh" 26 #include "G4OpenInventorViewer.hh" 34 27 35 #include <Inventor/nodes/SoSelection.h> 28 #include <Inventor/nodes/SoSelection.h> 36 #include <Inventor/nodes/SoShape.h> 29 #include <Inventor/nodes/SoShape.h> 37 #include <Inventor/nodes/SoOrthographicCamera. 30 #include <Inventor/nodes/SoOrthographicCamera.h> 38 #include <Inventor/nodes/SoPerspectiveCamera.h 31 #include <Inventor/nodes/SoPerspectiveCamera.h> 39 #include <Inventor/actions/SoCallbackAction.h> 32 #include <Inventor/actions/SoCallbackAction.h> 40 #include <Inventor/actions/SoWriteAction.h> 33 #include <Inventor/actions/SoWriteAction.h> 41 #include <Inventor/sensors/SoNodeSensor.h> 34 #include <Inventor/sensors/SoNodeSensor.h> 42 35 43 #include "HEPVis/nodes/SoImageWriter.h" 36 #include "HEPVis/nodes/SoImageWriter.h" 44 #include "HEPVis/actions/SoGL2PSAction.h" 37 #include "HEPVis/actions/SoGL2PSAction.h" 45 #include "HEPVis/actions/SoCounterAction.h" 38 #include "HEPVis/actions/SoCounterAction.h" 46 #include "HEPVis/actions/SoAlternateRepAction. << 47 39 48 #include "G4OpenInventor.hh" 40 #include "G4OpenInventor.hh" 49 #include "G4OpenInventorSceneHandler.hh" 41 #include "G4OpenInventorSceneHandler.hh" 50 #include "G4VInteractorManager.hh" 42 #include "G4VInteractorManager.hh" 51 #include "G4Scene.hh" 43 #include "G4Scene.hh" 52 #include "Geant4_SoPolyhedron.h" 44 #include "Geant4_SoPolyhedron.h" 53 #include "G4AttValue.hh" << 54 #include "G4AttDef.hh" << 55 #include "G4AttCheck.hh" << 56 #include "G4AttHolder.hh" << 57 45 58 G4OpenInventorViewer::G4OpenInventorViewer( 46 G4OpenInventorViewer::G4OpenInventorViewer( 59 G4OpenInventorSceneHandler& sceneHandler 47 G4OpenInventorSceneHandler& sceneHandler 60 ,const G4String& name) 48 ,const G4String& name) 61 :G4VViewer(sceneHandler, sceneHandler.Incremen 49 :G4VViewer(sceneHandler, sceneHandler.IncrementViewCount(), name) 62 ,fG4OpenInventorSceneHandler(sceneHandler) 50 ,fG4OpenInventorSceneHandler(sceneHandler) 63 ,fInteractorManager(0) 51 ,fInteractorManager(0) 64 ,fSoSelection(0) 52 ,fSoSelection(0) 65 ,fSoImageWriter(0) 53 ,fSoImageWriter(0) 66 ,fGL2PSAction(0) //To be set be suclass. 54 ,fGL2PSAction(0) //To be set be suclass. 67 ,fGroupCameraSensor(0) 55 ,fGroupCameraSensor(0) 68 //,fCameraSensor(0) << 56 ,fCameraSensor(0) 69 { 57 { 70 fVP.SetAutoRefresh(true); << 58 fNeedKernelVisit = true; //?? Temporary, until KernelVisitDecision fixed. >> 59 71 fDefaultVP.SetAutoRefresh(true); 60 fDefaultVP.SetAutoRefresh(true); 72 fVP.SetPicking(true); << 61 fVP.SetAutoRefresh(true); 73 fDefaultVP.SetPicking(true); << 74 62 75 //FIXME : G.Barrand : not convinced that we 63 //FIXME : G.Barrand : not convinced that we have to rm culling. 76 // For viewing of all objects by default : 64 // For viewing of all objects by default : 77 //fDefaultVP.SetCulling(false); 65 //fDefaultVP.SetCulling(false); 78 //fVP.SetCulling(false); 66 //fVP.SetCulling(false); 79 67 80 fInteractorManager = 68 fInteractorManager = 81 ((G4OpenInventor*)fG4OpenInventorSceneHand 69 ((G4OpenInventor*)fG4OpenInventorSceneHandler.GetGraphicsSystem())-> 82 GetInteractorManager(); 70 GetInteractorManager(); 83 71 84 // Main user scene graph root sent to the vi 72 // Main user scene graph root sent to the viewers. 85 fSoSelection = new SoSelection; 73 fSoSelection = new SoSelection; 86 fSoSelection->ref(); 74 fSoSelection->ref(); 87 fSoSelection->addSelectionCallback(Selection 75 fSoSelection->addSelectionCallback(SelectionCB,this); 88 //fSoSelection->addDeselectionCallback(Desel 76 //fSoSelection->addDeselectionCallback(DeselectionCB,this); 89 fSoSelection->policy = SoSelection::SINGLE; 77 fSoSelection->policy = SoSelection::SINGLE; 90 78 91 SoGroup* group = new SoGroup; 79 SoGroup* group = new SoGroup; 92 fSoSelection->addChild(group); 80 fSoSelection->addChild(group); 93 81 94 // Have a camera under fSoSelection in orde 82 // Have a camera under fSoSelection in order 95 // that the below SceneGraphSensor be notife 83 // that the below SceneGraphSensor be notifed 96 // when the viewer changes the camera type. 84 // when the viewer changes the camera type. 97 // But we put the camera under a SoGroup so 85 // But we put the camera under a SoGroup so that 98 // the SceneGraphSensor be not triggered at 86 // the SceneGraphSensor be not triggered at each change 99 // under the fG4OpenInventorSceneHandler.fRo 87 // under the fG4OpenInventorSceneHandler.fRoot. 100 SoOrthographicCamera* camera = new SoOrthogr 88 SoOrthographicCamera* camera = new SoOrthographicCamera; 101 camera->viewportMapping.setValue(SoCamera::A 89 camera->viewportMapping.setValue(SoCamera::ADJUST_CAMERA); 102 //camera->aspectRatio.setValue(10); 90 //camera->aspectRatio.setValue(10); 103 camera->position.setValue(0,0,10); 91 camera->position.setValue(0,0,10); 104 camera->orientation.setValue(SbRotation(SbVe 92 camera->orientation.setValue(SbRotation(SbVec3f(0,1,0),0)); 105 camera->height.setValue(10); 93 camera->height.setValue(10); 106 camera->nearDistance.setValue(1); 94 camera->nearDistance.setValue(1); 107 camera->farDistance.setValue(100); 95 camera->farDistance.setValue(100); 108 camera->focalDistance.setValue(10); 96 camera->focalDistance.setValue(10); 109 group->addChild(camera); 97 group->addChild(camera); 110 98 111 {SoInput soInput; << 112 if(soInput.openFile("g4view.iv",TRUE)) { << 113 SoSeparator* separator = SoDB::readAll(&so << 114 if(separator) fSoSelection->addChild(separ << 115 }} << 116 << 117 fSoSelection->addChild(fG4OpenInventorSceneH 99 fSoSelection->addChild(fG4OpenInventorSceneHandler.fRoot); 118 100 119 // SoImageWriter should be the last. 101 // SoImageWriter should be the last. 120 fSoImageWriter = new SoImageWriter(); 102 fSoImageWriter = new SoImageWriter(); 121 fSoImageWriter->fileName.setValue("g4out.ps" 103 fSoImageWriter->fileName.setValue("g4out.ps"); 122 fSoSelection->addChild(fSoImageWriter); 104 fSoSelection->addChild(fSoImageWriter); 123 105 124 // Sensors : 106 // Sensors : 125 // To detect that the viewer had changed the 107 // To detect that the viewer had changed the camera type : 126 fGroupCameraSensor = new SoNodeSensor(GroupC 108 fGroupCameraSensor = new SoNodeSensor(GroupCameraSensorCB,this); 127 fGroupCameraSensor->setPriority(0);//Needed 109 fGroupCameraSensor->setPriority(0);//Needed in order to do getTriggerNode() 128 fGroupCameraSensor->attach(group); 110 fGroupCameraSensor->attach(group); 129 // FWJ Upgraded the group sensor so the came << 111 130 // fCameraSensor = new SoNodeSensor(CameraS << 112 fCameraSensor = new SoNodeSensor(CameraSensorCB,this); 131 // fCameraSensor->setPriority(0);//Needed i << 113 fCameraSensor->setPriority(0);//Needed in order to do getTriggerNode() 132 // fCameraSensor->attach(camera); << 133 } 114 } 134 115 135 G4OpenInventorViewer::~G4OpenInventorViewer () 116 G4OpenInventorViewer::~G4OpenInventorViewer () { 136 // fCameraSensor->detach(); << 117 fCameraSensor->detach(); 137 // delete fCameraSensor; << 118 delete fCameraSensor; 138 fGroupCameraSensor->detach(); 119 fGroupCameraSensor->detach(); 139 delete fGroupCameraSensor; 120 delete fGroupCameraSensor; 140 fSoSelection->unref(); 121 fSoSelection->unref(); 141 } 122 } 142 123 143 void G4OpenInventorViewer::KernelVisitDecision 124 void G4OpenInventorViewer::KernelVisitDecision () { 144 125 145 // If there's a significant difference with 126 // If there's a significant difference with the last view parameters 146 // of either the scene handler or this viewe 127 // of either the scene handler or this viewer, trigger a rebuild. 147 128 148 if ( 129 if ( 149 //??fG4OpenInventorSceneHandler.fPODLLis 130 //??fG4OpenInventorSceneHandler.fPODLList.size() == 0 || 150 // We need a test for empty scene graph, 131 // We need a test for empty scene graph, such as 151 // staticRoot.size() or something??????? 132 // staticRoot.size() or something?????????? See temporary fix 152 // in contructor. (John Allison Aug 200 133 // in contructor. (John Allison Aug 2001) 153 CompareForKernelVisit(fLastVP)) { 134 CompareForKernelVisit(fLastVP)) { 154 NeedKernelVisit (); 135 NeedKernelVisit (); 155 } 136 } >> 137 fLastVP = fVP; 156 } 138 } 157 139 158 G4bool G4OpenInventorViewer::CompareForKernelV 140 G4bool G4OpenInventorViewer::CompareForKernelVisit(G4ViewParameters& vp) { 159 141 160 if ( 142 if ( 161 (vp.GetDrawingStyle () != fVP.GetDraw 143 (vp.GetDrawingStyle () != fVP.GetDrawingStyle ()) || 162 (vp.GetNumberOfCloudPoints() != fVP.Get << 144 (vp.GetRepStyle () != fVP.GetRepStyle ()) || 163 (vp.IsAuxEdgeVisible () != fVP.IsAuxEd << 164 (vp.IsCulling () != fVP.IsCulli 145 (vp.IsCulling () != fVP.IsCulling ()) || 165 (vp.IsCullingInvisible () != fVP.IsCulli 146 (vp.IsCullingInvisible () != fVP.IsCullingInvisible ()) || 166 (vp.IsDensityCulling () != fVP.IsDensi 147 (vp.IsDensityCulling () != fVP.IsDensityCulling ()) || 167 (vp.IsCullingCovered () != fVP.IsCulli 148 (vp.IsCullingCovered () != fVP.IsCullingCovered ()) || 168 (vp.GetCBDAlgorithmNumber() != << 169 fVP.GetCBDAlgorithmNumber()) << 170 (vp.IsSection () != fVP.IsSecti 149 (vp.IsSection () != fVP.IsSection ()) || >> 150 // No need to visit kernel if section plane changes. 171 (vp.IsCutaway () != fVP.IsCutaw 151 (vp.IsCutaway () != fVP.IsCutaway ()) || 172 // This assumes use of generic clipping << 152 (vp.GetCutawayPlanes ().size () != 173 // DCUT, cutaway). If a decision is mad << 153 fVP.GetCutawayPlanes ().size ()) || 174 // this will need changing. See G4OpenG << 154 // No need to visit kernel if cutaway planes change. 175 // G4OpenGLStoredViewer.cc::CompareForKe << 176 // G4OpenGLStoredSceneHander::CreateSect << 177 (vp.IsExplode () != fVP.IsExplo 155 (vp.IsExplode () != fVP.IsExplode ()) || 178 (vp.GetNoOfSides () != fVP.GetNoOf << 156 (vp.GetNoOfSides () != fVP.GetNoOfSides ()) 179 (vp.GetGlobalMarkerScale() != fVP.Get << 157 ) { 180 (vp.GetGlobalLineWidthScale() != fVP.Get << 158 return true;; 181 (vp.IsMarkerNotHidden () != fVP.IsMarke << 159 } 182 (vp.GetDefaultVisAttributes()->GetColour << 183 fVP.GetDefaultVisAttributes()->GetColou << 184 (vp.GetDefaultTextVisAttributes()->GetCo << 185 fVP.GetDefaultTextVisAttributes()->GetC << 186 (vp.GetBackgroundColour ()!= fVP.GetBack << 187 (vp.IsPicking () != fVP.IsPicki << 188 // Scaling for Open Inventor is done by << 189 // needs a kernel visit. (In this respe << 190 // OpenGL drivers, where it's done in Se << 191 (vp.GetScaleFactor () != fVP.GetScal << 192 (vp.GetVisAttributesModifiers() != << 193 fVP.GetVisAttributesModifiers()) << 194 (vp.IsSpecialMeshRendering() != << 195 fVP.IsSpecialMeshRendering()) << 196 (vp.GetSpecialMeshRenderingOption() != << 197 fVP.GetSpecialMeshRenderingOption()) << 198 ) << 199 return true; << 200 << 201 if (vp.IsDensityCulling () && 160 if (vp.IsDensityCulling () && 202 (vp.GetVisibleDensity () != fVP.GetVisib 161 (vp.GetVisibleDensity () != fVP.GetVisibleDensity ())) 203 return true; 162 return true; 204 163 205 if (vp.GetCBDAlgorithmNumber() > 0) { << 206 if (vp.GetCBDParameters().size() != fVP.Ge << 207 else if (vp.GetCBDParameters() != fVP.GetC << 208 } << 209 << 210 if (vp.IsSection () && << 211 (vp.GetSectionPlane () != fVP.GetSection << 212 return true; << 213 << 214 if (vp.IsCutaway ()) { << 215 if (vp.GetCutawayMode() != fVP.GetCutawayM << 216 if (vp.GetCutawayPlanes ().size () != << 217 fVP.GetCutawayPlanes ().size ()) return true << 218 for (size_t i = 0; i < vp.GetCutawayPlanes << 219 if (vp.GetCutawayPlanes()[i] != fVP.GetC << 220 return true; << 221 } << 222 << 223 if (vp.IsExplode () && 164 if (vp.IsExplode () && 224 (vp.GetExplodeFactor () != fVP.GetExplod 165 (vp.GetExplodeFactor () != fVP.GetExplodeFactor ())) 225 return true; 166 return true; 226 167 227 if (vp.IsSpecialMeshRendering() && << 228 (vp.GetSpecialMeshVolumes() != fVP.GetSp << 229 return true; << 230 << 231 return false; 168 return false; 232 } 169 } 233 170 234 void G4OpenInventorViewer::ClearView () { 171 void G4OpenInventorViewer::ClearView () { 235 } 172 } 236 173 237 void G4OpenInventorViewer::SetView () { 174 void G4OpenInventorViewer::SetView () { 238 175 239 // Get G4 camera infos : 176 // Get G4 camera infos : 240 const G4Point3D target 177 const G4Point3D target 241 = fSceneHandler.GetScene()->GetStandardTar 178 = fSceneHandler.GetScene()->GetStandardTargetPoint() 242 + fVP.GetCurrentTargetPoint (); 179 + fVP.GetCurrentTargetPoint (); 243 G4double radius = fSceneHandler.GetScene()-> 180 G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius(); 244 if(radius<=0.) radius = 1.; 181 if(radius<=0.) radius = 1.; 245 const G4double cameraDistance = fVP.GetCamer 182 const G4double cameraDistance = fVP.GetCameraDistance (radius); 246 const G4Vector3D& direction = fVP.GetViewpoi 183 const G4Vector3D& direction = fVP.GetViewpointDirection().unit(); 247 const G4Point3D cameraPosition = target + ca 184 const G4Point3D cameraPosition = target + cameraDistance * direction; 248 //const G4double pnear = fVP.GetNearDistance 185 //const G4double pnear = fVP.GetNearDistance (cameraDistance, radius); 249 //const G4double pfar = fVP.GetFarDistance 186 //const G4double pfar = fVP.GetFarDistance (cameraDistance, pnear, radius); 250 const G4Normal3D& up = fVP.GetUpVector (); 187 const G4Normal3D& up = fVP.GetUpVector (); 251 188 252 /* 189 /* 253 printf("debug : target : %g %g %g\n",target. 190 printf("debug : target : %g %g %g\n",target.x(), 254 target. 191 target.y(), 255 target. 192 target.z()); 256 printf("debug : dir : %g %g %g\n",direction. 193 printf("debug : dir : %g %g %g\n",direction.x(), 257 direction. 194 direction.y(), 258 direction. 195 direction.z()); 259 printf("debug : pos : %g %g %g\n",cameraPosi 196 printf("debug : pos : %g %g %g\n",cameraPosition.x(), 260 cameraPosi 197 cameraPosition.y(), 261 cameraPosi 198 cameraPosition.z()); 262 //printf("debug : near %g far %g\n",pnear,pf 199 //printf("debug : near %g far %g\n",pnear,pfar); 263 */ 200 */ 264 201 265 SoCamera* camera = GetCamera(); 202 SoCamera* camera = GetCamera(); 266 if(!camera) return; 203 if(!camera) return; 267 204 268 // viewer camera setup : 205 // viewer camera setup : 269 camera->position.setValue((float)cameraPosit 206 camera->position.setValue((float)cameraPosition.x(), 270 (float)cameraPo 207 (float)cameraPosition.y(), 271 (float)cameraPo 208 (float)cameraPosition.z()); 272 209 273 SbVec3f sbTarget((float)target.x(), 210 SbVec3f sbTarget((float)target.x(), 274 (float)target.y(), 211 (float)target.y(), 275 (float)target.z()); 212 (float)target.z()); 276 SbVec3f sbUp((float)up.x(), 213 SbVec3f sbUp((float)up.x(), 277 (float)up.y(), 214 (float)up.y(), 278 (float)up.z()); 215 (float)up.z()); 279 sbUp.normalize(); 216 sbUp.normalize(); 280 // Need Coin's camera->pointAt(sbTarget,sbUp 217 // Need Coin's camera->pointAt(sbTarget,sbUp); not in the SGI API 281 // Stole Coin's code... 218 // Stole Coin's code... 282 pointAt(camera,sbTarget,sbUp); 219 pointAt(camera,sbTarget,sbUp); 283 220 284 //camera->height.setValue(10); 221 //camera->height.setValue(10); 285 //camera->nearDistance.setValue((float)pnear 222 //camera->nearDistance.setValue((float)pnear); 286 //camera->farDistance.setValue((float)pfar); 223 //camera->farDistance.setValue((float)pfar); 287 //camera->focalDistance.setValue((float)came 224 //camera->focalDistance.setValue((float)cameraDistance); 288 225 289 if(camera->isOfType(SoOrthographicCamera::ge 226 if(camera->isOfType(SoOrthographicCamera::getClassTypeId())) { 290 if (fVP.GetFieldHalfAngle() == 0.) { 227 if (fVP.GetFieldHalfAngle() == 0.) { 291 //FIXME : ((SoOrthographicCamera*)camera 228 //FIXME : ((SoOrthographicCamera*)camera)->height.setValue(); 292 //FIXME : (Don't think we have to do tha 229 //FIXME : (Don't think we have to do that.) 293 } else { 230 } else { 294 //FIXME : Have to set a perspective came 231 //FIXME : Have to set a perspective camera ! 295 //FIXME : viewer->setCameraType(SoPerspe 232 //FIXME : viewer->setCameraType(SoPerspectiveCamera::getClassTypeId()) 296 //FIXME : ((SoPerspectiveCamera*)camera) 233 //FIXME : ((SoPerspectiveCamera*)camera)->heightAngle.setValue 297 //FIXME : (2.*fVP.GetFieldHalfAngle()) 234 //FIXME : (2.*fVP.GetFieldHalfAngle()); 298 } 235 } 299 } else if(camera->isOfType(SoPerspectiveCame 236 } else if(camera->isOfType(SoPerspectiveCamera::getClassTypeId())) { 300 if (fVP.GetFieldHalfAngle() == 0.) { 237 if (fVP.GetFieldHalfAngle() == 0.) { 301 //FIXME : Have to set an orthographic ca 238 //FIXME : Have to set an orthographic camera ! 302 //FIXME : viewer->setCameraType(SoOrthog 239 //FIXME : viewer->setCameraType(SoOrthographicCamera::getClassTypeId()) 303 } else { 240 } else { 304 //FIXME : ((SoPerspectiveCamera*)camera) 241 //FIXME : ((SoPerspectiveCamera*)camera)->heightAngle.setValue 305 //FIXME : (2.*fVP.GetFieldHalfAngle()) 242 //FIXME : (2.*fVP.GetFieldHalfAngle()); 306 } 243 } 307 } 244 } >> 245 >> 246 308 } 247 } 309 248 310 //COIN_FUNCTION_EXTENSION 249 //COIN_FUNCTION_EXTENSION 311 void 250 void 312 G4OpenInventorViewer::pointAt(SoCamera* camera 251 G4OpenInventorViewer::pointAt(SoCamera* camera,const SbVec3f & targetpoint, const SbVec3f & upvector) 313 { 252 { 314 SbVec3f dir = targetpoint - camera->position 253 SbVec3f dir = targetpoint - camera->position.getValue(); 315 if (dir.normalize() == 0.0f) return; 254 if (dir.normalize() == 0.0f) return; 316 lookAt(camera,dir, upvector); 255 lookAt(camera,dir, upvector); 317 } 256 } 318 257 319 //COIN_FUNCTION 258 //COIN_FUNCTION 320 // Private method that calculates a new orient 259 // Private method that calculates a new orientation based on camera 321 // direction and camera up vector. Vectors mus 260 // direction and camera up vector. Vectors must be unit length. 322 void 261 void 323 G4OpenInventorViewer::lookAt(SoCamera* camera, 262 G4OpenInventorViewer::lookAt(SoCamera* camera,const SbVec3f & dir, const SbVec3f & up) 324 { 263 { 325 SbVec3f z = -dir; 264 SbVec3f z = -dir; 326 SbVec3f y = up; 265 SbVec3f y = up; 327 SbVec3f x = y.cross(z); 266 SbVec3f x = y.cross(z); 328 267 329 // recompute y to create a valid coordinate 268 // recompute y to create a valid coordinate system 330 y = z.cross(x); 269 y = z.cross(x); 331 270 332 // normalize x and y to create an orthonorma 271 // normalize x and y to create an orthonormal coord system 333 y.normalize(); 272 y.normalize(); 334 x.normalize(); 273 x.normalize(); 335 274 336 // create a rotation matrix 275 // create a rotation matrix 337 SbMatrix rot = SbMatrix::identity(); 276 SbMatrix rot = SbMatrix::identity(); 338 rot[0][0] = x[0]; 277 rot[0][0] = x[0]; 339 rot[0][1] = x[1]; 278 rot[0][1] = x[1]; 340 rot[0][2] = x[2]; 279 rot[0][2] = x[2]; 341 280 342 rot[1][0] = y[0]; 281 rot[1][0] = y[0]; 343 rot[1][1] = y[1]; 282 rot[1][1] = y[1]; 344 rot[1][2] = y[2]; 283 rot[1][2] = y[2]; 345 284 346 rot[2][0] = z[0]; 285 rot[2][0] = z[0]; 347 rot[2][1] = z[1]; 286 rot[2][1] = z[1]; 348 rot[2][2] = z[2]; 287 rot[2][2] = z[2]; 349 288 350 camera->orientation.setValue(SbRotation(rot) 289 camera->orientation.setValue(SbRotation(rot)); 351 } 290 } 352 291 353 void 292 void 354 G4OpenInventorViewer::lookedAt(SoCamera* camer 293 G4OpenInventorViewer::lookedAt(SoCamera* camera,SbVec3f & dir, SbVec3f & up) 355 { 294 { 356 SbRotation rot = camera->orientation.getValu 295 SbRotation rot = camera->orientation.getValue(); 357 SbMatrix mrot; rot.getValue(mrot); 296 SbMatrix mrot; rot.getValue(mrot); 358 297 359 SbVec3f x, y, z; 298 SbVec3f x, y, z; 360 299 361 // create a rotation matrix 300 // create a rotation matrix 362 x[0] = mrot[0][0]; 301 x[0] = mrot[0][0]; 363 x[1] = mrot[0][1]; 302 x[1] = mrot[0][1]; 364 x[2] = mrot[0][2]; 303 x[2] = mrot[0][2]; 365 304 366 y[0] = mrot[1][0]; 305 y[0] = mrot[1][0]; 367 y[1] = mrot[1][1]; 306 y[1] = mrot[1][1]; 368 y[2] = mrot[1][2]; 307 y[2] = mrot[1][2]; 369 308 370 z[0] = mrot[2][0]; 309 z[0] = mrot[2][0]; 371 z[1] = mrot[2][1]; 310 z[1] = mrot[2][1]; 372 z[2] = mrot[2][2]; 311 z[2] = mrot[2][2]; 373 312 374 dir = -z; 313 dir = -z; 375 dir.normalize(); 314 dir.normalize(); 376 up = SbVec3f(0.f,1.f,0.f); // Choose y-axis 315 up = SbVec3f(0.f,1.f,0.f); // Choose y-axis if possible. 377 if (std::abs(up.dot(z)) > 1.e-6) { 316 if (std::abs(up.dot(z)) > 1.e-6) { 378 up = y; 317 up = y; 379 up.normalize(); 318 up.normalize(); 380 } 319 } 381 } 320 } 382 321 383 void G4OpenInventorViewer::DrawView () { 322 void G4OpenInventorViewer::DrawView () { 384 //G4cout << "debug Iv::DrawViewer " <<G4endl 323 //G4cout << "debug Iv::DrawViewer " <<G4endl; 385 if (!fNeedKernelVisit) KernelVisitDecision() << 324 KernelVisitDecision(); 386 fLastVP= fVP; << 387 ProcessView(); 325 ProcessView(); 388 FinishView(); 326 FinishView(); 389 } 327 } 390 328 391 void G4OpenInventorViewer::ShowView () { 329 void G4OpenInventorViewer::ShowView () { 392 fInteractorManager -> SecondaryLoop (); 330 fInteractorManager -> SecondaryLoop (); 393 } 331 } 394 332 395 // FWJ This sensor now performs the fVP update << 333 void G4OpenInventorViewer::GroupCameraSensorCB(void* aThis,SoSensor* aSensor){ 396 void G4OpenInventorViewer::GroupCameraSensorCB << 397 { << 398 G4OpenInventorViewer* This = (G4OpenInventor 334 G4OpenInventorViewer* This = (G4OpenInventorViewer*)aThis; 399 335 400 SoNode* node = ((SoNodeSensor*)aSensor)->get 336 SoNode* node = ((SoNodeSensor*)aSensor)->getTriggerNode(); 401 // printf("debug : GroupCameraSensorCB %s\n << 337 //printf("debug : GroupCameraSensorCB %s\n", 402 // node->getTypeId().getName().getSt << 338 //node->getTypeId().getName().getString()); 403 339 404 if(node->isOfType(SoCamera::getClassTypeId() 340 if(node->isOfType(SoCamera::getClassTypeId())) { 405 SoCamera* camera = (SoCamera*)node; << 406 << 407 // FWJ DEBUG << 408 // G4cout << " UPDATING fVP FROM CAME << 409 SbVec3f direction, up; << 410 lookedAt(camera, direction, up); << 411 This->fVP.SetViewpointDirection << 412 (G4Vector3D(-direction[0], -direction[1] << 413 This->fVP.SetUpVector(G4Vector3D(up[0], up << 414 << 415 SbVec3f pos = camera->position.getValue(); << 416 SbVec3f target = pos + direction * camera- << 417 << 418 This->fVP.SetCurrentTargetPoint(G4Point3D( << 419 << 420 // FWJ camera sensor no longer needed << 421 // Viewer had changed the camera type, 341 // Viewer had changed the camera type, 422 // attach the fCameraSensor to the new cam 342 // attach the fCameraSensor to the new camera. 423 // FWJ DEBUG << 343 SoCamera* camera = (SoCamera*)node; 424 // G4cout << " SWITCHING TO CAMERA " << 344 This->fCameraSensor->detach(); 425 // This->fCameraSensor->detach(); << 345 This->fCameraSensor->attach(camera); 426 // This->fCameraSensor->attach(camera); << 427 } 346 } 428 347 429 } 348 } 430 349 431 /* FWJ This sensor is no longer needed << 432 void G4OpenInventorViewer::CameraSensorCB(void 350 void G4OpenInventorViewer::CameraSensorCB(void* aThis,SoSensor* aSensor) { 433 G4OpenInventorViewer* This = (G4OpenInventor 351 G4OpenInventorViewer* This = (G4OpenInventorViewer*)aThis; 434 352 435 // printf("debug : CameraSensorCB\n"); << 353 //printf("debug : CameraSensorCB\n"); 436 354 437 SoNode* node = ((SoNodeSensor*)aSensor)->get 355 SoNode* node = ((SoNodeSensor*)aSensor)->getTriggerNode(); 438 // printf("debug : CameraSensorCB %s\n", << 439 // node->getTypeId().getName().getStri << 440 356 441 if(node->isOfType(SoCamera::getClassTypeId() 357 if(node->isOfType(SoCamera::getClassTypeId())) { 442 SoCamera* camera = (SoCamera*)node; 358 SoCamera* camera = (SoCamera*)node; 443 359 444 SbVec3f direction, up; 360 SbVec3f direction, up; 445 lookedAt(camera,direction, up); 361 lookedAt(camera,direction, up); 446 This->fVP.SetViewpointDirection 362 This->fVP.SetViewpointDirection 447 (G4Vector3D(-direction[0],-direction[1], 363 (G4Vector3D(-direction[0],-direction[1],-direction[2])); 448 This->fVP.SetUpVector(G4Vector3D(up[0],up[ 364 This->fVP.SetUpVector(G4Vector3D(up[0],up[1],up[2])); 449 365 450 SbVec3f pos = camera->position.getValue(); 366 SbVec3f pos = camera->position.getValue(); 451 SbVec3f target = pos + direction * camera- 367 SbVec3f target = pos + direction * camera->focalDistance.getValue(); 452 368 453 This->fVP.SetCurrentTargetPoint(G4Point3D( 369 This->fVP.SetCurrentTargetPoint(G4Point3D(target[0],target[1],target[2])); 454 } 370 } 455 } 371 } 456 */ << 457 372 458 void G4OpenInventorViewer::SelectionCB( 373 void G4OpenInventorViewer::SelectionCB( 459 void* aThis 374 void* aThis 460 ,SoPath* aPath 375 ,SoPath* aPath 461 ) 376 ) 462 { 377 { 463 G4OpenInventorViewer* This = (G4OpenInventor 378 G4OpenInventorViewer* This = (G4OpenInventorViewer*)aThis; 464 SoNode* node = ((SoFullPath*)aPath)->getTail 379 SoNode* node = ((SoFullPath*)aPath)->getTail(); 465 G4AttHolder* attHolder = dynamic_cast<G4AttH << 380 G4String name((char*)node->getName().getString()); 466 if(attHolder && attHolder->GetAttDefs().size << 381 G4String cls((char*)node->getTypeId().getName().getString()); 467 for (size_t i = 0; i < attHolder->GetAttDe << 382 G4cout << "SoNode : " << node 468 G4cout << G4AttCheck(attHolder->GetAttVa << 383 << " SoType : " << cls 469 attHolder->GetAttDefs()[i]); << 384 << " name : " << name 470 } << 385 << G4endl; 471 } else { << 386 /*FIXME : to explore 472 G4String name((char*)node->getName().getSt << 473 G4String cls((char*)node->getTypeId().getN << 474 G4cout << "SoNode : " << node << 475 << " SoType : " << cls << 476 << " name : " << name << 477 << G4endl; << 478 G4cout << "No attributes attached." << G4e << 479 } << 480 /*FIXME : to explore (need different button << 481 if(node->isOfType(Geant4_SoPolyhedron::getCl 387 if(node->isOfType(Geant4_SoPolyhedron::getClassTypeId())) { 482 Geant4_SoPolyhedron* polyhedron = (Geant4_ 388 Geant4_SoPolyhedron* polyhedron = (Geant4_SoPolyhedron*)node; 483 if(polyhedron->solid.getValue()==FALSE) 389 if(polyhedron->solid.getValue()==FALSE) 484 polyhedron->solid.setValue(TRUE); 390 polyhedron->solid.setValue(TRUE); 485 else 391 else 486 polyhedron->solid.setValue(FALSE); 392 polyhedron->solid.setValue(FALSE); 487 }*/ 393 }*/ 488 This->fSoSelection->deselectAll(); 394 This->fSoSelection->deselectAll(); 489 } 395 } 490 /* 396 /* 491 void G4OpenInventorViewer::DeselectionCB( 397 void G4OpenInventorViewer::DeselectionCB( 492 void* aThis 398 void* aThis 493 ,SoPath* aPath 399 ,SoPath* aPath 494 ) 400 ) 495 { 401 { 496 //G4OpenInventorViewer* This = (G4OpenInvent 402 //G4OpenInventorViewer* This = (G4OpenInventorViewer*)aThis; 497 G4String name((char*)aPath->getTail()->getTy 403 G4String name((char*)aPath->getTail()->getTypeId().getName().getString()); 498 G4cout << "Deselect : " << name << G4endl; 404 G4cout << "Deselect : " << name << G4endl; 499 } 405 } 500 */ 406 */ 501 407 502 void G4OpenInventorViewer::DrawDetector() { 408 void G4OpenInventorViewer::DrawDetector() { 503 /* Replace this... - JA << 504 // DrawView does a ClearStore. Do not clear 409 // DrawView does a ClearStore. Do not clear the transient store : 505 SoSeparator* tmp = fG4OpenInventorSceneHandl 410 SoSeparator* tmp = fG4OpenInventorSceneHandler.fTransientRoot; 506 fG4OpenInventorSceneHandler.fTransientRoot = 411 fG4OpenInventorSceneHandler.fTransientRoot = new SoSeparator; 507 if (!fNeedKernelVisit) KernelVisitDecision() << 412 KernelVisitDecision(); 508 ProcessView(); 413 ProcessView(); 509 fG4OpenInventorSceneHandler.fTransientRoot-> 414 fG4OpenInventorSceneHandler.fTransientRoot->unref(); 510 fG4OpenInventorSceneHandler.fTransientRoot = 415 fG4OpenInventorSceneHandler.fTransientRoot = tmp; 511 */ << 512 // ...by this... - JA << 513 DrawView(); << 514 } 416 } 515 417 516 ////////////////////////////////////////////// 418 ////////////////////////////////////////////////////////////////////////////// 517 /// Menu items callbacks ///////////////////// 419 /// Menu items callbacks ///////////////////////////////////////////////////// 518 ////////////////////////////////////////////// 420 ////////////////////////////////////////////////////////////////////////////// 519 421 520 void G4OpenInventorViewer::Escape(){ 422 void G4OpenInventorViewer::Escape(){ 521 G4cout << "Escape..." <<G4endl; 423 G4cout << "Escape..." <<G4endl; 522 fInteractorManager->RequireExitSecondaryLoop 424 fInteractorManager->RequireExitSecondaryLoop (OIV_EXIT_CODE); 523 } 425 } 524 426 525 void G4OpenInventorViewer::WritePostScript(con 427 void G4OpenInventorViewer::WritePostScript(const G4String& aFile) { 526 if(!fGL2PSAction) return; 428 if(!fGL2PSAction) return; 527 fGL2PSAction->setFileName(aFile.c_str()); 429 fGL2PSAction->setFileName(aFile.c_str()); 528 fGL2PSAction->setExportImageFormat_EPS(); << 529 fGL2PSAction->setTitleAndProducer("Geant4 ou << 530 G4cout << "Produce " << aFile << "..." << G4 << 531 if (fGL2PSAction->enableFileWriting()) { << 532 ViewerRender(); << 533 fGL2PSAction->disableFileWriting(); << 534 } << 535 } << 536 << 537 void G4OpenInventorViewer::WritePDF(const G4St << 538 if(!fGL2PSAction) return; << 539 fGL2PSAction->setFileName(aFile.c_str()); << 540 fGL2PSAction->setExportImageFormat_PDF(); << 541 fGL2PSAction->setTitleAndProducer("Geant4 ou << 542 G4cout << "Produce " << aFile << "..." << G4 430 G4cout << "Produce " << aFile << "..." << G4endl; 543 if (fGL2PSAction->enableFileWriting()) { << 431 fGL2PSAction->enableFileWriting(); 544 ViewerRender(); << 432 ViewerRender(); 545 fGL2PSAction->disableFileWriting(); << 433 fGL2PSAction->disableFileWriting(); 546 } << 547 } 434 } 548 435 549 void G4OpenInventorViewer::WritePixmapPostScri 436 void G4OpenInventorViewer::WritePixmapPostScript(const G4String& aFile) { 550 fSoImageWriter->fileName.setValue(aFile.c_st 437 fSoImageWriter->fileName.setValue(aFile.c_str()); 551 //imageWriter->format.setValue(SoImageWriter 438 //imageWriter->format.setValue(SoImageWriter::POST_SCRIPT); 552 fSoImageWriter->enable(); 439 fSoImageWriter->enable(); 553 ViewerRender(); 440 ViewerRender(); 554 fSoImageWriter->disable(); 441 fSoImageWriter->disable(); 555 if(fSoImageWriter->getStatus()) { 442 if(fSoImageWriter->getStatus()) { 556 G4cout << G4String(fSoImageWriter->fileNam 443 G4cout << G4String(fSoImageWriter->fileName.getValue().getString()) 557 << " produced." 444 << " produced." 558 << G4endl; 445 << G4endl; 559 } else { 446 } else { 560 G4cout << G4String(fSoImageWriter->fileNam 447 G4cout << G4String(fSoImageWriter->fileName.getValue().getString()) 561 << " not produced." 448 << " not produced." 562 << G4endl; 449 << G4endl; 563 } 450 } 564 } 451 } 565 452 566 void G4OpenInventorViewer::WriteInventor(const 453 void G4OpenInventorViewer::WriteInventor(const G4String& aFile) { 567 G4cout << "Produce " << aFile << "..." << G4 454 G4cout << "Produce " << aFile << "..." << G4endl; 568 << 569 SbBool genAlternateRep = TRUE; << 570 //SbBool binary = FALSE; << 571 SbBool binary = TRUE; << 572 SoAlternateRepAction alternateRepAction; << 573 if(genAlternateRep==TRUE) { << 574 alternateRepAction.setGenerate(TRUE); //Cl << 575 alternateRepAction.apply(fSoSelection); << 576 } << 577 << 578 SoWriteAction writeAction; 455 SoWriteAction writeAction; 579 writeAction.getOutput()->openFile(aFile.c_st 456 writeAction.getOutput()->openFile(aFile.c_str()); 580 writeAction.getOutput()->setBinary(binary); << 457 writeAction.getOutput()->setBinary(FALSE); 581 writeAction.apply(fSoSelection); 458 writeAction.apply(fSoSelection); 582 writeAction.getOutput()->closeFile(); 459 writeAction.getOutput()->closeFile(); 583 << 584 if(genAlternateRep==TRUE) { << 585 alternateRepAction.setGenerate(FALSE); //C << 586 alternateRepAction.apply(fSoSelection); << 587 } << 588 << 589 << 590 << 591 } 460 } 592 461 593 struct Counter { 462 struct Counter { 594 int fTriangles; 463 int fTriangles; 595 int fLineSegments; 464 int fLineSegments; 596 int fPoints; 465 int fPoints; 597 }; 466 }; 598 467 599 static void CountTrianglesCB( 468 static void CountTrianglesCB( 600 void* userData 469 void* userData 601 ,SoCallbackAction* 470 ,SoCallbackAction* 602 ,const SoPrimitiveVertex* 471 ,const SoPrimitiveVertex* 603 ,const SoPrimitiveVertex*, 472 ,const SoPrimitiveVertex*, 604 const SoPrimitiveVertex*) 473 const SoPrimitiveVertex*) 605 { 474 { 606 Counter* counter = (Counter*)userData; 475 Counter* counter = (Counter*)userData; 607 counter->fTriangles++; 476 counter->fTriangles++; 608 } 477 } 609 478 610 static void CountLineSegmentsCB( 479 static void CountLineSegmentsCB( 611 void* userData 480 void* userData 612 ,SoCallbackAction* 481 ,SoCallbackAction* 613 ,const SoPrimitiveVertex* 482 ,const SoPrimitiveVertex* 614 ,const SoPrimitiveVertex*) 483 ,const SoPrimitiveVertex*) 615 { 484 { 616 Counter* counter = (Counter*)userData; 485 Counter* counter = (Counter*)userData; 617 counter->fLineSegments++; 486 counter->fLineSegments++; 618 } 487 } 619 488 620 static void CountPointsCB( 489 static void CountPointsCB( 621 void* userData 490 void* userData 622 ,SoCallbackAction* 491 ,SoCallbackAction* 623 ,const SoPrimitiveVertex*) 492 ,const SoPrimitiveVertex*) 624 { 493 { 625 Counter* counter = (Counter*)userData; 494 Counter* counter = (Counter*)userData; 626 counter->fPoints++; 495 counter->fPoints++; 627 } 496 } 628 497 629 void G4OpenInventorViewer::SceneGraphStatistic 498 void G4OpenInventorViewer::SceneGraphStatistics() { 630 Counter counter; 499 Counter counter; 631 counter.fTriangles = 0; 500 counter.fTriangles = 0; 632 counter.fLineSegments = 0; 501 counter.fLineSegments = 0; 633 counter.fPoints = 0; 502 counter.fPoints = 0; 634 503 635 SoCallbackAction callbackAction; 504 SoCallbackAction callbackAction; 636 callbackAction.addTriangleCallback 505 callbackAction.addTriangleCallback 637 (SoShape::getClassTypeId(),CountTrianglesC 506 (SoShape::getClassTypeId(),CountTrianglesCB,(void*)&counter); 638 callbackAction.addLineSegmentCallback 507 callbackAction.addLineSegmentCallback 639 (SoShape::getClassTypeId(),CountLineSegmen 508 (SoShape::getClassTypeId(),CountLineSegmentsCB,(void*)&counter); 640 callbackAction.addPointCallback 509 callbackAction.addPointCallback 641 (SoShape::getClassTypeId(),CountPointsCB,( 510 (SoShape::getClassTypeId(),CountPointsCB,(void*)&counter); 642 callbackAction.apply(fSoSelection); 511 callbackAction.apply(fSoSelection); 643 512 644 SoCounterAction counterAction; 513 SoCounterAction counterAction; 645 counterAction.apply(fSoSelection); 514 counterAction.apply(fSoSelection); 646 int nodes = counterAction.getCount(); 515 int nodes = counterAction.getCount(); 647 516 648 counterAction.setLookFor(SoCounterAction::TY 517 counterAction.setLookFor(SoCounterAction::TYPE); 649 counterAction.setType(SoShape::getClassTypeI 518 counterAction.setType(SoShape::getClassTypeId()); 650 counterAction.apply(fSoSelection); 519 counterAction.apply(fSoSelection); 651 int shapes = counterAction.getCount(); 520 int shapes = counterAction.getCount(); 652 521 653 G4cout << "Number of triangles : " << counte 522 G4cout << "Number of triangles : " << counter.fTriangles << G4endl; 654 G4cout << "Number of line segments : " << co 523 G4cout << "Number of line segments : " << counter.fLineSegments << G4endl; 655 G4cout << "Number of points : " << counter.f 524 G4cout << "Number of points : " << counter.fPoints << G4endl; 656 G4cout << "Number of nodes : " << nodes << G 525 G4cout << "Number of nodes : " << nodes << G4endl; 657 G4cout << "Number of shapes : " << shapes << 526 G4cout << "Number of shapes : " << shapes << G4endl; 658 } 527 } 659 528 660 void G4OpenInventorViewer::EraseDetector() { 529 void G4OpenInventorViewer::EraseDetector() { 661 fG4OpenInventorSceneHandler.fDetectorRoot->r 530 fG4OpenInventorSceneHandler.fDetectorRoot->removeAllChildren(); 662 } 531 } 663 void G4OpenInventorViewer::EraseEvent() { 532 void G4OpenInventorViewer::EraseEvent() { 664 fG4OpenInventorSceneHandler.fTransientRoot-> 533 fG4OpenInventorSceneHandler.fTransientRoot->removeAllChildren(); 665 } 534 } 666 535 667 void G4OpenInventorViewer::SetPreviewAndFull() 536 void G4OpenInventorViewer::SetPreviewAndFull() { 668 fG4OpenInventorSceneHandler.fPreviewAndFull 537 fG4OpenInventorSceneHandler.fPreviewAndFull = true; 669 538 670 NeedKernelVisit(); 539 NeedKernelVisit(); 671 DrawDetector(); 540 DrawDetector(); 672 } 541 } 673 542 674 void G4OpenInventorViewer::SetPreview() { 543 void G4OpenInventorViewer::SetPreview() { 675 fG4OpenInventorSceneHandler.fPreviewAndFull 544 fG4OpenInventorSceneHandler.fPreviewAndFull = false; 676 545 677 NeedKernelVisit(); 546 NeedKernelVisit(); 678 DrawDetector(); 547 DrawDetector(); 679 } 548 } 680 549 681 // When ViewParameter <-> SoCamera mapping rea 550 // When ViewParameter <-> SoCamera mapping ready 682 // uncomment the below 551 // uncomment the below 683 //#define USE_SET_VIEW 552 //#define USE_SET_VIEW 684 553 685 void G4OpenInventorViewer::SetSolid() { 554 void G4OpenInventorViewer::SetSolid() { 686 G4ViewParameters vp = GetViewParameters(); 555 G4ViewParameters vp = GetViewParameters(); 687 G4ViewParameters::DrawingStyle existingStyle 556 G4ViewParameters::DrawingStyle existingStyle = vp.GetDrawingStyle(); 688 //From G4VisCommandsViewerSet : /vis/viewer/ 557 //From G4VisCommandsViewerSet : /vis/viewer/set/style solid. 689 switch (existingStyle) { 558 switch (existingStyle) { 690 case G4ViewParameters::wireframe: 559 case G4ViewParameters::wireframe: 691 vp.SetDrawingStyle(G4ViewParameters::hsr); 560 vp.SetDrawingStyle(G4ViewParameters::hsr); 692 break; 561 break; 693 case G4ViewParameters::hlr: 562 case G4ViewParameters::hlr: 694 vp.SetDrawingStyle(G4ViewParameters::hlhsr 563 vp.SetDrawingStyle(G4ViewParameters::hlhsr); 695 break; 564 break; 696 case G4ViewParameters::hsr: 565 case G4ViewParameters::hsr: 697 break; 566 break; 698 case G4ViewParameters::hlhsr: 567 case G4ViewParameters::hlhsr: 699 break; 568 break; 700 case G4ViewParameters::cloud: << 701 vp.SetDrawingStyle(G4ViewParameters::hsr); << 702 break; << 703 } 569 } 704 SetViewParameters(vp); 570 SetViewParameters(vp); >> 571 fModified = false; // To avoid a SetView in G4VViewer::ProcessView >> 572 // that will change the camera. 705 DrawDetector(); 573 DrawDetector(); 706 } 574 } 707 void G4OpenInventorViewer::SetWireFrame() { 575 void G4OpenInventorViewer::SetWireFrame() { 708 G4ViewParameters vp = GetViewParameters(); 576 G4ViewParameters vp = GetViewParameters(); 709 G4ViewParameters::DrawingStyle existingStyle 577 G4ViewParameters::DrawingStyle existingStyle = vp.GetDrawingStyle(); 710 switch (existingStyle) { 578 switch (existingStyle) { 711 case G4ViewParameters::wireframe: 579 case G4ViewParameters::wireframe: 712 break; 580 break; 713 case G4ViewParameters::hlr: 581 case G4ViewParameters::hlr: 714 break; 582 break; 715 case G4ViewParameters::hsr: 583 case G4ViewParameters::hsr: 716 vp.SetDrawingStyle(G4ViewParameters::wiref 584 vp.SetDrawingStyle(G4ViewParameters::wireframe); 717 break; 585 break; 718 case G4ViewParameters::hlhsr: 586 case G4ViewParameters::hlhsr: 719 vp.SetDrawingStyle(G4ViewParameters::hlr); 587 vp.SetDrawingStyle(G4ViewParameters::hlr); 720 break; 588 break; 721 case G4ViewParameters::cloud: << 722 vp.SetDrawingStyle(G4ViewParameters::wiref << 723 break; << 724 } 589 } 725 SetViewParameters(vp); 590 SetViewParameters(vp); >> 591 fModified = false; // To avoid a SetView in G4VViewer::ProcessView >> 592 // that will change the camera. 726 DrawDetector(); 593 DrawDetector(); 727 } 594 } 728 595 729 596 730 void G4OpenInventorViewer::SetReducedWireFrame 597 void G4OpenInventorViewer::SetReducedWireFrame(bool aValue) { 731 G4ViewParameters vp = GetViewParameters(); 598 G4ViewParameters vp = GetViewParameters(); 732 599 733 // Set the wire frame kind : 600 // Set the wire frame kind : 734 vp.SetAuxEdgeVisible(!aValue); 601 vp.SetAuxEdgeVisible(!aValue); 735 602 736 // Set wire frame : 603 // Set wire frame : 737 G4ViewParameters::DrawingStyle existingStyle 604 G4ViewParameters::DrawingStyle existingStyle = vp.GetDrawingStyle(); 738 switch (existingStyle) { 605 switch (existingStyle) { 739 case G4ViewParameters::wireframe: 606 case G4ViewParameters::wireframe: 740 break; 607 break; 741 case G4ViewParameters::hlr: 608 case G4ViewParameters::hlr: 742 break; 609 break; 743 case G4ViewParameters::hsr: 610 case G4ViewParameters::hsr: 744 vp.SetDrawingStyle(G4ViewParameters::wiref 611 vp.SetDrawingStyle(G4ViewParameters::wireframe); 745 break; 612 break; 746 case G4ViewParameters::hlhsr: 613 case G4ViewParameters::hlhsr: 747 vp.SetDrawingStyle(G4ViewParameters::hlr); 614 vp.SetDrawingStyle(G4ViewParameters::hlr); 748 break; 615 break; 749 case G4ViewParameters::cloud: << 750 vp.SetDrawingStyle(G4ViewParameters::wiref << 751 break; << 752 } 616 } 753 SetViewParameters(vp); 617 SetViewParameters(vp); >> 618 fModified = false; // To avoid a SetView in G4VViewer::ProcessView >> 619 // that will change the camera. 754 NeedKernelVisit(); // Just in case it was al 620 NeedKernelVisit(); // Just in case it was alread in wire framw. 755 DrawDetector(); 621 DrawDetector(); 756 } 622 } 757 623 758 void G4OpenInventorViewer::UpdateScene() { 624 void G4OpenInventorViewer::UpdateScene() { 759 /* Replace this... - JA << 760 fG4OpenInventorSceneHandler.ClearStore(); 625 fG4OpenInventorSceneHandler.ClearStore(); 761 ClearView(); 626 ClearView(); 762 if (!fNeedKernelVisit) KernelVisitDecision() << 627 KernelVisitDecision(); 763 ProcessView(); 628 ProcessView(); 764 ShowView(); 629 ShowView(); 765 */ << 766 // ...by this - JA << 767 NeedKernelVisit(); << 768 DrawView(); << 769 } 630 } 770 G4String G4OpenInventorViewer::Help(const G4St 631 G4String G4OpenInventorViewer::Help(const G4String& aTopic) { 771 if(aTopic=="controls") { 632 if(aTopic=="controls") { 772 return G4String("\ 633 return G4String("\ 773 Controls on an Inventor examiner viewer are :\ 634 Controls on an Inventor examiner viewer are :\n\ 774 - in picking mode (cursor is the upper left ar 635 - in picking mode (cursor is the upper left arrow)\n\ 775 Ctrl + pick a volume : see daughters.\n\ 636 Ctrl + pick a volume : see daughters.\n\ 776 Shift + pick a volume : see mother.\n\ 637 Shift + pick a volume : see mother.\n\ 777 - in viewing mode (cursor is the hand)\n\ 638 - in viewing mode (cursor is the hand)\n\ 778 Left-button + pointer move : rotate.\n\ 639 Left-button + pointer move : rotate.\n\ 779 Ctrl+Left-button + pointer move : pan.\n\ 640 Ctrl+Left-button + pointer move : pan.\n\ 780 Ctrl+Shift+Left-button + pointer move : scal 641 Ctrl+Shift+Left-button + pointer move : scale.\n\ 781 Middle-button + pointer move : pan.\n\ 642 Middle-button + pointer move : pan.\n\ 782 Right-button : popup menu.\n"); 643 Right-button : popup menu.\n"); 783 } else { 644 } else { 784 return ""; 645 return ""; 785 } 646 } 786 } 647 } >> 648 >> 649 #endif 787 650