Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
G4XXXStoredViewer.cc
Go to the documentation of this file.
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// $Id$
28//
29//
30// John Allison 7th March 2006
31// A template for a graphics driver with a store/database.
32//?? Lines beginning like this require specialisation for your driver.
33
34#include "G4XXXStoredViewer.hh"
35
36#include "G4VSceneHandler.hh"
38
39#include <fstream>
40#include <sstream>
41
43(G4VSceneHandler& sceneHandler, const G4String& name):
44 G4VViewer(sceneHandler, sceneHandler.IncrementViewCount(), name)
45{}
46
48
50#ifdef G4XXXStoredDEBUG
51 G4cout << "G4XXXStoredViewer::SetView() called." << G4endl;
52#endif
53}
54
56#ifdef G4XXXStoredDEBUG
57 G4cout << "G4XXXStoredViewer::ClearView() called." << G4endl;
58#endif
59}
60
62#ifdef G4XXXStoredDEBUG
63 G4cout << "G4XXXStoredViewer::DrawView() called." << G4endl;
64#endif
65
66 // First, a view should decide when to re-visit the G4 kernel.
67 // Sometimes it might not be necessary, e.g., if the scene is stored
68 // in a graphical database (e.g., OpenGL's display lists) and only
69 // the viewing angle has changed. But graphics systems without a
70 // graphical database will always need to visit the G4 kernel.
71
72 // The fNeedKernelVisit flag might have been set by the user in
73 // /vis/viewer/rebuild, but if not, make decision and set flag only
74 // if necessary...
76 G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
77
78 ProcessView (); // Clears store and processes scene only if necessary.
79
80 if (kernelVisitWasNeeded) {
81 // Some systems, notably OpenGL, can draw while re-building, so
82 // there might not be a need to draw from store again here. But
83 // in this case...
85 } else {
87 }
88
89 // ...before finally...
90 FinishView (); // Flush streams and/or swap buffers.
91}
92
94#ifdef G4XXXStoredDEBUG
95 G4cout << "G4XXXStoredViewer::ShowView() called." << G4endl;
96#endif
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 typedef std::list<G4String> Store;
105 typedef std::list<G4String>::iterator StoreIterator;
106 Store& store =
107 static_cast<G4XXXStoredSceneHandler&>(fSceneHandler).fStore;
108 if (store.empty() || CompareForKernelVisit(fLastVP)) {
109 NeedKernelVisit (); // Sets fNeedKernelVisit.
110 }
111 fLastVP = fVP;
112}
113
115{
116 // Typical comparison. Taken from OpenGL.
117 if (
118 (lastVP.GetDrawingStyle () != fVP.GetDrawingStyle ()) ||
119 (lastVP.IsAuxEdgeVisible () != fVP.IsAuxEdgeVisible ()) ||
120 (lastVP.GetRepStyle () != fVP.GetRepStyle ()) ||
121 (lastVP.IsCulling () != fVP.IsCulling ()) ||
122 (lastVP.IsCullingInvisible () != fVP.IsCullingInvisible ()) ||
123 (lastVP.IsDensityCulling () != fVP.IsDensityCulling ()) ||
124 (lastVP.IsCullingCovered () != fVP.IsCullingCovered ()) ||
125 // No need to visit kernel if section plane changes.
126 // No need to visit kernel if cutaway planes change.
127 (lastVP.IsExplode () != fVP.IsExplode ()) ||
128 (lastVP.GetNoOfSides () != fVP.GetNoOfSides ()) ||
129 (lastVP.IsMarkerNotHidden () != fVP.IsMarkerNotHidden ()) ||
130 (lastVP.GetDefaultVisAttributes()->GetColour() !=
135 (lastVP.GetVisAttributesModifiers().size() !=
137 ) {
138 return true;
139 }
140
141 if (lastVP.IsDensityCulling () &&
142 (lastVP.GetVisibleDensity () != fVP.GetVisibleDensity ()))
143 return true;
144
145 if (lastVP.IsExplode () &&
146 (lastVP.GetExplodeFactor () != fVP.GetExplodeFactor ()))
147 return true;
148
149 return false;
150}
151
153 typedef std::list<G4String> Store;
154 typedef std::list<G4String>::iterator StoreIterator;
155 Store& store =
156 static_cast<G4XXXStoredSceneHandler&>(fSceneHandler).fStore;
157 // Write to a file for testing...
158 static G4int iCount = 0;
159 std::ostringstream oss;
160 oss << fName << '.' << iCount++ << ".out";
161 std::ofstream ofs(oss.str().c_str());
162 for (StoreIterator i = store.begin(); i != store.end(); ++i) {
163 ofs << *i;
164 }
165 ofs.close();
166}
int G4int
Definition: G4Types.hh:66
bool G4bool
Definition: G4Types.hh:67
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
G4bool fNeedKernelVisit
Definition: G4VViewer.hh:142
void ProcessView()
Definition: G4VViewer.cc:115
G4VSceneHandler & fSceneHandler
Definition: G4VViewer.hh:133
G4String fName
Definition: G4VViewer.hh:135
void NeedKernelVisit()
Definition: G4VViewer.cc:86
G4ViewParameters fVP
Definition: G4VViewer.hh:137
virtual void FinishView()
Definition: G4VViewer.cc:111
const std::vector< G4ModelingParameters::VisAttributesModifier > & GetVisAttributesModifiers() const
G4int GetNoOfSides() const
G4double GetExplodeFactor() const
G4bool IsMarkerNotHidden() const
const G4Colour & GetBackgroundColour() const
G4bool IsCulling() const
const G4VisAttributes * GetDefaultTextVisAttributes() const
G4bool IsExplode() const
G4bool IsCullingInvisible() const
RepStyle GetRepStyle() const
const G4VisAttributes * GetDefaultVisAttributes() const
G4bool IsDensityCulling() const
G4double GetVisibleDensity() const
G4bool IsCullingCovered() const
DrawingStyle GetDrawingStyle() const
G4bool IsAuxEdgeVisible() const
const G4Colour & GetColour() const
G4bool CompareForKernelVisit(G4ViewParameters &)
G4XXXStoredViewer(G4VSceneHandler &, const G4String &name)
virtual ~G4XXXStoredViewer()
G4ViewParameters fLastVP