Geant4  10.00.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 66373 2012-12-18 09:41:34Z 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  G4cout << "Produce " << aFile << "..." << G4endl;
486  if (fGL2PSAction->enableFileWriting()) {
487  ViewerRender();
488  fGL2PSAction->disableFileWriting();
489  }
490 }
491 
492 void G4OpenInventorViewer::WritePixmapPostScript(const G4String& aFile) {
493  fSoImageWriter->fileName.setValue(aFile.c_str());
494  //imageWriter->format.setValue(SoImageWriter::POST_SCRIPT);
495  fSoImageWriter->enable();
496  ViewerRender();
497  fSoImageWriter->disable();
498  if(fSoImageWriter->getStatus()) {
499  G4cout << G4String(fSoImageWriter->fileName.getValue().getString())
500  << " produced."
501  << G4endl;
502  } else {
503  G4cout << G4String(fSoImageWriter->fileName.getValue().getString())
504  << " not produced."
505  << G4endl;
506  }
507 }
508 
509 void G4OpenInventorViewer::WriteInventor(const G4String& aFile) {
510  G4cout << "Produce " << aFile << "..." << G4endl;
511 
512  SbBool genAlternateRep = TRUE;
513  //SbBool binary = FALSE;
514  SbBool binary = TRUE;
515  SoAlternateRepAction alternateRepAction;
516  if(genAlternateRep==TRUE) {
517  alternateRepAction.setGenerate(TRUE); //Clear alternate reps.
518  alternateRepAction.apply(fSoSelection);
519  }
520 
521  SoWriteAction writeAction;
522  writeAction.getOutput()->openFile(aFile.c_str());
523  writeAction.getOutput()->setBinary(binary);
524  writeAction.apply(fSoSelection);
525  writeAction.getOutput()->closeFile();
526 
527  if(genAlternateRep==TRUE) {
528  alternateRepAction.setGenerate(FALSE); //Clear alternate reps.
529  alternateRepAction.apply(fSoSelection);
530  }
531 
532 
533 
534 }
535 
536 struct Counter {
537  int fTriangles;
538  int fLineSegments;
539  int fPoints;
540 };
541 
542 static void CountTrianglesCB(
543  void* userData
544 ,SoCallbackAction*
545 ,const SoPrimitiveVertex*
546 ,const SoPrimitiveVertex*,
547 const SoPrimitiveVertex*)
548 {
549  Counter* counter = (Counter*)userData;
550  counter->fTriangles++;
551 }
552 
553 static void CountLineSegmentsCB(
554  void* userData
555 ,SoCallbackAction*
556 ,const SoPrimitiveVertex*
557 ,const SoPrimitiveVertex*)
558 {
559  Counter* counter = (Counter*)userData;
560  counter->fLineSegments++;
561 }
562 
563 static void CountPointsCB(
564  void* userData
565 ,SoCallbackAction*
566 ,const SoPrimitiveVertex*)
567 {
568  Counter* counter = (Counter*)userData;
569  counter->fPoints++;
570 }
571 
572 void G4OpenInventorViewer::SceneGraphStatistics() {
573  Counter counter;
574  counter.fTriangles = 0;
575  counter.fLineSegments = 0;
576  counter.fPoints = 0;
577 
578  SoCallbackAction callbackAction;
579  callbackAction.addTriangleCallback
580  (SoShape::getClassTypeId(),CountTrianglesCB,(void*)&counter);
581  callbackAction.addLineSegmentCallback
582  (SoShape::getClassTypeId(),CountLineSegmentsCB,(void*)&counter);
583  callbackAction.addPointCallback
584  (SoShape::getClassTypeId(),CountPointsCB,(void*)&counter);
585  callbackAction.apply(fSoSelection);
586 
587  SoCounterAction counterAction;
588  counterAction.apply(fSoSelection);
589  int nodes = counterAction.getCount();
590 
591  counterAction.setLookFor(SoCounterAction::TYPE);
592  counterAction.setType(SoShape::getClassTypeId());
593  counterAction.apply(fSoSelection);
594  int shapes = counterAction.getCount();
595 
596  G4cout << "Number of triangles : " << counter.fTriangles << G4endl;
597  G4cout << "Number of line segments : " << counter.fLineSegments << G4endl;
598  G4cout << "Number of points : " << counter.fPoints << G4endl;
599  G4cout << "Number of nodes : " << nodes << G4endl;
600  G4cout << "Number of shapes : " << shapes << G4endl;
601 }
602 
603 void G4OpenInventorViewer::EraseDetector() {
604  fG4OpenInventorSceneHandler.fDetectorRoot->removeAllChildren();
605 }
606 void G4OpenInventorViewer::EraseEvent() {
607  fG4OpenInventorSceneHandler.fTransientRoot->removeAllChildren();
608 }
609 
610 void G4OpenInventorViewer::SetPreviewAndFull() {
611  fG4OpenInventorSceneHandler.fPreviewAndFull = true;
612 
613  NeedKernelVisit();
614  DrawDetector();
615 }
616 
617 void G4OpenInventorViewer::SetPreview() {
618  fG4OpenInventorSceneHandler.fPreviewAndFull = false;
619 
620  NeedKernelVisit();
621  DrawDetector();
622 }
623 
624 // When ViewParameter <-> SoCamera mapping ready
625 // uncomment the below
626 //#define USE_SET_VIEW
627 
628 void G4OpenInventorViewer::SetSolid() {
629  G4ViewParameters vp = GetViewParameters();
630  G4ViewParameters::DrawingStyle existingStyle = vp.GetDrawingStyle();
631  //From G4VisCommandsViewerSet : /vis/viewer/set/style solid.
632  switch (existingStyle) {
635  break;
638  break;
640  break;
642  break;
643  }
644  SetViewParameters(vp);
645  DrawDetector();
646 }
647 void G4OpenInventorViewer::SetWireFrame() {
648  G4ViewParameters vp = GetViewParameters();
649  G4ViewParameters::DrawingStyle existingStyle = vp.GetDrawingStyle();
650  switch (existingStyle) {
652  break;
654  break;
657  break;
660  break;
661  }
662  SetViewParameters(vp);
663  DrawDetector();
664 }
665 
666 
667 void G4OpenInventorViewer::SetReducedWireFrame(bool aValue) {
668  G4ViewParameters vp = GetViewParameters();
669 
670  // Set the wire frame kind :
671  vp.SetAuxEdgeVisible(!aValue);
672 
673  // Set wire frame :
674  G4ViewParameters::DrawingStyle existingStyle = vp.GetDrawingStyle();
675  switch (existingStyle) {
677  break;
679  break;
682  break;
685  break;
686  }
687  SetViewParameters(vp);
688  NeedKernelVisit(); // Just in case it was alread in wire framw.
689  DrawDetector();
690 }
691 
692 void G4OpenInventorViewer::UpdateScene() {
693  /* Replace this... - JA
694  fG4OpenInventorSceneHandler.ClearStore();
695  ClearView();
696  if (!fNeedKernelVisit) KernelVisitDecision();
697  ProcessView();
698  ShowView();
699  */
700  // ...by this - JA
701  NeedKernelVisit();
702  DrawView();
703 }
704 G4String G4OpenInventorViewer::Help(const G4String& aTopic) {
705  if(aTopic=="controls") {
706  return G4String("\
707 Controls on an Inventor examiner viewer are :\n\
708 - in picking mode (cursor is the upper left arrow)\n\
709  Ctrl + pick a volume : see daughters.\n\
710  Shift + pick a volume : see mother.\n\
711 - in viewing mode (cursor is the hand)\n\
712  Left-button + pointer move : rotate.\n\
713  Ctrl+Left-button + pointer move : pan.\n\
714  Ctrl+Shift+Left-button + pointer move : scale.\n\
715  Middle-button + pointer move : pan.\n\
716  Right-button : popup menu.\n");
717  } else {
718  return "";
719  }
720 }
721 
722 #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:555
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
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