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: G4XXXStoredViewer.cc,v 1.5 2006/08/29 16:11:25 allison Exp $ |
---|
28 | // GEANT4 tag $Name: $ |
---|
29 | // |
---|
30 | // |
---|
31 | // John Allison 7th March 2006 |
---|
32 | // A template for a graphics driver with a store/database. |
---|
33 | //?? Lines beginning like this require specialisation for your driver. |
---|
34 | |
---|
35 | #include "G4XXXStoredViewer.hh" |
---|
36 | |
---|
37 | #include "G4VSceneHandler.hh" |
---|
38 | #include "G4XXXStoredSceneHandler.hh" |
---|
39 | |
---|
40 | #include <fstream> |
---|
41 | #include <sstream> |
---|
42 | |
---|
43 | G4XXXStoredViewer::G4XXXStoredViewer |
---|
44 | (G4VSceneHandler& sceneHandler, const G4String& name): |
---|
45 | G4VViewer(sceneHandler, sceneHandler.IncrementViewCount(), name) |
---|
46 | {} |
---|
47 | |
---|
48 | G4XXXStoredViewer::~G4XXXStoredViewer() {} |
---|
49 | |
---|
50 | void G4XXXStoredViewer::SetView() { |
---|
51 | #ifdef G4XXXStoredDEBUG |
---|
52 | G4cout << "G4XXXStoredViewer::SetView() called." << G4endl; |
---|
53 | #endif |
---|
54 | } |
---|
55 | |
---|
56 | void G4XXXStoredViewer::ClearView() { |
---|
57 | #ifdef G4XXXStoredDEBUG |
---|
58 | G4cout << "G4XXXStoredViewer::ClearView() called." << G4endl; |
---|
59 | #endif |
---|
60 | } |
---|
61 | |
---|
62 | void G4XXXStoredViewer::DrawView() { |
---|
63 | #ifdef G4XXXStoredDEBUG |
---|
64 | G4cout << "G4XXXStoredViewer::DrawView() called." << G4endl; |
---|
65 | #endif |
---|
66 | |
---|
67 | // First, a view should decide when to re-visit the G4 kernel. |
---|
68 | // Sometimes it might not be necessary, e.g., if the scene is stored |
---|
69 | // in a graphical database (e.g., OpenGL's display lists) and only |
---|
70 | // the viewing angle has changed. But graphics systems without a |
---|
71 | // graphical database will always need to visit the G4 kernel. |
---|
72 | |
---|
73 | // The fNeedKernelVisit flag might have been set by the user in |
---|
74 | // /vis/viewer/rebuild, but if not, make decision and set flag only |
---|
75 | // if necessary... |
---|
76 | if (!fNeedKernelVisit) KernelVisitDecision(); |
---|
77 | G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets). |
---|
78 | |
---|
79 | ProcessView (); // Clears store and processes scene only if necessary. |
---|
80 | |
---|
81 | if (kernelVisitWasNeeded) { |
---|
82 | // Some systems, notably OpenGL, can draw while re-building, so |
---|
83 | // there might not be a need to draw from store again here. But |
---|
84 | // in this case... |
---|
85 | DrawFromStore(); |
---|
86 | } else { |
---|
87 | DrawFromStore(); |
---|
88 | } |
---|
89 | |
---|
90 | // ...before finally... |
---|
91 | FinishView (); // Flush streams and/or swap buffers. |
---|
92 | } |
---|
93 | |
---|
94 | void G4XXXStoredViewer::ShowView() { |
---|
95 | #ifdef G4XXXStoredDEBUG |
---|
96 | G4cout << "G4XXXStoredViewer::ShowView() called." << G4endl; |
---|
97 | #endif |
---|
98 | } |
---|
99 | |
---|
100 | void G4XXXStoredViewer::KernelVisitDecision () { |
---|
101 | |
---|
102 | // If there's a significant difference with the last view parameters |
---|
103 | // of either the scene handler or this viewer, trigger a rebuild. |
---|
104 | |
---|
105 | typedef std::list<G4String> Store; |
---|
106 | typedef std::list<G4String>::iterator StoreIterator; |
---|
107 | Store& store = |
---|
108 | static_cast<G4XXXStoredSceneHandler&>(fSceneHandler).fStore; |
---|
109 | if (store.empty() || CompareForKernelVisit(fLastVP)) { |
---|
110 | NeedKernelVisit (); // Sets fNeedKernelVisit. |
---|
111 | } |
---|
112 | fLastVP = fVP; |
---|
113 | } |
---|
114 | |
---|
115 | G4bool G4XXXStoredViewer::CompareForKernelVisit(G4ViewParameters& lastVP) |
---|
116 | { |
---|
117 | // Typical comparison. Taken from OpenGL. |
---|
118 | if ( |
---|
119 | (lastVP.GetDrawingStyle () != fVP.GetDrawingStyle ()) || |
---|
120 | (lastVP.IsAuxEdgeVisible () != fVP.IsAuxEdgeVisible ()) || |
---|
121 | (lastVP.GetRepStyle () != fVP.GetRepStyle ()) || |
---|
122 | (lastVP.IsCulling () != fVP.IsCulling ()) || |
---|
123 | (lastVP.IsCullingInvisible () != fVP.IsCullingInvisible ()) || |
---|
124 | (lastVP.IsDensityCulling () != fVP.IsDensityCulling ()) || |
---|
125 | (lastVP.IsCullingCovered () != fVP.IsCullingCovered ()) || |
---|
126 | // No need to visit kernel if section plane changes. |
---|
127 | // No need to visit kernel if cutaway planes change. |
---|
128 | (lastVP.IsExplode () != fVP.IsExplode ()) || |
---|
129 | (lastVP.GetNoOfSides () != fVP.GetNoOfSides ()) || |
---|
130 | (lastVP.IsMarkerNotHidden () != fVP.IsMarkerNotHidden ()) || |
---|
131 | (lastVP.GetBackgroundColour ()!= fVP.GetBackgroundColour ()) |
---|
132 | ) { |
---|
133 | return true; |
---|
134 | } |
---|
135 | |
---|
136 | if (lastVP.IsDensityCulling () && |
---|
137 | (lastVP.GetVisibleDensity () != fVP.GetVisibleDensity ())) |
---|
138 | return true; |
---|
139 | |
---|
140 | if (lastVP.IsExplode () && |
---|
141 | (lastVP.GetExplodeFactor () != fVP.GetExplodeFactor ())) |
---|
142 | return true; |
---|
143 | |
---|
144 | return false; |
---|
145 | } |
---|
146 | |
---|
147 | void G4XXXStoredViewer::DrawFromStore() { |
---|
148 | typedef std::list<G4String> Store; |
---|
149 | typedef std::list<G4String>::iterator StoreIterator; |
---|
150 | Store& store = |
---|
151 | static_cast<G4XXXStoredSceneHandler&>(fSceneHandler).fStore; |
---|
152 | // Write to a file for testing... |
---|
153 | static G4int iCount = 0; |
---|
154 | std::ostringstream oss; |
---|
155 | oss << fName << '.' << iCount++ << ".out"; |
---|
156 | std::ofstream ofs(oss.str().c_str()); |
---|
157 | for (StoreIterator i = store.begin(); i != store.end(); ++i) { |
---|
158 | ofs << *i; |
---|
159 | } |
---|
160 | ofs.close(); |
---|
161 | } |
---|