ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4XXXSGViewer.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4XXXSGViewer.cc
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 //
28 //
29 // John Allison 10th March 2006
30 // A template for a sophisticated graphics driver with a scene graph.
31 //?? Lines beginning like this require specialisation for your driver.
32 
33 #include "G4XXXSGViewer.hh"
34 
35 #include "G4VSceneHandler.hh"
36 #include "G4XXXSGSceneHandler.hh"
37 
38 #include <fstream>
39 
41 (G4VSceneHandler& sceneHandler, const G4String& name):
42  G4VViewer(sceneHandler, sceneHandler.IncrementViewCount(), name)
43 {}
44 
46 
48  //#ifdef G4XXXSGDEBUG
49  G4cout << "G4XXXSGViewer::SetView() called." << G4endl;
50  //#endif
51 }
52 
54  //#ifdef G4XXXSGDEBUG
55  G4cout << "G4XXXSGViewer::ClearView() called." << G4endl;
56  //#endif
57 }
58 
60  //#ifdef G4XXXSGDEBUG
61  G4cout << "G4XXXSGViewer::DrawView() called." << G4endl;
62  //#endif
63 
64  // First, a view should decide when to re-visit the G4 kernel.
65  // Sometimes it might not be necessary, e.g., if the scene is stored
66  // in a graphical database (e.g., OpenGL's display lists) and only
67  // the viewing angle has changed. But graphics systems without a
68  // graphical database will always need to visit the G4 kernel.
69 
70  // The fNeedKernelVisit flag might have been set by the user in
71  // /vis/viewer/rebuild, but if not, make decision and set flag only
72  // if necessary...
74  G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
75 
76  ProcessView (); // Clears store and processes scene only if necessary.
77 
78  if (kernelVisitWasNeeded) {
79  // Some systems, notably OpenGL, can draw while re-building, so
80  // there might not be a need to draw from store again here. But
81  // in this case...
82  DrawFromStore("G4XXXSGViewer::DrawView");
83  } else {
84  DrawFromStore("G4XXXSGViewer::DrawView");
85  }
86 
87  // ...before finally...
88  FinishView (); // Flush streams and/or swap buffers.
89 }
90 
92  //#ifdef G4XXXSGDEBUG
93  G4cout << "G4XXXSGViewer::ShowView() called." << G4endl;
94  //#endif
95  // This is what you should see...
96  DrawFromStore("G4XXXSGViewer::ShowView");
97 }
98 
100 
101  // If there's a significant difference with the last view parameters
102  // of either the scene handler or this viewer, trigger a rebuild.
103 
104  SceneGraph& sceneGraph =
105  static_cast<G4XXXSGSceneHandler&>(fSceneHandler).fSceneGraph;
106  if (sceneGraph.fDaughters.size() == 3 // I.e., only the root nodes.
107  // (The above needs re-thinking.)
109  NeedKernelVisit (); // Sets fNeedKernelVisit.
110  }
111  fLastVP = fVP;
112 }
113 
115 {
116  // Typical comparison. Taken from OpenGL.
117  if (
118  (lastVP.GetDrawingStyle () != fVP.GetDrawingStyle ()) ||
120  (lastVP.IsAuxEdgeVisible () != fVP.IsAuxEdgeVisible ()) ||
121  (lastVP.IsCulling () != fVP.IsCulling ()) ||
122  (lastVP.IsCullingInvisible () != fVP.IsCullingInvisible ()) ||
123  (lastVP.IsDensityCulling () != fVP.IsDensityCulling ()) ||
124  (lastVP.IsCullingCovered () != fVP.IsCullingCovered ()) ||
125  (lastVP.GetCBDAlgorithmNumber() !=
127  // No need to visit kernel if section plane changes.
128  // No need to visit kernel if cutaway planes change.
129  (lastVP.IsExplode () != fVP.IsExplode ()) ||
130  (lastVP.GetNoOfSides () != fVP.GetNoOfSides ()) ||
131  (lastVP.IsMarkerNotHidden () != fVP.IsMarkerNotHidden ()) ||
132  (lastVP.GetDefaultVisAttributes()->GetColour() !=
134  (lastVP.GetDefaultTextVisAttributes()->GetColour() !=
136  (lastVP.GetBackgroundColour ()!= fVP.GetBackgroundColour ())||
137  (lastVP.GetVisAttributesModifiers() !=
139  ) {
140  return true;
141  }
142 
143  if (lastVP.IsDensityCulling () &&
144  (lastVP.GetVisibleDensity () != fVP.GetVisibleDensity ()))
145  return true;
146 
147  if (lastVP.GetCBDAlgorithmNumber() > 0) {
148  if (lastVP.GetCBDParameters().size() != fVP.GetCBDParameters().size()) return true;
149  else if (lastVP.GetCBDParameters() != fVP.GetCBDParameters()) return true;
150  }
151 
152  if (lastVP.IsExplode () &&
153  (lastVP.GetExplodeFactor () != fVP.GetExplodeFactor ()))
154  return true;
155 
156  return false;
157 }
158 
160  SceneGraph& sceneGraph =
161  static_cast<G4XXXSGSceneHandler&>(fSceneHandler).fSceneGraph;
162  // Write to a file for testing...
163  static G4int iCount = 0;
164  std::ostringstream oss;
165  oss << source << '.' << fName << '.' << iCount++ << ".out";
166  G4cout << "Writing " << oss.str() << G4endl;
167  std::ofstream ofs(oss.str().c_str());
168  JA::PrintTree(ofs,&sceneGraph);
169  ofs.close();
170 }