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