Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
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 // $Id: G4OpenInventorViewer.cc 109520 2018-04-26 16:01:14Z 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())->
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.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;
671  }
672  SetViewParameters(vp);
673  DrawDetector();
674 }
675 void G4OpenInventorViewer::SetWireFrame() {
676  G4ViewParameters vp = GetViewParameters();
677  G4ViewParameters::DrawingStyle existingStyle = vp.GetDrawingStyle();
678  switch (existingStyle) {
680  break;
682  break;
685  break;
688  break;
689  }
690  SetViewParameters(vp);
691  DrawDetector();
692 }
693 
694 
695 void G4OpenInventorViewer::SetReducedWireFrame(bool aValue) {
696  G4ViewParameters vp = GetViewParameters();
697 
698  // Set the wire frame kind :
699  vp.SetAuxEdgeVisible(!aValue);
700 
701  // Set wire frame :
702  G4ViewParameters::DrawingStyle existingStyle = vp.GetDrawingStyle();
703  switch (existingStyle) {
705  break;
707  break;
710  break;
713  break;
714  }
715  SetViewParameters(vp);
716  NeedKernelVisit(); // Just in case it was alread in wire framw.
717  DrawDetector();
718 }
719 
720 void G4OpenInventorViewer::UpdateScene() {
721  /* Replace this... - JA
722  fG4OpenInventorSceneHandler.ClearStore();
723  ClearView();
724  if (!fNeedKernelVisit) KernelVisitDecision();
725  ProcessView();
726  ShowView();
727  */
728  // ...by this - JA
729  NeedKernelVisit();
730  DrawView();
731 }
732 G4String G4OpenInventorViewer::Help(const G4String& aTopic) {
733  if(aTopic=="controls") {
734  return G4String("\
735 Controls on an Inventor examiner viewer are :\n\
736 - in picking mode (cursor is the upper left arrow)\n\
737  Ctrl + pick a volume : see daughters.\n\
738  Shift + pick a volume : see mother.\n\
739 - in viewing mode (cursor is the hand)\n\
740  Left-button + pointer move : rotate.\n\
741  Ctrl+Left-button + pointer move : pan.\n\
742  Ctrl+Shift+Left-button + pointer move : scale.\n\
743  Middle-button + pointer move : pan.\n\
744  Right-button : popup menu.\n");
745  } else {
746  return "";
747  }
748 }
749 
750 #endif
Float_t x
Definition: compare.C:6
int getCount() const
const std::vector< G4ModelingParameters::VisAttributesModifier > & GetVisAttributesModifiers() const
G4bool IsMarkerNotHidden() const
G4double GetExplodeFactor() const
const XML_Char * name
Definition: expat.h:151
static const G4double pos
const XML_Char * target
Definition: expat.h:268
void SetDrawingStyle(G4ViewParameters::DrawingStyle style)
G4bool IsDensityCulling() const
const G4Plane3D & GetSectionPlane() const
#define OIV_EXIT_CODE
BasicVector3D< T > unit() const
#define G4endl
Definition: G4ios.hh:61
Float_t y
Definition: compare.C:6
Double_t z
G4bool IsAuxEdgeVisible() const
void setGenerate(SbBool)
#define userData
Definition: xmlparse.cc:572
const std::vector< const std::map< G4String, G4AttDef > * > & GetAttDefs() const
Definition: G4AttHolder.hh:62
const std::vector< G4double > & GetCBDParameters() const
G4bool IsCulling() const
const G4Vector3D & GetScaleFactor() const
G4bool IsPicking() const
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
G4bool IsExplode() const
void SetAuxEdgeVisible(G4bool)
G4int GetCBDAlgorithmNumber() const
#define FALSE
Definition: globals.hh:52
G4bool IsCutaway() const
#define TRUE
Definition: globals.hh:55
const G4VisAttributes * GetDefaultVisAttributes() const
void setLookFor(LookFor)
G4int GetNoOfSides() const
Double_t radius
G4bool IsCullingInvisible() const
HepGeom::Vector3D< G4double > G4Vector3D
Definition: G4Vector3D.hh:35
G4VInteractorManager * GetInteractorManager()
void setType(const SoType, SbBool=TRUE)
#define GL2PS_PDF
Definition: gl2ps.h:122
DrawingStyle GetDrawingStyle() const
const std::vector< const std::vector< G4AttValue > * > & GetAttValues() const
Definition: G4AttHolder.hh:60
const G4Planes & GetCutawayPlanes() const
TDirectory * dir
const G4Colour & GetBackgroundColour() const
G4GLOB_DLL std::ostream G4cout
#define SoImageWriter
Definition: SoImageWriter.h:40
const G4VisAttributes * GetDefaultTextVisAttributes() const
G4bool IsCullingCovered() const
G4double GetVisibleDensity() const
HepGeom::Point3D< G4double > G4Point3D
Definition: G4Point3D.hh:35
const G4Colour & GetColour() const
static G4bool GetColour(const G4String &key, G4Colour &result)
Definition: G4Colour.cc:163
G4bool IsSection() const
#define GL2PS_EPS
Definition: gl2ps.h:120