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