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