Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 102573 2017-02-09 08:50:23Z 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 
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())->
82  GetInteractorManager();
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  // If G4OpenInventor ever introduces VAMs, the following might need
188  // changing to a complete comparison, i.e., remove ".size()". See
189  // G4OpenGLStoredViewer::CompareForKernelVisit.
190  (vp.GetVisAttributesModifiers().size() !=
191  fVP.GetVisAttributesModifiers().size())
192  )
193  return true;
194 
195  if (vp.IsDensityCulling () &&
196  (vp.GetVisibleDensity () != fVP.GetVisibleDensity ()))
197  return true;
198 
199  if (vp.IsSection () &&
200  (vp.GetSectionPlane () != fVP.GetSectionPlane ()))
201  return true;
202 
203  if (vp.IsCutaway ()) {
204  if (vp.GetCutawayPlanes ().size () !=
205  fVP.GetCutawayPlanes ().size ()) return true;
206  for (size_t i = 0; i < vp.GetCutawayPlanes().size(); ++i)
207  if (vp.GetCutawayPlanes()[i] != fVP.GetCutawayPlanes()[i])
208  return true;
209  }
210 
211  if (vp.IsExplode () &&
212  (vp.GetExplodeFactor () != fVP.GetExplodeFactor ()))
213  return true;
214 
215  return false;
216 }
217 
218 void G4OpenInventorViewer::ClearView () {
219 }
220 
221 void G4OpenInventorViewer::SetView () {
222 
223  // Get G4 camera infos :
224  const G4Point3D target
225  = fSceneHandler.GetScene()->GetStandardTargetPoint()
226  + fVP.GetCurrentTargetPoint ();
227  G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
228  if(radius<=0.) radius = 1.;
229  const G4double cameraDistance = fVP.GetCameraDistance (radius);
230  const G4Vector3D& direction = fVP.GetViewpointDirection().unit();
231  const G4Point3D cameraPosition = target + cameraDistance * direction;
232  //const G4double pnear = fVP.GetNearDistance (cameraDistance, radius);
233  //const G4double pfar = fVP.GetFarDistance (cameraDistance, pnear, radius);
234  const G4Normal3D& up = fVP.GetUpVector ();
235 
236 /*
237  printf("debug : target : %g %g %g\n",target.x(),
238  target.y(),
239  target.z());
240  printf("debug : dir : %g %g %g\n",direction.x(),
241  direction.y(),
242  direction.z());
243  printf("debug : pos : %g %g %g\n",cameraPosition.x(),
244  cameraPosition.y(),
245  cameraPosition.z());
246  //printf("debug : near %g far %g\n",pnear,pfar);
247 */
248 
249  SoCamera* camera = GetCamera();
250  if(!camera) return;
251 
252  // viewer camera setup :
253  camera->position.setValue((float)cameraPosition.x(),
254  (float)cameraPosition.y(),
255  (float)cameraPosition.z());
256 
257  SbVec3f sbTarget((float)target.x(),
258  (float)target.y(),
259  (float)target.z());
260  SbVec3f sbUp((float)up.x(),
261  (float)up.y(),
262  (float)up.z());
263  sbUp.normalize();
264  // Need Coin's camera->pointAt(sbTarget,sbUp); not in the SGI API
265  // Stole Coin's code...
266  pointAt(camera,sbTarget,sbUp);
267 
268  //camera->height.setValue(10);
269  //camera->nearDistance.setValue((float)pnear);
270  //camera->farDistance.setValue((float)pfar);
271  //camera->focalDistance.setValue((float)cameraDistance);
272 
273  if(camera->isOfType(SoOrthographicCamera::getClassTypeId())) {
274  if (fVP.GetFieldHalfAngle() == 0.) {
275  //FIXME : ((SoOrthographicCamera*)camera)->height.setValue();
276  //FIXME : (Don't think we have to do that.)
277  } else {
278  //FIXME : Have to set a perspective camera !
279  //FIXME : viewer->setCameraType(SoPerspectiveCamera::getClassTypeId())
280  //FIXME : ((SoPerspectiveCamera*)camera)->heightAngle.setValue
281  //FIXME : (2.*fVP.GetFieldHalfAngle());
282  }
283  } else if(camera->isOfType(SoPerspectiveCamera::getClassTypeId())) {
284  if (fVP.GetFieldHalfAngle() == 0.) {
285  //FIXME : Have to set an orthographic camera !
286  //FIXME : viewer->setCameraType(SoOrthographicCamera::getClassTypeId())
287  } else {
288  //FIXME : ((SoPerspectiveCamera*)camera)->heightAngle.setValue
289  //FIXME : (2.*fVP.GetFieldHalfAngle());
290  }
291  }
292 }
293 
294 //COIN_FUNCTION_EXTENSION
295 void
296 G4OpenInventorViewer::pointAt(SoCamera* camera,const SbVec3f & targetpoint, const SbVec3f & upvector)
297 {
298  SbVec3f dir = targetpoint - camera->position.getValue();
299  if (dir.normalize() == 0.0f) return;
300  lookAt(camera,dir, upvector);
301 }
302 
303 //COIN_FUNCTION
304 // Private method that calculates a new orientation based on camera
305 // direction and camera up vector. Vectors must be unit length.
306 void
307 G4OpenInventorViewer::lookAt(SoCamera* camera,const SbVec3f & dir, const SbVec3f & up)
308 {
309  SbVec3f z = -dir;
310  SbVec3f y = up;
311  SbVec3f x = y.cross(z);
312 
313  // recompute y to create a valid coordinate system
314  y = z.cross(x);
315 
316  // normalize x and y to create an orthonormal coord system
317  y.normalize();
318  x.normalize();
319 
320  // create a rotation matrix
321  SbMatrix rot = SbMatrix::identity();
322  rot[0][0] = x[0];
323  rot[0][1] = x[1];
324  rot[0][2] = x[2];
325 
326  rot[1][0] = y[0];
327  rot[1][1] = y[1];
328  rot[1][2] = y[2];
329 
330  rot[2][0] = z[0];
331  rot[2][1] = z[1];
332  rot[2][2] = z[2];
333 
334  camera->orientation.setValue(SbRotation(rot));
335 }
336 
337 void
338 G4OpenInventorViewer::lookedAt(SoCamera* camera,SbVec3f & dir, SbVec3f & up)
339 {
340  SbRotation rot = camera->orientation.getValue();
341  SbMatrix mrot; rot.getValue(mrot);
342 
343  SbVec3f x, y, z;
344 
345  // create a rotation matrix
346  x[0] = mrot[0][0];
347  x[1] = mrot[0][1];
348  x[2] = mrot[0][2];
349 
350  y[0] = mrot[1][0];
351  y[1] = mrot[1][1];
352  y[2] = mrot[1][2];
353 
354  z[0] = mrot[2][0];
355  z[1] = mrot[2][1];
356  z[2] = mrot[2][2];
357 
358  dir = -z;
359  dir.normalize();
360  up = SbVec3f(0.f,1.f,0.f); // Choose y-axis if possible.
361  if (std::abs(up.dot(z)) > 1.e-6) {
362  up = y;
363  up.normalize();
364  }
365 }
366 
367 void G4OpenInventorViewer::DrawView () {
368  //G4cout << "debug Iv::DrawViewer " <<G4endl;
369  if (!fNeedKernelVisit) KernelVisitDecision();
370  ProcessView();
371  FinishView();
372 }
373 
374 void G4OpenInventorViewer::ShowView () {
375  fInteractorManager -> SecondaryLoop ();
376 }
377 
378 void G4OpenInventorViewer::GroupCameraSensorCB(void* aThis,SoSensor* aSensor){
379  G4OpenInventorViewer* This = (G4OpenInventorViewer*)aThis;
380 
381  SoNode* node = ((SoNodeSensor*)aSensor)->getTriggerNode();
382  //printf("debug : GroupCameraSensorCB %s\n",
383  //node->getTypeId().getName().getString());
384 
385  if(node->isOfType(SoCamera::getClassTypeId())) {
386  // Viewer had changed the camera type,
387  // attach the fCameraSensor to the new camera.
388  SoCamera* camera = (SoCamera*)node;
389  This->fCameraSensor->detach();
390  This->fCameraSensor->attach(camera);
391  }
392 
393 }
394 
395 void G4OpenInventorViewer::CameraSensorCB(void* aThis,SoSensor* aSensor) {
396  G4OpenInventorViewer* This = (G4OpenInventorViewer*)aThis;
397 
398  //printf("debug : CameraSensorCB\n");
399 
400  SoNode* node = ((SoNodeSensor*)aSensor)->getTriggerNode();
401 
402  if(node->isOfType(SoCamera::getClassTypeId())) {
403  SoCamera* camera = (SoCamera*)node;
404 
405  SbVec3f direction, up;
406  lookedAt(camera,direction, up);
407  This->fVP.SetViewpointDirection
408  (G4Vector3D(-direction[0],-direction[1],-direction[2]));
409  This->fVP.SetUpVector(G4Vector3D(up[0],up[1],up[2]));
410 
411  SbVec3f pos = camera->position.getValue();
412  SbVec3f target = pos + direction * camera->focalDistance.getValue();
413 
414  This->fVP.SetCurrentTargetPoint(G4Point3D(target[0],target[1],target[2]));
415  }
416 }
417 
418 void G4OpenInventorViewer::SelectionCB(
419  void* aThis
420 ,SoPath* aPath
421 )
422 {
423  G4OpenInventorViewer* This = (G4OpenInventorViewer*)aThis;
424  SoNode* node = ((SoFullPath*)aPath)->getTail();
425  G4AttHolder* attHolder = dynamic_cast<G4AttHolder*>(node);
426  if(attHolder && attHolder->GetAttDefs().size()) {
427  for (size_t i = 0; i < attHolder->GetAttDefs().size(); ++i) {
428  G4cout << G4AttCheck(attHolder->GetAttValues()[i],
429  attHolder->GetAttDefs()[i]);
430  }
431  } else {
432  G4String name((char*)node->getName().getString());
433  G4String cls((char*)node->getTypeId().getName().getString());
434  G4cout << "SoNode : " << node
435  << " SoType : " << cls
436  << " name : " << name
437  << G4endl;
438  G4cout << "No attributes attached." << G4endl;
439  }
440  /*FIXME : to explore (need different button - this is used for picking.
441  if(node->isOfType(Geant4_SoPolyhedron::getClassTypeId())) {
442  Geant4_SoPolyhedron* polyhedron = (Geant4_SoPolyhedron*)node;
443  if(polyhedron->solid.getValue()==FALSE)
444  polyhedron->solid.setValue(TRUE);
445  else
446  polyhedron->solid.setValue(FALSE);
447  }*/
448  This->fSoSelection->deselectAll();
449 }
450 /*
451 void G4OpenInventorViewer::DeselectionCB(
452  void* aThis
453 ,SoPath* aPath
454 )
455 {
456  //G4OpenInventorViewer* This = (G4OpenInventorViewer*)aThis;
457  G4String name((char*)aPath->getTail()->getTypeId().getName().getString());
458  G4cout << "Deselect : " << name << G4endl;
459 }
460 */
461 
462 void G4OpenInventorViewer::DrawDetector() {
463  /* Replace this... - JA
464  // DrawView does a ClearStore. Do not clear the transient store :
465  SoSeparator* tmp = fG4OpenInventorSceneHandler.fTransientRoot;
466  fG4OpenInventorSceneHandler.fTransientRoot = new SoSeparator;
467  if (!fNeedKernelVisit) KernelVisitDecision();
468  ProcessView();
469  fG4OpenInventorSceneHandler.fTransientRoot->unref();
470  fG4OpenInventorSceneHandler.fTransientRoot = tmp;
471  */
472  // ...by this... - JA
473  DrawView();
474 }
475 
479 
480 void G4OpenInventorViewer::Escape(){
481  G4cout << "Escape..." <<G4endl;
482  fInteractorManager->RequireExitSecondaryLoop (OIV_EXIT_CODE);
483 }
484 
485 void G4OpenInventorViewer::WritePostScript(const G4String& aFile) {
486  if(!fGL2PSAction) return;
487  fGL2PSAction->setFileName(aFile.c_str());
488  fGL2PSAction->setExportImageFormat(GL2PS_EPS);
489  // Use gl2ps default buffer (2048*2048)
490  fGL2PSAction->setBufferSize(0);
491  G4cout << "Produce " << aFile << "..." << G4endl;
492  if (fGL2PSAction->enableFileWriting()) {
493  ViewerRender();
494  fGL2PSAction->disableFileWriting();
495  }
496  fGL2PSAction->resetBufferSizeParameters();
497 }
498 
499 void G4OpenInventorViewer::WritePDF(const G4String& aFile) {
500  if(!fGL2PSAction) return;
501  fGL2PSAction->setFileName(aFile.c_str());
502  fGL2PSAction->setExportImageFormat(GL2PS_PDF);
503  // Use gl2ps default buffer (2048*2048)
504  fGL2PSAction->setBufferSize(0);
505  G4cout << "Produce " << aFile << "..." << G4endl;
506  if (fGL2PSAction->enableFileWriting()) {
507  ViewerRender();
508  fGL2PSAction->disableFileWriting();
509  }
510  fGL2PSAction->resetBufferSizeParameters();
511 }
512 
513 void G4OpenInventorViewer::WritePixmapPostScript(const G4String& aFile) {
514  fSoImageWriter->fileName.setValue(aFile.c_str());
515  //imageWriter->format.setValue(SoImageWriter::POST_SCRIPT);
516  fSoImageWriter->enable();
517  ViewerRender();
518  fSoImageWriter->disable();
519  if(fSoImageWriter->getStatus()) {
520  G4cout << G4String(fSoImageWriter->fileName.getValue().getString())
521  << " produced."
522  << G4endl;
523  } else {
524  G4cout << G4String(fSoImageWriter->fileName.getValue().getString())
525  << " not produced."
526  << G4endl;
527  }
528 }
529 
530 void G4OpenInventorViewer::WriteInventor(const G4String& aFile) {
531  G4cout << "Produce " << aFile << "..." << G4endl;
532 
533  SbBool genAlternateRep = TRUE;
534  //SbBool binary = FALSE;
535  SbBool binary = TRUE;
536  SoAlternateRepAction alternateRepAction;
537  if(genAlternateRep==TRUE) {
538  alternateRepAction.setGenerate(TRUE); //Clear alternate reps.
539  alternateRepAction.apply(fSoSelection);
540  }
541 
542  SoWriteAction writeAction;
543  writeAction.getOutput()->openFile(aFile.c_str());
544  writeAction.getOutput()->setBinary(binary);
545  writeAction.apply(fSoSelection);
546  writeAction.getOutput()->closeFile();
547 
548  if(genAlternateRep==TRUE) {
549  alternateRepAction.setGenerate(FALSE); //Clear alternate reps.
550  alternateRepAction.apply(fSoSelection);
551  }
552 
553 
554 
555 }
556 
557 struct Counter {
558  int fTriangles;
559  int fLineSegments;
560  int fPoints;
561 };
562 
563 static void CountTrianglesCB(
564  void* userData
565 ,SoCallbackAction*
566 ,const SoPrimitiveVertex*
567 ,const SoPrimitiveVertex*,
568 const SoPrimitiveVertex*)
569 {
570  Counter* counter = (Counter*)userData;
571  counter->fTriangles++;
572 }
573 
574 static void CountLineSegmentsCB(
575  void* userData
576 ,SoCallbackAction*
577 ,const SoPrimitiveVertex*
578 ,const SoPrimitiveVertex*)
579 {
580  Counter* counter = (Counter*)userData;
581  counter->fLineSegments++;
582 }
583 
584 static void CountPointsCB(
585  void* userData
586 ,SoCallbackAction*
587 ,const SoPrimitiveVertex*)
588 {
589  Counter* counter = (Counter*)userData;
590  counter->fPoints++;
591 }
592 
593 void G4OpenInventorViewer::SceneGraphStatistics() {
594  Counter counter;
595  counter.fTriangles = 0;
596  counter.fLineSegments = 0;
597  counter.fPoints = 0;
598 
599  SoCallbackAction callbackAction;
600  callbackAction.addTriangleCallback
601  (SoShape::getClassTypeId(),CountTrianglesCB,(void*)&counter);
602  callbackAction.addLineSegmentCallback
603  (SoShape::getClassTypeId(),CountLineSegmentsCB,(void*)&counter);
604  callbackAction.addPointCallback
605  (SoShape::getClassTypeId(),CountPointsCB,(void*)&counter);
606  callbackAction.apply(fSoSelection);
607 
608  SoCounterAction counterAction;
609  counterAction.apply(fSoSelection);
610  int nodes = counterAction.getCount();
611 
612  counterAction.setLookFor(SoCounterAction::TYPE);
613  counterAction.setType(SoShape::getClassTypeId());
614  counterAction.apply(fSoSelection);
615  int shapes = counterAction.getCount();
616 
617  G4cout << "Number of triangles : " << counter.fTriangles << G4endl;
618  G4cout << "Number of line segments : " << counter.fLineSegments << G4endl;
619  G4cout << "Number of points : " << counter.fPoints << G4endl;
620  G4cout << "Number of nodes : " << nodes << G4endl;
621  G4cout << "Number of shapes : " << shapes << G4endl;
622 }
623 
624 void G4OpenInventorViewer::EraseDetector() {
625  fG4OpenInventorSceneHandler.fDetectorRoot->removeAllChildren();
626 }
627 void G4OpenInventorViewer::EraseEvent() {
628  fG4OpenInventorSceneHandler.fTransientRoot->removeAllChildren();
629 }
630 
631 void G4OpenInventorViewer::SetPreviewAndFull() {
632  fG4OpenInventorSceneHandler.fPreviewAndFull = true;
633 
634  NeedKernelVisit();
635  DrawDetector();
636 }
637 
638 void G4OpenInventorViewer::SetPreview() {
639  fG4OpenInventorSceneHandler.fPreviewAndFull = false;
640 
641  NeedKernelVisit();
642  DrawDetector();
643 }
644 
645 // When ViewParameter <-> SoCamera mapping ready
646 // uncomment the below
647 //#define USE_SET_VIEW
648 
649 void G4OpenInventorViewer::SetSolid() {
650  G4ViewParameters vp = GetViewParameters();
651  G4ViewParameters::DrawingStyle existingStyle = vp.GetDrawingStyle();
652  //From G4VisCommandsViewerSet : /vis/viewer/set/style solid.
653  switch (existingStyle) {
656  break;
659  break;
661  break;
663  break;
664  }
665  SetViewParameters(vp);
666  DrawDetector();
667 }
668 void G4OpenInventorViewer::SetWireFrame() {
669  G4ViewParameters vp = GetViewParameters();
670  G4ViewParameters::DrawingStyle existingStyle = vp.GetDrawingStyle();
671  switch (existingStyle) {
673  break;
675  break;
678  break;
681  break;
682  }
683  SetViewParameters(vp);
684  DrawDetector();
685 }
686 
687 
688 void G4OpenInventorViewer::SetReducedWireFrame(bool aValue) {
689  G4ViewParameters vp = GetViewParameters();
690 
691  // Set the wire frame kind :
692  vp.SetAuxEdgeVisible(!aValue);
693 
694  // Set wire frame :
695  G4ViewParameters::DrawingStyle existingStyle = vp.GetDrawingStyle();
696  switch (existingStyle) {
698  break;
700  break;
703  break;
706  break;
707  }
708  SetViewParameters(vp);
709  NeedKernelVisit(); // Just in case it was alread in wire framw.
710  DrawDetector();
711 }
712 
713 void G4OpenInventorViewer::UpdateScene() {
714  /* Replace this... - JA
715  fG4OpenInventorSceneHandler.ClearStore();
716  ClearView();
717  if (!fNeedKernelVisit) KernelVisitDecision();
718  ProcessView();
719  ShowView();
720  */
721  // ...by this - JA
722  NeedKernelVisit();
723  DrawView();
724 }
725 G4String G4OpenInventorViewer::Help(const G4String& aTopic) {
726  if(aTopic=="controls") {
727  return G4String("\
728 Controls on an Inventor examiner viewer are :\n\
729 - in picking mode (cursor is the upper left arrow)\n\
730  Ctrl + pick a volume : see daughters.\n\
731  Shift + pick a volume : see mother.\n\
732 - in viewing mode (cursor is the hand)\n\
733  Left-button + pointer move : rotate.\n\
734  Ctrl+Left-button + pointer move : pan.\n\
735  Ctrl+Shift+Left-button + pointer move : scale.\n\
736  Middle-button + pointer move : pan.\n\
737  Right-button : popup menu.\n");
738  } else {
739  return "";
740  }
741 }
742 
743 #endif
const XML_Char * name
Definition: expat.h:151
void setType(const SoType, SbBool=TRUE)
const G4Colour & GetBackgroundColour() const
const XML_Char * target
Definition: expat.h:268
G4double GetVisibleDensity() const
void SetAuxEdgeVisible(G4bool)
G4bool IsCullingInvisible() const
G4double GetExplodeFactor() const
#define OIV_EXIT_CODE
BasicVector3D< T > unit() const
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
void setLookFor(LookFor)
HepGeom::Point3D< G4double > G4Point3D
Definition: G4Point3D.hh:35
HepGeom::Vector3D< G4double > G4Vector3D
Definition: G4Vector3D.hh:35
void setGenerate(SbBool)
const G4Planes & GetCutawayPlanes() const
tuple x
Definition: test.py:50
#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
int getCount() const
const G4VisAttributes * GetDefaultTextVisAttributes() const
G4bool IsExplode() const
G4bool IsSection() const
G4bool IsCutaway() const
G4bool IsMarkerNotHidden() const
#define GL2PS_PDF
Definition: gl2ps.h:122
void SetDrawingStyle(G4ViewParameters::DrawingStyle style)
const G4Vector3D & GetScaleFactor() const
G4int GetNoOfSides() const
#define SoImageWriter
Definition: SoImageWriter.h:40
tuple z
Definition: test.py:28
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
#define GL2PS_EPS
Definition: gl2ps.h:120