source: trunk/source/visualization/OpenInventor/src/G4OpenInventorViewer.cc @ 1051

Last change on this file since 1051 was 1051, checked in by garnier, 15 years ago

qq modifs de debug

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