Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/visualization/OpenInventor/src/G4OpenInventorViewer.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /visualization/OpenInventor/src/G4OpenInventorViewer.cc (Version 11.3.0) and /visualization/OpenInventor/src/G4OpenInventorViewer.cc (Version 8.0.p1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                    <<   3 // * DISCLAIMER                                                       *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th <<   5 // * The following disclaimer summarizes all the specific disclaimers *
  6 // * the Geant4 Collaboration.  It is provided <<   6 // * of contributors to this software. The specific disclaimers,which *
  7 // * conditions of the Geant4 Software License <<   7 // * govern, are listed with their locations in:                      *
  8 // * LICENSE and available at  http://cern.ch/ <<   8 // *   http://cern.ch/geant4/license                                  *
  9 // * include a list of copyright holders.      << 
 10 // *                                                9 // *                                                                  *
 11 // * Neither the authors of this software syst     10 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     11 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     12 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     13 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  <<  14 // * use.                                                             *
 16 // * for the full disclaimer and the limitatio << 
 17 // *                                               15 // *                                                                  *
 18 // * This  code  implementation is the result  <<  16 // * This  code  implementation is the  intellectual property  of the *
 19 // * technical work of the GEANT4 collaboratio <<  17 // * GEANT4 collaboration.                                            *
 20 // * By using,  copying,  modifying or  distri <<  18 // * By copying,  distributing  or modifying the Program (or any work *
 21 // * any work based  on the software)  you  ag <<  19 // * based  on  the Program)  you indicate  your  acceptance of  this *
 22 // * use  in  resulting  scientific  publicati <<  20 // * statement, and all its terms.                                    *
 23 // * acceptance of all terms of the Geant4 Sof << 
 24 // *******************************************     21 // ********************************************************************
 25 //                                                 22 //
 26                                                <<  23 #ifdef G4VIS_BUILD_OI_DRIVER
 27 // 03-MAY-2021 F.W. Jones: removed the camera  << 
 28 // since the group node sensor receives all ca << 
 29 // can update the view parameters, irrespectiv << 
 30 // camera type.                                << 
 31                                                    24 
 32 // this :                                          25 // this :
 33 #include "G4OpenInventorViewer.hh"                 26 #include "G4OpenInventorViewer.hh"
 34                                                    27 
 35 #include <Inventor/nodes/SoSelection.h>            28 #include <Inventor/nodes/SoSelection.h>
 36 #include <Inventor/nodes/SoShape.h>                29 #include <Inventor/nodes/SoShape.h>
 37 #include <Inventor/nodes/SoOrthographicCamera.     30 #include <Inventor/nodes/SoOrthographicCamera.h>
 38 #include <Inventor/nodes/SoPerspectiveCamera.h     31 #include <Inventor/nodes/SoPerspectiveCamera.h>
 39 #include <Inventor/actions/SoCallbackAction.h>     32 #include <Inventor/actions/SoCallbackAction.h>
 40 #include <Inventor/actions/SoWriteAction.h>        33 #include <Inventor/actions/SoWriteAction.h>
 41 #include <Inventor/sensors/SoNodeSensor.h>         34 #include <Inventor/sensors/SoNodeSensor.h>
 42                                                    35 
 43 #include "HEPVis/nodes/SoImageWriter.h"            36 #include "HEPVis/nodes/SoImageWriter.h"
 44 #include "HEPVis/actions/SoGL2PSAction.h"          37 #include "HEPVis/actions/SoGL2PSAction.h"
 45 #include "HEPVis/actions/SoCounterAction.h"        38 #include "HEPVis/actions/SoCounterAction.h"
 46 #include "HEPVis/actions/SoAlternateRepAction.     39 #include "HEPVis/actions/SoAlternateRepAction.h"
 47                                                    40 
 48 #include "G4OpenInventor.hh"                       41 #include "G4OpenInventor.hh"
 49 #include "G4OpenInventorSceneHandler.hh"           42 #include "G4OpenInventorSceneHandler.hh"
 50 #include "G4VInteractorManager.hh"                 43 #include "G4VInteractorManager.hh"
 51 #include "G4Scene.hh"                              44 #include "G4Scene.hh"
 52 #include "Geant4_SoPolyhedron.h"                   45 #include "Geant4_SoPolyhedron.h"
 53 #include "G4AttValue.hh"                       << 
 54 #include "G4AttDef.hh"                         << 
 55 #include "G4AttCheck.hh"                       << 
 56 #include "G4AttHolder.hh"                      << 
 57                                                    46 
 58 G4OpenInventorViewer::G4OpenInventorViewer(        47 G4OpenInventorViewer::G4OpenInventorViewer(
 59  G4OpenInventorSceneHandler& sceneHandler          48  G4OpenInventorSceneHandler& sceneHandler
 60 ,const G4String& name)                             49 ,const G4String& name)
 61 :G4VViewer(sceneHandler, sceneHandler.Incremen     50 :G4VViewer(sceneHandler, sceneHandler.IncrementViewCount(), name)
 62 ,fG4OpenInventorSceneHandler(sceneHandler)         51 ,fG4OpenInventorSceneHandler(sceneHandler)
 63 ,fInteractorManager(0)                             52 ,fInteractorManager(0)
 64 ,fSoSelection(0)                                   53 ,fSoSelection(0)
 65 ,fSoImageWriter(0)                                 54 ,fSoImageWriter(0)
 66 ,fGL2PSAction(0) //To be set be suclass.           55 ,fGL2PSAction(0) //To be set be suclass.
 67 ,fGroupCameraSensor(0)                             56 ,fGroupCameraSensor(0)
 68  //,fCameraSensor(0)                           <<  57 ,fCameraSensor(0)
 69 {                                                  58 {
 70   fVP.SetAutoRefresh(true);                    <<  59   fNeedKernelVisit = true;  //?? Temporary, until KernelVisitDecision fixed.
                                                   >>  60 
 71   fDefaultVP.SetAutoRefresh(true);                 61   fDefaultVP.SetAutoRefresh(true);
 72   fVP.SetPicking(true);                        <<  62   fVP.SetAutoRefresh(true);
 73   fDefaultVP.SetPicking(true);                 << 
 74                                                    63 
 75   //FIXME : G.Barrand : not convinced that we      64   //FIXME : G.Barrand : not convinced that we have to rm culling.
 76   // For viewing of all objects by default :       65   // For viewing of all objects by default :
 77   //fDefaultVP.SetCulling(false);                  66   //fDefaultVP.SetCulling(false);
 78   //fVP.SetCulling(false);                         67   //fVP.SetCulling(false);
 79                                                    68 
 80   fInteractorManager =                             69   fInteractorManager = 
 81     ((G4OpenInventor*)fG4OpenInventorSceneHand     70     ((G4OpenInventor*)fG4OpenInventorSceneHandler.GetGraphicsSystem())->
 82     GetInteractorManager();                        71     GetInteractorManager();
 83                                                    72 
 84   // Main user scene graph root sent to the vi     73   // Main user scene graph root sent to the viewers.
 85   fSoSelection = new SoSelection;                  74   fSoSelection = new SoSelection;
 86   fSoSelection->ref();                             75   fSoSelection->ref();
 87   fSoSelection->addSelectionCallback(Selection     76   fSoSelection->addSelectionCallback(SelectionCB,this);
 88   //fSoSelection->addDeselectionCallback(Desel     77   //fSoSelection->addDeselectionCallback(DeselectionCB,this);
 89   fSoSelection->policy = SoSelection::SINGLE;      78   fSoSelection->policy = SoSelection::SINGLE;
 90                                                    79 
 91   SoGroup* group = new SoGroup;                    80   SoGroup* group = new SoGroup;
 92   fSoSelection->addChild(group);                   81   fSoSelection->addChild(group);
 93                                                    82 
 94   //  Have a camera under fSoSelection in orde     83   //  Have a camera under fSoSelection in order
 95   // that the below SceneGraphSensor be notife     84   // that the below SceneGraphSensor be notifed
 96   // when the viewer changes the camera type.      85   // when the viewer changes the camera type.
 97   //  But we put the camera under a SoGroup so     86   //  But we put the camera under a SoGroup so that
 98   // the SceneGraphSensor be not triggered at      87   // the SceneGraphSensor be not triggered at each change
 99   // under the fG4OpenInventorSceneHandler.fRo     88   // under the fG4OpenInventorSceneHandler.fRoot.
100   SoOrthographicCamera* camera = new SoOrthogr     89   SoOrthographicCamera* camera = new SoOrthographicCamera;
101   camera->viewportMapping.setValue(SoCamera::A     90   camera->viewportMapping.setValue(SoCamera::ADJUST_CAMERA);
102   //camera->aspectRatio.setValue(10);              91   //camera->aspectRatio.setValue(10);
103   camera->position.setValue(0,0,10);               92   camera->position.setValue(0,0,10);
104   camera->orientation.setValue(SbRotation(SbVe     93   camera->orientation.setValue(SbRotation(SbVec3f(0,1,0),0));
105   camera->height.setValue(10);                     94   camera->height.setValue(10);
106   camera->nearDistance.setValue(1);                95   camera->nearDistance.setValue(1);
107   camera->farDistance.setValue(100);               96   camera->farDistance.setValue(100);
108   camera->focalDistance.setValue(10);              97   camera->focalDistance.setValue(10);
109   group->addChild(camera);                         98   group->addChild(camera);
110                                                    99 
111  {SoInput soInput;                                100  {SoInput soInput;
112    if(soInput.openFile("g4view.iv",TRUE)) {       101    if(soInput.openFile("g4view.iv",TRUE)) {
113     SoSeparator* separator = SoDB::readAll(&so    102     SoSeparator* separator = SoDB::readAll(&soInput);
114     if(separator) fSoSelection->addChild(separ    103     if(separator) fSoSelection->addChild(separator);
115   }}                                              104   }}
116                                                   105 
117   fSoSelection->addChild(fG4OpenInventorSceneH    106   fSoSelection->addChild(fG4OpenInventorSceneHandler.fRoot);
118                                                   107 
119   // SoImageWriter should be the last.            108   // SoImageWriter should be the last.
120   fSoImageWriter = new SoImageWriter();           109   fSoImageWriter = new SoImageWriter();
121   fSoImageWriter->fileName.setValue("g4out.ps"    110   fSoImageWriter->fileName.setValue("g4out.ps");
122   fSoSelection->addChild(fSoImageWriter);         111   fSoSelection->addChild(fSoImageWriter);
123                                                   112 
124   // Sensors :                                    113   // Sensors :
125   // To detect that the viewer had changed the    114   // To detect that the viewer had changed the camera type :
126   fGroupCameraSensor = new SoNodeSensor(GroupC    115   fGroupCameraSensor = new SoNodeSensor(GroupCameraSensorCB,this);
127   fGroupCameraSensor->setPriority(0);//Needed     116   fGroupCameraSensor->setPriority(0);//Needed in order to do getTriggerNode()
128   fGroupCameraSensor->attach(group);              117   fGroupCameraSensor->attach(group);
129   // FWJ Upgraded the group sensor so the came << 118 
130   //  fCameraSensor = new SoNodeSensor(CameraS << 119   fCameraSensor = new SoNodeSensor(CameraSensorCB,this);
131   //  fCameraSensor->setPriority(0);//Needed i << 120   fCameraSensor->setPriority(0);//Needed in order to do getTriggerNode()
132   //  fCameraSensor->attach(camera);           << 
133 }                                                 121 }
134                                                   122 
135 G4OpenInventorViewer::~G4OpenInventorViewer ()    123 G4OpenInventorViewer::~G4OpenInventorViewer () {
136    //  fCameraSensor->detach();                << 124   fCameraSensor->detach();
137    //  delete fCameraSensor;                   << 125   delete fCameraSensor;
138   fGroupCameraSensor->detach();                   126   fGroupCameraSensor->detach();
139   delete fGroupCameraSensor;                      127   delete fGroupCameraSensor;
140   fSoSelection->unref();                          128   fSoSelection->unref();
141 }                                                 129 }
142                                                   130 
143 void G4OpenInventorViewer::KernelVisitDecision    131 void G4OpenInventorViewer::KernelVisitDecision () {
144                                                   132   
145   // If there's a significant difference with     133   // If there's a significant difference with the last view parameters
146   // of either the scene handler or this viewe    134   // of either the scene handler or this viewer, trigger a rebuild.
147                                                   135 
148   if (                                            136   if (
149       //??fG4OpenInventorSceneHandler.fPODLLis    137       //??fG4OpenInventorSceneHandler.fPODLList.size() == 0 ||
150       // We need a test for empty scene graph,    138       // We need a test for empty scene graph, such as
151       // staticRoot.size() or something???????    139       // staticRoot.size() or something??????????  See temporary fix
152       // in contructor.  (John Allison Aug 200    140       // in contructor.  (John Allison Aug 2001)
153       CompareForKernelVisit(fLastVP)) {           141       CompareForKernelVisit(fLastVP)) {
154     NeedKernelVisit ();                           142     NeedKernelVisit ();
155   }                                               143   }      
                                                   >> 144   fLastVP = fVP;
156 }                                                 145 }
157                                                   146  
158 G4bool G4OpenInventorViewer::CompareForKernelV    147 G4bool G4OpenInventorViewer::CompareForKernelVisit(G4ViewParameters& vp) {
159                                                   148 
160   if (                                            149   if (
161       (vp.GetDrawingStyle ()    != fVP.GetDraw    150       (vp.GetDrawingStyle ()    != fVP.GetDrawingStyle ())    ||
162       (vp.GetNumberOfCloudPoints()  != fVP.Get << 151       (vp.GetRepStyle ()        != fVP.GetRepStyle ())        ||
163       (vp.IsAuxEdgeVisible ()   != fVP.IsAuxEd << 
164       (vp.IsCulling ()          != fVP.IsCulli    152       (vp.IsCulling ()          != fVP.IsCulling ())          ||
165       (vp.IsCullingInvisible () != fVP.IsCulli    153       (vp.IsCullingInvisible () != fVP.IsCullingInvisible ()) ||
166       (vp.IsDensityCulling ()   != fVP.IsDensi    154       (vp.IsDensityCulling ()   != fVP.IsDensityCulling ())   ||
167       (vp.IsCullingCovered ()   != fVP.IsCulli    155       (vp.IsCullingCovered ()   != fVP.IsCullingCovered ())   ||
168       (vp.GetCBDAlgorithmNumber() !=           << 
169        fVP.GetCBDAlgorithmNumber())            << 
170       (vp.IsSection ()          != fVP.IsSecti    156       (vp.IsSection ()          != fVP.IsSection ())          ||
                                                   >> 157       // No need to visit kernel if section plane changes.
171       (vp.IsCutaway ()          != fVP.IsCutaw    158       (vp.IsCutaway ()          != fVP.IsCutaway ())          ||
172       // This assumes use of generic clipping  << 159       (vp.GetCutawayPlanes ().size () !=
173       // DCUT, cutaway).  If a decision is mad << 160                                  fVP.GetCutawayPlanes ().size ()) ||
174       // this will need changing.  See G4OpenG << 161       // No need to visit kernel if cutaway planes change.
175       // G4OpenGLStoredViewer.cc::CompareForKe << 
176       // G4OpenGLStoredSceneHander::CreateSect << 
177       (vp.IsExplode ()          != fVP.IsExplo    162       (vp.IsExplode ()          != fVP.IsExplode ())          ||
178       (vp.GetNoOfSides ()       != fVP.GetNoOf << 163       (vp.GetNoOfSides ()       != fVP.GetNoOfSides ())
179       (vp.GetGlobalMarkerScale()    != fVP.Get << 164       ) {
180       (vp.GetGlobalLineWidthScale() != fVP.Get << 165       return true;;
181       (vp.IsMarkerNotHidden ()  != fVP.IsMarke << 166   }
182       (vp.GetDefaultVisAttributes()->GetColour << 
183        fVP.GetDefaultVisAttributes()->GetColou << 
184       (vp.GetDefaultTextVisAttributes()->GetCo << 
185        fVP.GetDefaultTextVisAttributes()->GetC << 
186       (vp.GetBackgroundColour ()!= fVP.GetBack << 
187       (vp.IsPicking ()          != fVP.IsPicki << 
188       // Scaling for Open Inventor is done by  << 
189       // needs a kernel visit.  (In this respe << 
190       // OpenGL drivers, where it's done in Se << 
191       (vp.GetScaleFactor ()     != fVP.GetScal << 
192       (vp.GetVisAttributesModifiers() !=       << 
193        fVP.GetVisAttributesModifiers())        << 
194       (vp.IsSpecialMeshRendering() !=          << 
195        fVP.IsSpecialMeshRendering())           << 
196       (vp.GetSpecialMeshRenderingOption() !=   << 
197        fVP.GetSpecialMeshRenderingOption())    << 
198       )                                        << 
199     return true;                               << 
200                                                << 
201   if (vp.IsDensityCulling () &&                   167   if (vp.IsDensityCulling () &&
202       (vp.GetVisibleDensity () != fVP.GetVisib    168       (vp.GetVisibleDensity () != fVP.GetVisibleDensity ()))
203     return true;                                  169     return true;
204                                                   170 
205   if (vp.GetCBDAlgorithmNumber() > 0) {        << 
206     if (vp.GetCBDParameters().size() != fVP.Ge << 
207     else if (vp.GetCBDParameters() != fVP.GetC << 
208   }                                            << 
209                                                << 
210   if (vp.IsSection () &&                       << 
211       (vp.GetSectionPlane () != fVP.GetSection << 
212     return true;                               << 
213                                                << 
214   if (vp.IsCutaway ()) {                       << 
215     if (vp.GetCutawayMode() != fVP.GetCutawayM << 
216     if (vp.GetCutawayPlanes ().size () !=      << 
217   fVP.GetCutawayPlanes ().size ()) return true << 
218     for (size_t i = 0; i < vp.GetCutawayPlanes << 
219       if (vp.GetCutawayPlanes()[i] != fVP.GetC << 
220   return true;                                 << 
221   }                                            << 
222                                                << 
223   if (vp.IsExplode () &&                          171   if (vp.IsExplode () &&
224       (vp.GetExplodeFactor () != fVP.GetExplod    172       (vp.GetExplodeFactor () != fVP.GetExplodeFactor ()))
225     return true;                                  173     return true;
226                                                   174       
227   if (vp.IsSpecialMeshRendering() &&           << 
228       (vp.GetSpecialMeshVolumes() != fVP.GetSp << 
229     return true;                               << 
230                                                << 
231   return false;                                   175   return false;
232 }                                                 176 }
233                                                   177 
234 void G4OpenInventorViewer::ClearView () {         178 void G4OpenInventorViewer::ClearView () {
235 }                                                 179 }
236                                                   180 
237 void G4OpenInventorViewer::SetView () {           181 void G4OpenInventorViewer::SetView () {
238                                                   182 
239   // Get G4 camera infos :                        183   // Get G4 camera infos :
240   const G4Point3D target                          184   const G4Point3D target
241     = fSceneHandler.GetScene()->GetStandardTar    185     = fSceneHandler.GetScene()->GetStandardTargetPoint()
242     + fVP.GetCurrentTargetPoint ();               186     + fVP.GetCurrentTargetPoint ();
243   G4double radius = fSceneHandler.GetScene()->    187   G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
244   if(radius<=0.) radius = 1.;                     188   if(radius<=0.) radius = 1.;
245   const G4double cameraDistance = fVP.GetCamer    189   const G4double cameraDistance = fVP.GetCameraDistance (radius);
246   const G4Vector3D& direction = fVP.GetViewpoi    190   const G4Vector3D& direction = fVP.GetViewpointDirection().unit();
247   const G4Point3D cameraPosition = target + ca    191   const G4Point3D cameraPosition = target + cameraDistance * direction;
248   //const G4double pnear = fVP.GetNearDistance    192   //const G4double pnear = fVP.GetNearDistance (cameraDistance, radius);
249   //const G4double pfar  = fVP.GetFarDistance     193   //const G4double pfar  = fVP.GetFarDistance  (cameraDistance, pnear, radius);
250   const G4Normal3D& up = fVP.GetUpVector ();      194   const G4Normal3D& up = fVP.GetUpVector ();  
251                                                   195 
252 /*                                                196 /*
253   printf("debug : target : %g %g %g\n",target.    197   printf("debug : target : %g %g %g\n",target.x(),
254                                        target.    198                                        target.y(),
255                                        target.    199                                        target.z());
256   printf("debug : dir : %g %g %g\n",direction.    200   printf("debug : dir : %g %g %g\n",direction.x(),
257                                     direction.    201                                     direction.y(),
258                                     direction.    202                                     direction.z());
259   printf("debug : pos : %g %g %g\n",cameraPosi    203   printf("debug : pos : %g %g %g\n",cameraPosition.x(),
260                                     cameraPosi    204                                     cameraPosition.y(),
261                                     cameraPosi    205                                     cameraPosition.z());
262   //printf("debug : near %g far %g\n",pnear,pf    206   //printf("debug : near %g far %g\n",pnear,pfar);
263 */                                                207 */
264                                                   208 
265   SoCamera* camera = GetCamera();                 209   SoCamera* camera = GetCamera();
266   if(!camera) return;                             210   if(!camera) return;
267                                                   211 
268   // viewer camera setup :                        212   // viewer camera setup :
269   camera->position.setValue((float)cameraPosit    213   camera->position.setValue((float)cameraPosition.x(),
270                                (float)cameraPo    214                                (float)cameraPosition.y(),
271                                (float)cameraPo    215                                (float)cameraPosition.z());
272                                                   216 
273   SbVec3f sbTarget((float)target.x(),             217   SbVec3f sbTarget((float)target.x(),
274                    (float)target.y(),             218                    (float)target.y(),
275                    (float)target.z());            219                    (float)target.z());
276   SbVec3f sbUp((float)up.x(),                     220   SbVec3f sbUp((float)up.x(),
277          (float)up.y(),                           221          (float)up.y(),
278          (float)up.z());                          222          (float)up.z());
279   sbUp.normalize();                               223   sbUp.normalize();
280   // Need Coin's camera->pointAt(sbTarget,sbUp    224   // Need Coin's camera->pointAt(sbTarget,sbUp); not in the SGI API
281   // Stole Coin's code...                         225   // Stole Coin's code...
282   pointAt(camera,sbTarget,sbUp);                  226   pointAt(camera,sbTarget,sbUp);
283                                                   227 
284   //camera->height.setValue(10);                  228   //camera->height.setValue(10);
285   //camera->nearDistance.setValue((float)pnear    229   //camera->nearDistance.setValue((float)pnear);
286   //camera->farDistance.setValue((float)pfar);    230   //camera->farDistance.setValue((float)pfar);
287   //camera->focalDistance.setValue((float)came    231   //camera->focalDistance.setValue((float)cameraDistance);
288                                                   232 
289   if(camera->isOfType(SoOrthographicCamera::ge    233   if(camera->isOfType(SoOrthographicCamera::getClassTypeId())) {
290     if (fVP.GetFieldHalfAngle() == 0.) {          234     if (fVP.GetFieldHalfAngle() == 0.) {
291       //FIXME : ((SoOrthographicCamera*)camera    235       //FIXME : ((SoOrthographicCamera*)camera)->height.setValue();
292       //FIXME : (Don't think we have to do tha    236       //FIXME : (Don't think we have to do that.)
293     } else {                                      237     } else {
294       //FIXME : Have to set a perspective came    238       //FIXME : Have to set a perspective camera !
295       //FIXME : viewer->setCameraType(SoPerspe    239       //FIXME : viewer->setCameraType(SoPerspectiveCamera::getClassTypeId())
296       //FIXME : ((SoPerspectiveCamera*)camera)    240       //FIXME : ((SoPerspectiveCamera*)camera)->heightAngle.setValue
297       //FIXME :   (2.*fVP.GetFieldHalfAngle())    241       //FIXME :   (2.*fVP.GetFieldHalfAngle());
298     }                                             242     }
299   } else if(camera->isOfType(SoPerspectiveCame    243   } else if(camera->isOfType(SoPerspectiveCamera::getClassTypeId())) {
300     if (fVP.GetFieldHalfAngle() == 0.) {          244     if (fVP.GetFieldHalfAngle() == 0.) {
301       //FIXME : Have to set an orthographic ca    245       //FIXME : Have to set an orthographic camera !
302       //FIXME : viewer->setCameraType(SoOrthog    246       //FIXME : viewer->setCameraType(SoOrthographicCamera::getClassTypeId())
303     } else {                                      247     } else {
304       //FIXME : ((SoPerspectiveCamera*)camera)    248       //FIXME : ((SoPerspectiveCamera*)camera)->heightAngle.setValue
305       //FIXME :   (2.*fVP.GetFieldHalfAngle())    249       //FIXME :   (2.*fVP.GetFieldHalfAngle());
306     }                                             250     }
307   }                                               251   }
308 }                                                 252 }
309                                                   253 
310 //COIN_FUNCTION_EXTENSION                         254 //COIN_FUNCTION_EXTENSION
311 void                                              255 void
312 G4OpenInventorViewer::pointAt(SoCamera* camera    256 G4OpenInventorViewer::pointAt(SoCamera* camera,const SbVec3f & targetpoint, const SbVec3f & upvector)
313 {                                                 257 {
314   SbVec3f dir = targetpoint - camera->position    258   SbVec3f dir = targetpoint - camera->position.getValue();
315   if (dir.normalize() == 0.0f) return;            259   if (dir.normalize() == 0.0f) return;
316   lookAt(camera,dir, upvector);                   260   lookAt(camera,dir, upvector);
317 }                                                 261 }
318                                                   262 
319 //COIN_FUNCTION                                   263 //COIN_FUNCTION
320 // Private method that calculates a new orient    264 // Private method that calculates a new orientation based on camera
321 // direction and camera up vector. Vectors mus    265 // direction and camera up vector. Vectors must be unit length.
322 void                                              266 void
323 G4OpenInventorViewer::lookAt(SoCamera* camera,    267 G4OpenInventorViewer::lookAt(SoCamera* camera,const SbVec3f & dir, const SbVec3f & up)
324 {                                                 268 {
325   SbVec3f z = -dir;                               269   SbVec3f z = -dir;
326   SbVec3f y = up;                                 270   SbVec3f y = up;
327   SbVec3f x = y.cross(z);                         271   SbVec3f x = y.cross(z);
328                                                   272 
329   // recompute y to create a valid coordinate     273   // recompute y to create a valid coordinate system
330   y = z.cross(x);                                 274   y = z.cross(x);
331                                                   275 
332   // normalize x and y to create an orthonorma    276   // normalize x and y to create an orthonormal coord system
333   y.normalize();                                  277   y.normalize();
334   x.normalize();                                  278   x.normalize();
335                                                   279 
336   // create a rotation matrix                     280   // create a rotation matrix
337   SbMatrix rot = SbMatrix::identity();            281   SbMatrix rot = SbMatrix::identity();
338   rot[0][0] = x[0];                               282   rot[0][0] = x[0];
339   rot[0][1] = x[1];                               283   rot[0][1] = x[1];
340   rot[0][2] = x[2];                               284   rot[0][2] = x[2];
341                                                   285 
342   rot[1][0] = y[0];                               286   rot[1][0] = y[0];
343   rot[1][1] = y[1];                               287   rot[1][1] = y[1];
344   rot[1][2] = y[2];                               288   rot[1][2] = y[2];
345                                                   289 
346   rot[2][0] = z[0];                               290   rot[2][0] = z[0];
347   rot[2][1] = z[1];                               291   rot[2][1] = z[1];
348   rot[2][2] = z[2];                               292   rot[2][2] = z[2];
349                                                   293 
350   camera->orientation.setValue(SbRotation(rot)    294   camera->orientation.setValue(SbRotation(rot));
351 }                                                 295 }
352                                                   296 
353 void                                              297 void
354 G4OpenInventorViewer::lookedAt(SoCamera* camer    298 G4OpenInventorViewer::lookedAt(SoCamera* camera,SbVec3f & dir, SbVec3f & up)
355 {                                                 299 {
356   SbRotation rot = camera->orientation.getValu    300   SbRotation rot = camera->orientation.getValue();
357   SbMatrix mrot; rot.getValue(mrot);              301   SbMatrix mrot; rot.getValue(mrot);
358                                                   302 
359   SbVec3f x, y, z;                                303   SbVec3f x, y, z;
360                                                   304 
361   // create a rotation matrix                     305   // create a rotation matrix
362   x[0] = mrot[0][0];                              306   x[0] = mrot[0][0];
363   x[1] = mrot[0][1];                              307   x[1] = mrot[0][1];
364   x[2] = mrot[0][2];                              308   x[2] = mrot[0][2];
365                                                   309 
366   y[0] = mrot[1][0];                              310   y[0] = mrot[1][0];
367   y[1] = mrot[1][1];                              311   y[1] = mrot[1][1];
368   y[2] = mrot[1][2];                              312   y[2] = mrot[1][2];
369                                                   313 
370   z[0] = mrot[2][0];                              314   z[0] = mrot[2][0];
371   z[1] = mrot[2][1];                              315   z[1] = mrot[2][1];
372   z[2] = mrot[2][2];                              316   z[2] = mrot[2][2];
373                                                   317 
374   dir = -z;                                       318   dir = -z;
375   dir.normalize();                                319   dir.normalize();
376   up = SbVec3f(0.f,1.f,0.f);  // Choose y-axis    320   up = SbVec3f(0.f,1.f,0.f);  // Choose y-axis if possible.
377   if (std::abs(up.dot(z)) > 1.e-6) {              321   if (std::abs(up.dot(z)) > 1.e-6) {
378     up = y;                                       322     up = y;
379     up.normalize();                               323     up.normalize();
380   }                                               324   }
381 }                                                 325 }
382                                                   326 
383 void G4OpenInventorViewer::DrawView () {          327 void G4OpenInventorViewer::DrawView () {
384   //G4cout << "debug Iv::DrawViewer " <<G4endl    328   //G4cout << "debug Iv::DrawViewer " <<G4endl;
385   if (!fNeedKernelVisit) KernelVisitDecision() << 329   KernelVisitDecision();
386   fLastVP= fVP;                                << 
387   ProcessView();                                  330   ProcessView();
388   FinishView();                                   331   FinishView();
389 }                                                 332 }
390                                                   333 
391 void G4OpenInventorViewer::ShowView () {          334 void G4OpenInventorViewer::ShowView () {
392   fInteractorManager -> SecondaryLoop ();         335   fInteractorManager -> SecondaryLoop ();
393 }                                                 336 }
394                                                   337 
395 // FWJ This sensor now performs the fVP update << 338 void G4OpenInventorViewer::GroupCameraSensorCB(void* aThis,SoSensor* aSensor){ 
396 void G4OpenInventorViewer::GroupCameraSensorCB << 
397 {                                              << 
398   G4OpenInventorViewer* This = (G4OpenInventor    339   G4OpenInventorViewer* This = (G4OpenInventorViewer*)aThis;
399                                                   340 
400   SoNode* node = ((SoNodeSensor*)aSensor)->get    341   SoNode* node = ((SoNodeSensor*)aSensor)->getTriggerNode();
401   //  printf("debug : GroupCameraSensorCB %s\n << 342   //printf("debug : GroupCameraSensorCB %s\n",
402   //         node->getTypeId().getName().getSt << 343   //node->getTypeId().getName().getString());
403                                                   344 
404   if(node->isOfType(SoCamera::getClassTypeId()    345   if(node->isOfType(SoCamera::getClassTypeId())) {
405     SoCamera* camera = (SoCamera*)node;        << 
406                                                << 
407     // FWJ DEBUG                               << 
408     //    G4cout << "   UPDATING fVP FROM CAME << 
409     SbVec3f direction, up;                     << 
410     lookedAt(camera, direction, up);           << 
411     This->fVP.SetViewpointDirection            << 
412       (G4Vector3D(-direction[0], -direction[1] << 
413     This->fVP.SetUpVector(G4Vector3D(up[0], up << 
414                                                << 
415     SbVec3f pos = camera->position.getValue(); << 
416     SbVec3f target = pos + direction * camera- << 
417                                                << 
418     This->fVP.SetCurrentTargetPoint(G4Point3D( << 
419                                                << 
420     // FWJ camera sensor no longer needed      << 
421     // Viewer had changed the camera type,        346     // Viewer had changed the camera type, 
422     // attach the fCameraSensor to the new cam    347     // attach the fCameraSensor to the new camera.
423     // FWJ DEBUG                               << 348     SoCamera* camera = (SoCamera*)node;
424     //    G4cout << "   SWITCHING TO CAMERA "  << 349     This->fCameraSensor->detach();
425     //    This->fCameraSensor->detach();       << 350     This->fCameraSensor->attach(camera);
426     //    This->fCameraSensor->attach(camera); << 
427   }                                               351   }
428                                                   352 
429 }                                                 353 }
430                                                   354 
431 /* FWJ This sensor is no longer needed         << 
432 void G4OpenInventorViewer::CameraSensorCB(void    355 void G4OpenInventorViewer::CameraSensorCB(void* aThis,SoSensor* aSensor) { 
433   G4OpenInventorViewer* This = (G4OpenInventor    356   G4OpenInventorViewer* This = (G4OpenInventorViewer*)aThis;
434                                                   357 
435   //  printf("debug : CameraSensorCB\n");      << 358   //printf("debug : CameraSensorCB\n");
436                                                   359 
437   SoNode* node = ((SoNodeSensor*)aSensor)->get    360   SoNode* node = ((SoNodeSensor*)aSensor)->getTriggerNode();
438 //  printf("debug : CameraSensorCB %s\n",      << 
439 //         node->getTypeId().getName().getStri << 
440                                                   361 
441   if(node->isOfType(SoCamera::getClassTypeId()    362   if(node->isOfType(SoCamera::getClassTypeId())) {
442     SoCamera* camera = (SoCamera*)node;           363     SoCamera* camera = (SoCamera*)node;
443                                                   364 
444     SbVec3f direction, up;                        365     SbVec3f direction, up;
445     lookedAt(camera,direction, up);               366     lookedAt(camera,direction, up);
446     This->fVP.SetViewpointDirection               367     This->fVP.SetViewpointDirection
447       (G4Vector3D(-direction[0],-direction[1],    368       (G4Vector3D(-direction[0],-direction[1],-direction[2]));
448     This->fVP.SetUpVector(G4Vector3D(up[0],up[    369     This->fVP.SetUpVector(G4Vector3D(up[0],up[1],up[2]));
449                                                   370 
450     SbVec3f pos = camera->position.getValue();    371     SbVec3f pos = camera->position.getValue();
451     SbVec3f target = pos + direction * camera-    372     SbVec3f target = pos + direction * camera->focalDistance.getValue();
452                                                   373 
453     This->fVP.SetCurrentTargetPoint(G4Point3D(    374     This->fVP.SetCurrentTargetPoint(G4Point3D(target[0],target[1],target[2]));
454   }                                               375   }
455 }                                                 376 }
456 */                                             << 
457                                                   377 
458 void G4OpenInventorViewer::SelectionCB(           378 void G4OpenInventorViewer::SelectionCB(
459  void* aThis                                      379  void* aThis
460 ,SoPath* aPath                                    380 ,SoPath* aPath
461 )                                                 381 ) 
462 {                                                 382 {
463   G4OpenInventorViewer* This = (G4OpenInventor    383   G4OpenInventorViewer* This = (G4OpenInventorViewer*)aThis;
464   SoNode* node = ((SoFullPath*)aPath)->getTail    384   SoNode* node = ((SoFullPath*)aPath)->getTail();
465   G4AttHolder* attHolder = dynamic_cast<G4AttH << 385   G4String name((char*)node->getName().getString());
466   if(attHolder && attHolder->GetAttDefs().size << 386   G4String cls((char*)node->getTypeId().getName().getString());
467     for (size_t i = 0; i < attHolder->GetAttDe << 387   G4cout << "SoNode : " << node 
468       G4cout << G4AttCheck(attHolder->GetAttVa << 388          << " SoType : " << cls 
469          attHolder->GetAttDefs()[i]);          << 389          << " name : " << name 
470     }                                          << 390          << G4endl;
471   } else {                                     << 391 /*FIXME : to explore
472     G4String name((char*)node->getName().getSt << 
473     G4String cls((char*)node->getTypeId().getN << 
474     G4cout << "SoNode : " << node              << 
475      << " SoType : " << cls                    << 
476      << " name : " << name                     << 
477      << G4endl;                                << 
478     G4cout << "No attributes attached." << G4e << 
479   }                                            << 
480   /*FIXME : to explore (need different button  << 
481   if(node->isOfType(Geant4_SoPolyhedron::getCl    392   if(node->isOfType(Geant4_SoPolyhedron::getClassTypeId())) {
482     Geant4_SoPolyhedron* polyhedron = (Geant4_    393     Geant4_SoPolyhedron* polyhedron = (Geant4_SoPolyhedron*)node;
483     if(polyhedron->solid.getValue()==FALSE)       394     if(polyhedron->solid.getValue()==FALSE)
484       polyhedron->solid.setValue(TRUE);           395       polyhedron->solid.setValue(TRUE);
485     else                                          396     else
486       polyhedron->solid.setValue(FALSE);          397       polyhedron->solid.setValue(FALSE);
487   }*/                                             398   }*/
488   This->fSoSelection->deselectAll();              399   This->fSoSelection->deselectAll();
489 }                                                 400 }
490 /*                                                401 /*
491 void G4OpenInventorViewer::DeselectionCB(         402 void G4OpenInventorViewer::DeselectionCB(
492  void* aThis                                      403  void* aThis
493 ,SoPath* aPath                                    404 ,SoPath* aPath
494 )                                                 405 ) 
495 {                                                 406 {
496   //G4OpenInventorViewer* This = (G4OpenInvent    407   //G4OpenInventorViewer* This = (G4OpenInventorViewer*)aThis;
497   G4String name((char*)aPath->getTail()->getTy    408   G4String name((char*)aPath->getTail()->getTypeId().getName().getString());
498   G4cout << "Deselect : " << name << G4endl;      409   G4cout << "Deselect : " << name << G4endl;
499 }                                                 410 }
500 */                                                411 */
501                                                   412 
502 void G4OpenInventorViewer::DrawDetector() {       413 void G4OpenInventorViewer::DrawDetector() {
503   /* Replace this... - JA                      << 
504   // DrawView does a ClearStore. Do not clear     414   // DrawView does a ClearStore. Do not clear the transient store :
505   SoSeparator* tmp = fG4OpenInventorSceneHandl    415   SoSeparator* tmp = fG4OpenInventorSceneHandler.fTransientRoot;
506   fG4OpenInventorSceneHandler.fTransientRoot =    416   fG4OpenInventorSceneHandler.fTransientRoot = new SoSeparator;
507   if (!fNeedKernelVisit) KernelVisitDecision() << 417   KernelVisitDecision();
508   ProcessView();                                  418   ProcessView();
509   fG4OpenInventorSceneHandler.fTransientRoot->    419   fG4OpenInventorSceneHandler.fTransientRoot->unref();
510   fG4OpenInventorSceneHandler.fTransientRoot =    420   fG4OpenInventorSceneHandler.fTransientRoot = tmp;
511   */                                           << 
512   // ...by this... - JA                        << 
513   DrawView();                                  << 
514 }                                                 421 }
515                                                   422 
516 //////////////////////////////////////////////    423 //////////////////////////////////////////////////////////////////////////////
517 /// Menu items callbacks /////////////////////    424 /// Menu items callbacks /////////////////////////////////////////////////////
518 //////////////////////////////////////////////    425 //////////////////////////////////////////////////////////////////////////////
519                                                   426 
520 void G4OpenInventorViewer::Escape(){              427 void G4OpenInventorViewer::Escape(){
521   G4cout << "Escape..." <<G4endl;                 428   G4cout << "Escape..." <<G4endl;
522   fInteractorManager->RequireExitSecondaryLoop    429   fInteractorManager->RequireExitSecondaryLoop (OIV_EXIT_CODE);
523 }                                                 430 }
524                                                   431 
525 void G4OpenInventorViewer::WritePostScript(con    432 void G4OpenInventorViewer::WritePostScript(const G4String& aFile) {
526   if(!fGL2PSAction) return;                       433   if(!fGL2PSAction) return;
527   fGL2PSAction->setFileName(aFile.c_str());       434   fGL2PSAction->setFileName(aFile.c_str());
528   fGL2PSAction->setExportImageFormat_EPS();    << 
529   fGL2PSAction->setTitleAndProducer("Geant4 ou << 
530   G4cout << "Produce " << aFile << "..." << G4 << 
531   if (fGL2PSAction->enableFileWriting()) {     << 
532     ViewerRender();                            << 
533     fGL2PSAction->disableFileWriting();        << 
534   }                                            << 
535 }                                              << 
536                                                << 
537 void G4OpenInventorViewer::WritePDF(const G4St << 
538   if(!fGL2PSAction) return;                    << 
539   fGL2PSAction->setFileName(aFile.c_str());    << 
540   fGL2PSAction->setExportImageFormat_PDF();    << 
541   fGL2PSAction->setTitleAndProducer("Geant4 ou << 
542   G4cout << "Produce " << aFile << "..." << G4    435   G4cout << "Produce " << aFile << "..." << G4endl;
543   if (fGL2PSAction->enableFileWriting()) {     << 436   fGL2PSAction->enableFileWriting();
544     ViewerRender();                            << 437   ViewerRender();
545     fGL2PSAction->disableFileWriting();        << 438   fGL2PSAction->disableFileWriting();
546   }                                            << 
547 }                                                 439 }
548                                                   440 
549 void G4OpenInventorViewer::WritePixmapPostScri    441 void G4OpenInventorViewer::WritePixmapPostScript(const G4String& aFile) {
550   fSoImageWriter->fileName.setValue(aFile.c_st    442   fSoImageWriter->fileName.setValue(aFile.c_str());
551   //imageWriter->format.setValue(SoImageWriter    443   //imageWriter->format.setValue(SoImageWriter::POST_SCRIPT);
552   fSoImageWriter->enable();                       444   fSoImageWriter->enable();
553   ViewerRender();                                 445   ViewerRender();
554   fSoImageWriter->disable();                      446   fSoImageWriter->disable();
555   if(fSoImageWriter->getStatus()) {               447   if(fSoImageWriter->getStatus()) {
556     G4cout << G4String(fSoImageWriter->fileNam    448     G4cout << G4String(fSoImageWriter->fileName.getValue().getString()) 
557            << " produced."                        449            << " produced."
558            << G4endl;                             450            << G4endl;
559   } else {                                        451   } else {
560     G4cout << G4String(fSoImageWriter->fileNam    452     G4cout << G4String(fSoImageWriter->fileName.getValue().getString()) 
561            << " not produced."                    453            << " not produced."
562            << G4endl;                             454            << G4endl;
563   }                                               455   }
564 }                                                 456 }  
565                                                   457 
566 void G4OpenInventorViewer::WriteInventor(const    458 void G4OpenInventorViewer::WriteInventor(const G4String& aFile) {
567   G4cout << "Produce " << aFile << "..." << G4    459   G4cout << "Produce " << aFile << "..." << G4endl;
568                                                   460 
569   SbBool genAlternateRep = TRUE;                  461   SbBool genAlternateRep = TRUE;
570   //SbBool binary = FALSE;                        462   //SbBool binary = FALSE;
571   SbBool binary = TRUE;                           463   SbBool binary = TRUE;
572   SoAlternateRepAction alternateRepAction;        464   SoAlternateRepAction alternateRepAction;
573   if(genAlternateRep==TRUE) {                     465   if(genAlternateRep==TRUE) {
574     alternateRepAction.setGenerate(TRUE); //Cl    466     alternateRepAction.setGenerate(TRUE); //Clear alternate reps.
575     alternateRepAction.apply(fSoSelection);       467     alternateRepAction.apply(fSoSelection);
576   }                                               468   }
577                                                   469 
578   SoWriteAction writeAction;                      470   SoWriteAction writeAction;
579   writeAction.getOutput()->openFile(aFile.c_st    471   writeAction.getOutput()->openFile(aFile.c_str());
580   writeAction.getOutput()->setBinary(binary);     472   writeAction.getOutput()->setBinary(binary);
581   writeAction.apply(fSoSelection);                473   writeAction.apply(fSoSelection);
582   writeAction.getOutput()->closeFile();           474   writeAction.getOutput()->closeFile();
583                                                   475 
584   if(genAlternateRep==TRUE) {                     476   if(genAlternateRep==TRUE) {
585     alternateRepAction.setGenerate(FALSE); //C    477     alternateRepAction.setGenerate(FALSE); //Clear alternate reps.
586     alternateRepAction.apply(fSoSelection);       478     alternateRepAction.apply(fSoSelection);
587   }                                               479   }
588                                                   480 
589                                                   481 
590                                                   482 
591 }                                                 483 }
592                                                   484 
593 struct Counter {                                  485 struct Counter {
594  int fTriangles;                                  486  int fTriangles;
595  int fLineSegments;                               487  int fLineSegments;
596  int fPoints;                                     488  int fPoints;
597 };                                                489 };
598                                                   490 
599 static void CountTrianglesCB(                     491 static void CountTrianglesCB(
600  void* userData                                   492  void* userData
601 ,SoCallbackAction*                                493 ,SoCallbackAction*
602 ,const SoPrimitiveVertex*                         494 ,const SoPrimitiveVertex*
603 ,const SoPrimitiveVertex*,                        495 ,const SoPrimitiveVertex*,
604 const SoPrimitiveVertex*)                         496 const SoPrimitiveVertex*)
605 {                                                 497 {
606   Counter* counter = (Counter*)userData;          498   Counter* counter = (Counter*)userData;
607   counter->fTriangles++;                          499   counter->fTriangles++;
608 }                                                 500 }
609                                                   501 
610 static void CountLineSegmentsCB(                  502 static void CountLineSegmentsCB(
611  void* userData                                   503  void* userData
612 ,SoCallbackAction*                                504 ,SoCallbackAction*
613 ,const SoPrimitiveVertex*                         505 ,const SoPrimitiveVertex*
614 ,const SoPrimitiveVertex*)                        506 ,const SoPrimitiveVertex*)
615 {                                                 507 {
616   Counter* counter = (Counter*)userData;          508   Counter* counter = (Counter*)userData;
617   counter->fLineSegments++;                       509   counter->fLineSegments++;
618 }                                                 510 }
619                                                   511 
620 static void CountPointsCB(                        512 static void CountPointsCB(
621  void* userData                                   513  void* userData
622 ,SoCallbackAction*                                514 ,SoCallbackAction*
623 ,const SoPrimitiveVertex*)                        515 ,const SoPrimitiveVertex*)
624 {                                                 516 {
625   Counter* counter = (Counter*)userData;          517   Counter* counter = (Counter*)userData;
626   counter->fPoints++;                             518   counter->fPoints++;
627 }                                                 519 }
628                                                   520 
629 void G4OpenInventorViewer::SceneGraphStatistic    521 void G4OpenInventorViewer::SceneGraphStatistics() {
630   Counter counter;                                522   Counter counter;
631   counter.fTriangles = 0;                         523   counter.fTriangles = 0;
632   counter.fLineSegments = 0;                      524   counter.fLineSegments = 0;
633   counter.fPoints = 0;                            525   counter.fPoints = 0;
634                                                   526 
635   SoCallbackAction callbackAction;                527   SoCallbackAction callbackAction;
636   callbackAction.addTriangleCallback              528   callbackAction.addTriangleCallback
637     (SoShape::getClassTypeId(),CountTrianglesC    529     (SoShape::getClassTypeId(),CountTrianglesCB,(void*)&counter);
638   callbackAction.addLineSegmentCallback           530   callbackAction.addLineSegmentCallback
639     (SoShape::getClassTypeId(),CountLineSegmen    531     (SoShape::getClassTypeId(),CountLineSegmentsCB,(void*)&counter);
640   callbackAction.addPointCallback                 532   callbackAction.addPointCallback
641     (SoShape::getClassTypeId(),CountPointsCB,(    533     (SoShape::getClassTypeId(),CountPointsCB,(void*)&counter);
642   callbackAction.apply(fSoSelection);             534   callbackAction.apply(fSoSelection);
643                                                   535 
644   SoCounterAction counterAction;                  536   SoCounterAction counterAction;
645   counterAction.apply(fSoSelection);              537   counterAction.apply(fSoSelection);
646   int nodes = counterAction.getCount();           538   int nodes = counterAction.getCount();
647                                                   539 
648   counterAction.setLookFor(SoCounterAction::TY    540   counterAction.setLookFor(SoCounterAction::TYPE);
649   counterAction.setType(SoShape::getClassTypeI    541   counterAction.setType(SoShape::getClassTypeId());
650   counterAction.apply(fSoSelection);              542   counterAction.apply(fSoSelection);
651   int shapes = counterAction.getCount();          543   int shapes = counterAction.getCount();
652                                                   544 
653   G4cout << "Number of triangles : " << counte    545   G4cout << "Number of triangles : " << counter.fTriangles << G4endl;
654   G4cout << "Number of line segments : " << co    546   G4cout << "Number of line segments : " << counter.fLineSegments << G4endl;
655   G4cout << "Number of points : " << counter.f    547   G4cout << "Number of points : " << counter.fPoints << G4endl;
656   G4cout << "Number of nodes : " << nodes << G    548   G4cout << "Number of nodes : " << nodes << G4endl;
657   G4cout << "Number of shapes : " << shapes <<    549   G4cout << "Number of shapes : " << shapes << G4endl;
658 }                                                 550 }
659                                                   551 
660 void G4OpenInventorViewer::EraseDetector() {      552 void G4OpenInventorViewer::EraseDetector() {
661   fG4OpenInventorSceneHandler.fDetectorRoot->r    553   fG4OpenInventorSceneHandler.fDetectorRoot->removeAllChildren();
662 }                                                 554 }
663 void G4OpenInventorViewer::EraseEvent() {         555 void G4OpenInventorViewer::EraseEvent() {
664   fG4OpenInventorSceneHandler.fTransientRoot->    556   fG4OpenInventorSceneHandler.fTransientRoot->removeAllChildren();
665 }                                                 557 }
666                                                   558 
667 void G4OpenInventorViewer::SetPreviewAndFull()    559 void G4OpenInventorViewer::SetPreviewAndFull() {
668   fG4OpenInventorSceneHandler.fPreviewAndFull     560   fG4OpenInventorSceneHandler.fPreviewAndFull = true;
669                                                   561 
670   NeedKernelVisit();                              562   NeedKernelVisit();
671   DrawDetector();                                 563   DrawDetector();
672 }                                                 564 }
673                                                   565 
674 void G4OpenInventorViewer::SetPreview() {         566 void G4OpenInventorViewer::SetPreview() {
675   fG4OpenInventorSceneHandler.fPreviewAndFull     567   fG4OpenInventorSceneHandler.fPreviewAndFull = false;
676                                                   568 
677   NeedKernelVisit();                              569   NeedKernelVisit();
678   DrawDetector();                                 570   DrawDetector();
679 }                                                 571 }
680                                                   572 
681 // When ViewParameter <-> SoCamera mapping rea    573 // When ViewParameter <-> SoCamera mapping ready 
682 // uncomment the below                            574 // uncomment the below
683 //#define USE_SET_VIEW                            575 //#define USE_SET_VIEW
684                                                   576 
685 void G4OpenInventorViewer::SetSolid() {           577 void G4OpenInventorViewer::SetSolid() {
686   G4ViewParameters vp = GetViewParameters();      578   G4ViewParameters vp = GetViewParameters();
687   G4ViewParameters::DrawingStyle existingStyle    579   G4ViewParameters::DrawingStyle existingStyle = vp.GetDrawingStyle();
688   //From G4VisCommandsViewerSet : /vis/viewer/    580   //From G4VisCommandsViewerSet : /vis/viewer/set/style solid.
689   switch (existingStyle) {                        581   switch (existingStyle) {
690   case G4ViewParameters::wireframe:               582   case G4ViewParameters::wireframe:
691     vp.SetDrawingStyle(G4ViewParameters::hsr);    583     vp.SetDrawingStyle(G4ViewParameters::hsr);
692     break;                                        584     break;
693   case G4ViewParameters::hlr:                     585   case G4ViewParameters::hlr:
694     vp.SetDrawingStyle(G4ViewParameters::hlhsr    586     vp.SetDrawingStyle(G4ViewParameters::hlhsr);
695     break;                                        587     break;
696   case G4ViewParameters::hsr:                     588   case G4ViewParameters::hsr:
697     break;                                        589     break;
698   case G4ViewParameters::hlhsr:                   590   case G4ViewParameters::hlhsr:
699     break;                                        591     break;
700   case G4ViewParameters::cloud:                << 
701     vp.SetDrawingStyle(G4ViewParameters::hsr); << 
702     break;                                     << 
703   }                                               592   }
704   SetViewParameters(vp);                          593   SetViewParameters(vp);
                                                   >> 594   fModified = false; // To avoid a SetView in G4VViewer::ProcessView 
                                                   >> 595                      // that will change the camera.
705   DrawDetector();                                 596   DrawDetector();
706 }                                                 597 }
707 void G4OpenInventorViewer::SetWireFrame() {       598 void G4OpenInventorViewer::SetWireFrame() {
708   G4ViewParameters vp = GetViewParameters();      599   G4ViewParameters vp = GetViewParameters();
709   G4ViewParameters::DrawingStyle existingStyle    600   G4ViewParameters::DrawingStyle existingStyle = vp.GetDrawingStyle();
710   switch (existingStyle) {                        601   switch (existingStyle) {
711   case G4ViewParameters::wireframe:               602   case G4ViewParameters::wireframe:
712     break;                                        603     break;
713   case G4ViewParameters::hlr:                     604   case G4ViewParameters::hlr:
714     break;                                        605     break;
715   case G4ViewParameters::hsr:                     606   case G4ViewParameters::hsr:
716     vp.SetDrawingStyle(G4ViewParameters::wiref    607     vp.SetDrawingStyle(G4ViewParameters::wireframe);
717     break;                                        608     break;
718   case G4ViewParameters::hlhsr:                   609   case G4ViewParameters::hlhsr:
719     vp.SetDrawingStyle(G4ViewParameters::hlr);    610     vp.SetDrawingStyle(G4ViewParameters::hlr);
720     break;                                        611     break;
721   case G4ViewParameters::cloud:                << 
722     vp.SetDrawingStyle(G4ViewParameters::wiref << 
723     break;                                     << 
724   }                                               612   }
725   SetViewParameters(vp);                          613   SetViewParameters(vp);
                                                   >> 614   fModified = false; // To avoid a SetView in G4VViewer::ProcessView 
                                                   >> 615                      // that will change the camera.
726   DrawDetector();                                 616   DrawDetector();
727 }                                                 617 }
728                                                   618 
729                                                   619 
730 void G4OpenInventorViewer::SetReducedWireFrame    620 void G4OpenInventorViewer::SetReducedWireFrame(bool aValue) {
731   G4ViewParameters vp = GetViewParameters();      621   G4ViewParameters vp = GetViewParameters();
732                                                   622 
733   // Set the wire frame kind :                    623   // Set the wire frame kind :
734   vp.SetAuxEdgeVisible(!aValue);                  624   vp.SetAuxEdgeVisible(!aValue);
735                                                   625 
736   // Set wire frame :                             626   // Set wire frame :
737   G4ViewParameters::DrawingStyle existingStyle    627   G4ViewParameters::DrawingStyle existingStyle = vp.GetDrawingStyle();
738   switch (existingStyle) {                        628   switch (existingStyle) {
739   case G4ViewParameters::wireframe:               629   case G4ViewParameters::wireframe:
740     break;                                        630     break;
741   case G4ViewParameters::hlr:                     631   case G4ViewParameters::hlr:
742     break;                                        632     break;
743   case G4ViewParameters::hsr:                     633   case G4ViewParameters::hsr:
744     vp.SetDrawingStyle(G4ViewParameters::wiref    634     vp.SetDrawingStyle(G4ViewParameters::wireframe);
745     break;                                        635     break;
746   case G4ViewParameters::hlhsr:                   636   case G4ViewParameters::hlhsr:
747     vp.SetDrawingStyle(G4ViewParameters::hlr);    637     vp.SetDrawingStyle(G4ViewParameters::hlr);
748     break;                                        638     break;
749   case G4ViewParameters::cloud:                << 
750     vp.SetDrawingStyle(G4ViewParameters::wiref << 
751     break;                                     << 
752   }                                               639   }
753   SetViewParameters(vp);                          640   SetViewParameters(vp);
                                                   >> 641   fModified = false; // To avoid a SetView in G4VViewer::ProcessView 
                                                   >> 642                      // that will change the camera.
754   NeedKernelVisit(); // Just in case it was al    643   NeedKernelVisit(); // Just in case it was alread in wire framw.
755   DrawDetector();                                 644   DrawDetector();
756 }                                                 645 }
757                                                   646 
758 void G4OpenInventorViewer::UpdateScene() {        647 void G4OpenInventorViewer::UpdateScene() {
759   /* Replace this... - JA                      << 
760   fG4OpenInventorSceneHandler.ClearStore();       648   fG4OpenInventorSceneHandler.ClearStore();
761   ClearView();                                    649   ClearView();
762   if (!fNeedKernelVisit) KernelVisitDecision() << 650   KernelVisitDecision();
763   ProcessView();                                  651   ProcessView();
764   ShowView();                                     652   ShowView();
765   */                                           << 
766   // ...by this - JA                           << 
767   NeedKernelVisit();                           << 
768   DrawView();                                  << 
769 }                                                 653 }
770 G4String G4OpenInventorViewer::Help(const G4St    654 G4String G4OpenInventorViewer::Help(const G4String& aTopic) {
771   if(aTopic=="controls") {                        655   if(aTopic=="controls") {
772     return G4String("\                            656     return G4String("\
773 Controls on an Inventor examiner viewer are :\    657 Controls on an Inventor examiner viewer are :\n\
774 - in picking mode (cursor is the upper left ar    658 - in picking mode (cursor is the upper left arrow)\n\
775   Ctrl + pick a volume : see daughters.\n\        659   Ctrl + pick a volume : see daughters.\n\
776   Shift + pick a volume : see mother.\n\          660   Shift + pick a volume : see mother.\n\
777 - in viewing mode (cursor is the hand)\n\         661 - in viewing mode (cursor is the hand)\n\
778   Left-button + pointer move : rotate.\n\         662   Left-button + pointer move : rotate.\n\
779   Ctrl+Left-button + pointer move : pan.\n\       663   Ctrl+Left-button + pointer move : pan.\n\
780   Ctrl+Shift+Left-button + pointer move : scal    664   Ctrl+Shift+Left-button + pointer move : scale.\n\
781   Middle-button + pointer move : pan.\n\          665   Middle-button + pointer move : pan.\n\
782   Right-button : popup menu.\n");                 666   Right-button : popup menu.\n");
783   } else {                                        667   } else {
784     return "";                                    668     return "";
785   }                                               669   }
786 }                                                 670 }
                                                   >> 671 
                                                   >> 672 #endif
787                                                   673