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