source: trunk/source/visualization/management/src/G4Scene.cc@ 1168

Last change on this file since 1168 was 1136, checked in by garnier, 16 years ago

debug updates

  • Property svn:mime-type set to text/cpp
File size: 7.2 KB
Line 
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: G4Scene.cc,v 1.23 2006/11/26 15:51:12 allison Exp $
28// GEANT4 tag $Name: $
29//
30//
31// Scene data John Allison 19th July 1996.
32
33#include "G4Scene.hh"
34
35#include "G4Vector3D.hh"
36#include "G4BoundingSphereScene.hh"
37#include "G4VisAttributes.hh"
38#include "G4PhysicalVolumeModel.hh"
39#include "G4TransportationManager.hh"
40
41G4Scene::G4Scene (const G4String& name):
42 fName (name),
43 fRefreshAtEndOfEvent(true),
44 fRefreshAtEndOfRun(true),
45 fMaxNumberOfKeptEvents(0)
46{} // Note all other data members have default initial values.
47
48G4Scene::~G4Scene () {}
49
50G4bool G4Scene::AddRunDurationModel (G4VModel* pModel, G4bool warn) {
51 std::vector<G4VModel*>::const_iterator i;
52#ifdef G4DEBUG_VIS_MANAGEMENT
53 printf("G4Scene::AddRunDurationModel\n");
54#endif
55 for (i = fRunDurationModelList.begin ();
56 i != fRunDurationModelList.end (); ++i) {
57 if (pModel -> GetGlobalDescription () ==
58 (*i) -> GetGlobalDescription ()) break;
59 }
60 if (i != fRunDurationModelList.end ()) {
61#ifdef G4DEBUG_VIS_MANAGEMENT
62 printf("G4Scene::AddRunDurationModel i != fRunDurationModelList.end ()\n");
63#endif
64 if (warn) {
65 G4cout << "G4Scene::AddRunDurationModel: model \""
66 << pModel -> GetGlobalDescription ()
67 << "\"\n is already in the run-duration list of scene \""
68 << fName
69 << "\"."
70 << G4endl;
71 }
72 return false;
73 }
74 fRunDurationModelList.push_back (pModel);
75 CalculateExtent ();
76 return true;
77}
78
79void G4Scene::CalculateExtent () {
80#ifdef G4DEBUG_VIS_MANAGEMENT
81 printf("G4Scene::CalculateExtent\n");
82#endif
83 G4int nModels = fRunDurationModelList.size ();
84 G4BoundingSphereScene boundingSphereScene;
85 for (G4int i = 0; i < nModels; i++) {
86 const G4VisExtent& thisExtent =
87 fRunDurationModelList[i] -> GetExtent ();
88 G4Point3D thisCentre = thisExtent.GetExtentCentre ();
89 G4double thisRadius = thisExtent.GetExtentRadius ();
90 thisCentre.transform (fRunDurationModelList[i] -> GetTransformation ());
91 boundingSphereScene.AccrueBoundingSphere (thisCentre, thisRadius);
92 }
93 fExtent = boundingSphereScene.GetBoundingSphereExtent ();
94 fStandardTargetPoint = fExtent.GetExtentCentre ();
95#ifdef G4DEBUG_VIS_MANAGEMENT
96 printf("G4Scene::CalculateExtent END\n");
97#endif
98}
99
100G4bool G4Scene::AddWorldIfEmpty (G4bool warn) {
101 G4bool successful = true;
102 if (IsEmpty ()) {
103 successful = false;
104 G4VPhysicalVolume* pWorld =
105 G4TransportationManager::GetTransportationManager ()
106 -> GetNavigatorForTracking () -> GetWorldVolume ();
107 if (pWorld) {
108 const G4VisAttributes* pVisAttribs =
109 pWorld -> GetLogicalVolume () -> GetVisAttributes ();
110 if (!pVisAttribs || pVisAttribs -> IsVisible ()) {
111 if (warn) {
112 G4cout <<
113 "Your \"world\" has no vis attributes or is marked as visible."
114 "\n For a better view of the contents, mark the world as"
115 " invisible, e.g.,"
116 "\n myWorldLogicalVol ->"
117 " SetVisAttributes (G4VisAttributes::Invisible);"
118 << G4endl;
119 }
120 }
121 successful = AddRunDurationModel (new G4PhysicalVolumeModel (pWorld));
122 // Note: default depth and no modeling parameters.
123 if (successful) {
124 if (warn) {
125 G4cout <<
126 "G4Scene::AddWorldIfEmpty: The scene was empty of run-duration models."
127 "\n \"world\" has been added.";
128 G4cout << G4endl;
129 }
130 }
131 }
132 }
133 return successful;
134}
135
136G4bool G4Scene::AddEndOfEventModel (G4VModel* pModel, G4bool warn) {
137 G4int i, nModels = fEndOfEventModelList.size ();
138 for (i = 0; i < nModels; i++) {
139 if (pModel -> GetGlobalDescription () ==
140 fEndOfEventModelList [i] -> GetGlobalDescription ()) break;
141 }
142 if (i < nModels) {
143 delete fEndOfEventModelList[i];
144 fEndOfEventModelList[i] = pModel;
145 if (warn) {
146 G4cout << "G4Scene::AddEndOfEventModel: a model \""
147 << pModel -> GetGlobalDescription ()
148 << "\"\n is already in the end-of-event list of scene \""
149 << fName <<
150 "\".\n The old model has been deleted; this new model replaces it."
151 << G4endl;
152 }
153 return true; // Model replaced sucessfully.
154 }
155 fEndOfEventModelList.push_back (pModel);
156 return true;
157}
158
159std::ostream& operator << (std::ostream& os, const G4Scene& s) {
160
161 size_t i;
162
163 os << "Scene data:";
164
165 os << "\n Run-duration model list:";
166 for (i = 0; i < s.fRunDurationModelList.size (); i++) {
167 os << "\n " << *(s.fRunDurationModelList[i]);
168 }
169
170 os << "\n End-of-event model list:";
171 for (i = 0; i < s.fEndOfEventModelList.size (); i++) {
172 os << "\n " << *(s.fEndOfEventModelList[i]);
173 }
174
175 os << "\n Extent or bounding box: " << s.fExtent;
176
177 os << "\n Standard target point: " << s.fStandardTargetPoint;
178
179 os << "\n End of event action set to \"";
180 if (s.fRefreshAtEndOfEvent) os << "refresh\"";
181 else {
182 os << "accumulate (maximum number of kept events: ";
183 if (s.fMaxNumberOfKeptEvents >= 0) os << s.fMaxNumberOfKeptEvents;
184 else os << "unlimited";
185 os << ")";
186 }
187
188 os << "\n End of run action set to \"";
189 if (s.fRefreshAtEndOfRun) os << "refresh";
190 else os << "accumulate";
191 os << "\"";
192
193 return os;
194}
195
196G4bool G4Scene::operator != (const G4Scene& s) const {
197 if (
198 (fRunDurationModelList.size () !=
199 s.fRunDurationModelList.size ()) ||
200 (fExtent != s.fExtent) ||
201 !(fStandardTargetPoint == s.fStandardTargetPoint) ||
202 fRefreshAtEndOfEvent != s.fRefreshAtEndOfEvent ||
203 fRefreshAtEndOfRun != s.fRefreshAtEndOfRun ||
204 fMaxNumberOfKeptEvents != s.fMaxNumberOfKeptEvents
205 ) return true;
206
207 for (size_t i = 0; i < fRunDurationModelList.size (); i++) {
208 if (fRunDurationModelList[i] != s.fRunDurationModelList[i])
209 return true;
210 }
211
212 return false;
213}
Note: See TracBrowser for help on using the repository browser.