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