Geant4-11
G4Scene.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//
28//
29// Scene data John Allison 19th July 1996.
30
31#include "G4Scene.hh"
32
33#include "G4Vector3D.hh"
35#include "G4VisAttributes.hh"
38
39#include <set>
40
42 fName (name),
43 fRefreshAtEndOfEvent(true),
44 fRefreshAtEndOfRun(true),
45 fMaxNumberOfKeptEvents(100)
46{} // Note all other data members have default initial values.
47
49
50namespace {
51 void PrintInvalidModel(const G4VModel* model)
52 {
54 ed << "Invalid model \"" << model->GetGlobalDescription()
55 << "\".\n Not included in extent calculation.";
57 ("G4Scene::CalculateExtent",
58 "visman0201", JustWarning, ed);
59 }
60}
61
63{
64 G4BoundingExtentScene boundingExtentScene;
65
66 for (size_t i = 0; i < fRunDurationModelList.size(); i++) {
67 if (fRunDurationModelList[i].fActive) {
68 G4VModel* model = fRunDurationModelList[i].fpModel;
69 if (model -> Validate()) {
70 const G4VisExtent& thisExtent = model -> GetExtent ();
71 if (thisExtent != G4VisExtent::GetNullExtent()) {
72 boundingExtentScene.AccrueBoundingExtent(thisExtent);
73 }
74 } else {
75 PrintInvalidModel(model);
76 }
77 }
78 }
79
80 for (size_t i = 0; i < fEndOfEventModelList.size(); i++) {
81 if (fEndOfEventModelList[i].fActive) {
82 G4VModel* model = fEndOfEventModelList[i].fpModel;
83 if (model -> Validate()) {
84 const G4VisExtent& thisExtent = model -> GetExtent ();
85 if (thisExtent != G4VisExtent::GetNullExtent()) {
86 boundingExtentScene.AccrueBoundingExtent(thisExtent);
87 }
88 } else {
89 PrintInvalidModel(model);
90 }
91 }
92 }
93
94 for (size_t i = 0; i < fEndOfRunModelList.size(); i++) {
95 if (fEndOfRunModelList[i].fActive) {
96 G4VModel* model = fEndOfRunModelList[i].fpModel;
97 if (model -> Validate()) {
98 const G4VisExtent& thisExtent = model -> GetExtent ();
99 if (thisExtent != G4VisExtent::GetNullExtent()) {
100 boundingExtentScene.AccrueBoundingExtent(thisExtent);
101 }
102 } else {
103 PrintInvalidModel(model);
104 }
105 }
106 }
107
108 fExtent = boundingExtentScene.GetBoundingExtent ();
110 if (fExtent.GetExtentRadius() <= 0.) {
112 ("G4Scene::CalculateExtent",
113 "visman0202", JustWarning,
114 "Scene has no extent. Please activate or add something."
115 "\nThe camera needs to have something to point at!"
116 "\nAdd a volume. (You may need \"/run/initialize\".)"
117 "\nOr use \"/vis/scene/add/extent\"."
118 "\n\"/vis/scene/list\" to see list of models.");
119 }
120}
121
123 G4bool successful = true;
124 if (IsEmpty ()) {
125 successful = false;
126 G4VPhysicalVolume* pWorld =
128 -> GetNavigatorForTracking () -> GetWorldVolume ();
129 if (pWorld) {
130 const G4VisAttributes* pVisAttribs =
131 pWorld -> GetLogicalVolume () -> GetVisAttributes ();
132 if (!pVisAttribs || pVisAttribs -> IsVisible ()) {
133 if (warn) {
134 G4cout <<
135 "Your \"world\" has no vis attributes or is marked as visible."
136 "\n For a better view of the contents, mark the world as"
137 " invisible, e.g.,"
138 "\n myWorldLogicalVol ->"
139 " SetVisAttributes (G4VisAttributes::GetInvisible());"
140 << G4endl;
141 }
142 }
143 successful = AddRunDurationModel (new G4PhysicalVolumeModel (pWorld));
144 // Note: default depth and no modeling parameters.
145 if (successful) {
146 if (warn) {
147 G4cout <<
148 "G4Scene::AddWorldIfEmpty: The scene was empty of run-duration models."
149 "\n \"world\" has been added.";
150 G4cout << G4endl;
151 }
152 }
153 }
154 }
155 return successful;
156}
157
159{
160 std::vector<Model>::const_iterator i;
161 for (i = fRunDurationModelList.begin ();
162 i != fRunDurationModelList.end (); ++i) {
163 if (pModel -> GetGlobalDescription () ==
164 i->fpModel->GetGlobalDescription ()) break;
165 }
166 if (i != fRunDurationModelList.end ()) {
167 if (warn) {
168 G4cout << "G4Scene::AddRunDurationModel: model \""
169 << pModel -> GetGlobalDescription ()
170 << "\"\n is already in the run-duration list of scene \""
171 << fName
172 << "\"."
173 << G4endl;
174 }
175 return false;
176 }
177 fRunDurationModelList.push_back (Model(pModel));
179 return true;
180}
181
183 G4int i, nModels = fEndOfEventModelList.size ();
184 for (i = 0; i < nModels; i++) {
185 if (pModel -> GetGlobalDescription () ==
186 fEndOfEventModelList[i].fpModel -> GetGlobalDescription ()) break;
187 }
188 if (i < nModels) {
189 if (warn) {
190 G4cout << "G4Scene::AddEndOfEventModel: a model \""
191 << pModel -> GetGlobalDescription ()
192 << "\"\n is already in the end-of-event list of scene \""
193 << fName << "\"."
194 << G4endl;
195 }
196 return false;
197 }
198 fEndOfEventModelList.push_back (Model(pModel));
199 return true;
200}
201
203 G4int i, nModels = fEndOfRunModelList.size ();
204 for (i = 0; i < nModels; i++) {
205 if (pModel -> GetGlobalDescription () ==
206 fEndOfRunModelList[i].fpModel -> GetGlobalDescription ()) break;
207 }
208 if (i < nModels) {
209 if (warn) {
210 G4cout << "G4Scene::AddEndOfRunModel: a model \""
211 << pModel -> GetGlobalDescription ()
212 << "\"\n is already in the end-of-run list of scene \""
213 << fName << "\"."
214 << G4endl;
215 }
216 return false;
217 }
218 fEndOfRunModelList.push_back (pModel);
219 return true;
220}
221
222std::ostream& operator << (std::ostream& os, const G4Scene& scene) {
223
224 size_t i;
225
226 os << "Scene data:";
227
228 os << "\n Run-duration model list:";
229 if (scene.fRunDurationModelList.size () == 0) {
230 os << " none";
231 }
232 for (i = 0; i < scene.fRunDurationModelList.size (); i++) {
233 if (scene.fRunDurationModelList[i].fActive) os << "\n Active: ";
234 else os << "\n Inactive: ";
235 os << *(scene.fRunDurationModelList[i].fpModel);
236 }
237
238 os << "\n End-of-event model list:";
239 if (scene.fEndOfEventModelList.size () == 0) {
240 os << " none";
241 }
242 for (i = 0; i < scene.fEndOfEventModelList.size (); i++) {
243 if (scene.fEndOfEventModelList[i].fActive) os << "\n Active: ";
244 else os << "\n Inactive: ";
245 os << *(scene.fEndOfEventModelList[i].fpModel);
246 }
247
248 os << "\n End-of-run model list:";
249 if (scene.fEndOfRunModelList.size () == 0) {
250 os << " none";
251 }
252 for (i = 0; i < scene.fEndOfRunModelList.size (); i++) {
253 if (scene.fEndOfRunModelList[i].fActive) os << "\n Active: ";
254 else os << "\n Inactive: ";
255 os << *(scene.fEndOfRunModelList[i].fpModel);
256 }
257
258 os << "\n Overall extent or bounding box: " << scene.fExtent;
259
260 os << "\n Standard target point: " << scene.fStandardTargetPoint;
261
262 os << "\n End of event action set to \"";
263 if (scene.fRefreshAtEndOfEvent) os << "refresh\"";
264 else {
265 os << "accumulate (maximum number of kept events: ";
266 if (scene.fMaxNumberOfKeptEvents >= 0) os << scene.fMaxNumberOfKeptEvents;
267 else os << "unlimited";
268 os << ")";
269 }
270
271 os << "\n End of run action set to \"";
272 if (scene.fRefreshAtEndOfRun) os << "refresh";
273 else os << "accumulate";
274 os << "\"";
275
276 return os;
277}
278
280 if (
281 (fRunDurationModelList.size () !=
282 scene.fRunDurationModelList.size ()) ||
283 (fEndOfEventModelList.size () !=
284 scene.fEndOfEventModelList.size ()) ||
285 (fEndOfRunModelList.size () !=
286 scene.fEndOfRunModelList.size ()) ||
287 (fExtent != scene.fExtent) ||
292 ) return true;
293
294 /* A complete comparison should, perhaps, include a comparison of
295 individual models, but it is not easy to implement operator!= for
296 all models. Also, it would be unfeasible to ask users to
297 implement opeerator!= if we ever get round to allowing
298 user-defined models. Moreover, there is no editing of G4Scene
299 objects, apart from changing fRefreshAtEndOfEvent, etc; as far as
300 models are concerned, all you can ever do is add them, so a test
301 on size (above) is enough.
302
303 for (size_t i = 0; i < fRunDurationModelList.size (); i++) {
304 if (fRunDurationModelList[i] != scene.fRunDurationModelList[i])
305 return true;
306 }
307
308 for (size_t i = 0; i < fEndOfEventModelList.size (); i++) {
309 if (fEndOfEventModelList[i] != scene.fEndOfEventModelList[i])
310 return true;
311 }
312
313 for (size_t i = 0; i < fEndOfRunModelList.size (); i++) {
314 if (fEndOfRunModelList[i] != scene.fEndOfRunModelList[i])
315 return true;
316 }
317 */
318
319 return false;
320}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
void AccrueBoundingExtent(const G4VisExtent &)
const G4VisExtent & GetBoundingExtent() const
std::vector< Model > fEndOfEventModelList
Definition: G4Scene.hh:179
void CalculateExtent()
Definition: G4Scene.cc:62
G4bool AddRunDurationModel(G4VModel *, G4bool warn=false)
Definition: G4Scene.cc:158
G4bool AddWorldIfEmpty(G4bool warn=false)
Definition: G4Scene.cc:122
std::vector< Model > fEndOfRunModelList
Definition: G4Scene.hh:180
G4int fMaxNumberOfKeptEvents
Definition: G4Scene.hh:185
std::vector< Model > fRunDurationModelList
Definition: G4Scene.hh:178
G4bool fRefreshAtEndOfRun
Definition: G4Scene.hh:184
const G4VisExtent & GetExtent() const
G4String fName
Definition: G4Scene.hh:177
G4bool operator!=(const G4Scene &) const
Definition: G4Scene.cc:279
G4bool AddEndOfRunModel(G4VModel *, G4bool warn=false)
Definition: G4Scene.cc:202
G4Scene(const G4String &name="scene-with-unspecified-name")
Definition: G4Scene.cc:41
G4Point3D fStandardTargetPoint
Definition: G4Scene.hh:182
G4VisExtent fExtent
Definition: G4Scene.hh:181
~G4Scene()
Definition: G4Scene.cc:48
G4bool fRefreshAtEndOfEvent
Definition: G4Scene.hh:183
G4bool AddEndOfEventModel(G4VModel *, G4bool warn=false)
Definition: G4Scene.cc:182
G4bool IsEmpty() const
static G4TransportationManager * GetTransportationManager()
const G4String & GetGlobalDescription() const
static const G4VisExtent & GetNullExtent()
Definition: G4VisExtent.cc:60
G4double GetExtentRadius() const
Definition: G4VisExtent.cc:75
const G4Point3D & GetExtentCentre() const
Definition: G4VisExtent.cc:65
std::ostream & operator<<(std::ostream &, const BasicVector3D< float > &)
const char * name(G4int ptype)
void PrintInvalidModel(const G4VModel *model)
Definition: G4Scene.cc:51