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