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


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