Geant4
9.6.p02
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
geant4_9_6_p02
source
visualization
XXX
src
G4XXXSGViewer.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 10th March 2006
31
// A template for a sophisticated graphics driver with a scene graph.
32
//?? Lines beginning like this require specialisation for your driver.
33
34
#include "
G4XXXSGViewer.hh
"
35
36
#include "
G4VSceneHandler.hh
"
37
#include "
G4XXXSGSceneHandler.hh
"
38
39
#include <fstream>
40
41
G4XXXSGViewer::G4XXXSGViewer
42
(
G4VSceneHandler
& sceneHandler,
const
G4String
&
name
):
43
G4VViewer
(sceneHandler, sceneHandler.
IncrementViewCount
(),
name
)
44
{}
45
46
G4XXXSGViewer::~G4XXXSGViewer
() {}
47
48
void
G4XXXSGViewer::SetView
() {
49
//#ifdef G4XXXSGDEBUG
50
G4cout
<<
"G4XXXSGViewer::SetView() called."
<<
G4endl
;
51
//#endif
52
}
53
54
void
G4XXXSGViewer::ClearView
() {
55
//#ifdef G4XXXSGDEBUG
56
G4cout
<<
"G4XXXSGViewer::ClearView() called."
<<
G4endl
;
57
//#endif
58
}
59
60
void
G4XXXSGViewer::DrawView
() {
61
//#ifdef G4XXXSGDEBUG
62
G4cout
<<
"G4XXXSGViewer::DrawView() called."
<<
G4endl
;
63
//#endif
64
65
// First, a view should decide when to re-visit the G4 kernel.
66
// Sometimes it might not be necessary, e.g., if the scene is stored
67
// in a graphical database (e.g., OpenGL's display lists) and only
68
// the viewing angle has changed. But graphics systems without a
69
// graphical database will always need to visit the G4 kernel.
70
71
// The fNeedKernelVisit flag might have been set by the user in
72
// /vis/viewer/rebuild, but if not, make decision and set flag only
73
// if necessary...
74
if
(!
fNeedKernelVisit
)
KernelVisitDecision
();
75
G4bool
kernelVisitWasNeeded =
fNeedKernelVisit
;
// Keep (ProcessView resets).
76
77
ProcessView
();
// Clears store and processes scene only if necessary.
78
79
if
(kernelVisitWasNeeded) {
80
// Some systems, notably OpenGL, can draw while re-building, so
81
// there might not be a need to draw from store again here. But
82
// in this case...
83
DrawFromStore
(
"G4XXXSGViewer::DrawView"
);
84
}
else
{
85
DrawFromStore
(
"G4XXXSGViewer::DrawView"
);
86
}
87
88
// ...before finally...
89
FinishView
();
// Flush streams and/or swap buffers.
90
}
91
92
void
G4XXXSGViewer::ShowView
() {
93
//#ifdef G4XXXSGDEBUG
94
G4cout
<<
"G4XXXSGViewer::ShowView() called."
<<
G4endl
;
95
//#endif
96
// This is what you should see...
97
DrawFromStore
(
"G4XXXSGViewer::ShowView"
);
98
}
99
100
void
G4XXXSGViewer::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
SceneGraph
& sceneGraph =
106
static_cast<
G4XXXSGSceneHandler
&
>
(
fSceneHandler
).fSceneGraph;
107
if
(sceneGraph.
fDaughters
.size() == 3
// I.e., only the root nodes.
108
// (The above needs re-thinking.)
109
||
CompareForKernelVisit
(
fLastVP
)) {
110
NeedKernelVisit
();
// Sets fNeedKernelVisit.
111
}
112
fLastVP
=
fVP
;
113
}
114
115
G4bool
G4XXXSGViewer::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.
GetDefaultVisAttributes
()->
GetColour
() !=
132
fVP
.
GetDefaultVisAttributes
()->
GetColour
()) ||
133
(lastVP.
GetDefaultTextVisAttributes
()->
GetColour
() !=
134
fVP
.
GetDefaultTextVisAttributes
()->
GetColour
()) ||
135
(lastVP.
GetBackgroundColour
()!=
fVP
.
GetBackgroundColour
())||
136
(lastVP.
GetVisAttributesModifiers
().size() !=
137
fVP
.
GetVisAttributesModifiers
().size())
138
) {
139
return
true
;
140
}
141
142
if
(lastVP.
IsDensityCulling
() &&
143
(lastVP.
GetVisibleDensity
() !=
fVP
.
GetVisibleDensity
()))
144
return
true
;
145
146
if
(lastVP.
IsExplode
() &&
147
(lastVP.
GetExplodeFactor
() !=
fVP
.
GetExplodeFactor
()))
148
return
true
;
149
150
return
false
;
151
}
152
153
void
G4XXXSGViewer::DrawFromStore
(
const
G4String
& source) {
154
SceneGraph
& sceneGraph =
155
static_cast<
G4XXXSGSceneHandler
&
>
(
fSceneHandler
).fSceneGraph;
156
// Write to a file for testing...
157
static
G4int
iCount = 0;
158
std::ostringstream oss;
159
oss << source <<
'.'
<<
fName
<<
'.'
<< iCount++ <<
".out"
;
160
G4cout
<<
"Writing "
<< oss.str() <<
G4endl
;
161
std::ofstream ofs(oss.str().c_str());
162
JA::PrintTree
(ofs,&sceneGraph);
163
ofs.close();
164
}
Generated on Sat May 25 2013 14:34:19 for Geant4 by
1.8.4