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 1.0)


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