ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4Scene.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4Scene.cc
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"
34 #include "G4BoundingExtentScene.hh"
35 #include "G4VisAttributes.hh"
36 #include "G4PhysicalVolumeModel.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 
92  CalculateExtent ();
93 
94  return true;
95 }
96 
97 namespace {
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  boundingExtentScene.AccrueBoundingExtent(thisExtent);
119  } else {
120  PrintInvalidModel(model);
121  }
122  }
123  }
124 
125  for (size_t i = 0; i < fEndOfEventModelList.size(); i++) {
126  if (fEndOfEventModelList[i].fActive) {
127  G4VModel* model = fEndOfEventModelList[i].fpModel;
128  if (model -> Validate()) { // Validates and also recomputes extent.
129  const G4VisExtent& thisExtent = model -> GetTransformedExtent ();
130  boundingExtentScene.AccrueBoundingExtent(thisExtent);
131  } else {
132  PrintInvalidModel(model);
133  }
134  }
135  }
136 
137  for (size_t i = 0; i < fEndOfRunModelList.size(); i++) {
138  if (fEndOfRunModelList[i].fActive) {
139  G4VModel* model = fEndOfRunModelList[i].fpModel;
140  if (model -> Validate()) { // Validates and also recomputes extent.
141  const G4VisExtent& thisExtent = model -> GetTransformedExtent ();
142  boundingExtentScene.AccrueBoundingExtent(thisExtent);
143  } else {
144  PrintInvalidModel(model);
145  }
146  }
147  }
148 
149  fExtent = boundingExtentScene.GetBoundingExtent ();
151  if (fExtent.GetExtentRadius() <= 0.) {
153  ("G4Scene::CalculateExtent",
154  "visman0202", JustWarning,
155  "Scene has no extent. Please activate or add something."
156  "\nThe camera needs to have something to point at!"
157  "\nAdd a volume. (You may need \"/run/initialize\".)"
158  "\nOr use \"/vis/scene/add/extent\"."
159  "\n\"/vis/scene/list\" to see list of models.");
160  }
161 }
162 
164  G4bool successful = true;
165  if (IsEmpty ()) {
166  successful = false;
167  G4VPhysicalVolume* pWorld =
169  -> GetNavigatorForTracking () -> GetWorldVolume ();
170  if (pWorld) {
171  const G4VisAttributes* pVisAttribs =
172  pWorld -> GetLogicalVolume () -> GetVisAttributes ();
173  if (!pVisAttribs || pVisAttribs -> IsVisible ()) {
174  if (warn) {
175  G4cout <<
176  "Your \"world\" has no vis attributes or is marked as visible."
177  "\n For a better view of the contents, mark the world as"
178  " invisible, e.g.,"
179  "\n myWorldLogicalVol ->"
180  " SetVisAttributes (G4VisAttributes::GetInvisible());"
181  << G4endl;
182  }
183  }
184  successful = AddRunDurationModel (new G4PhysicalVolumeModel (pWorld));
185  // Note: default depth and no modeling parameters.
186  if (successful) {
187  if (warn) {
188  G4cout <<
189  "G4Scene::AddWorldIfEmpty: The scene was empty of run-duration models."
190  "\n \"world\" has been added.";
191  G4cout << G4endl;
192  }
193  }
194  }
195  }
196  return successful;
197 }
198 
200  G4int i, nModels = fEndOfEventModelList.size ();
201  for (i = 0; i < nModels; i++) {
202  if (pModel -> GetGlobalDescription () ==
203  fEndOfEventModelList[i].fpModel -> GetGlobalDescription ()) break;
204  }
205  if (i < nModels) {
206  if (warn) {
207  G4cout << "G4Scene::AddEndOfEventModel: a model \""
208  << pModel -> GetGlobalDescription ()
209  << "\"\n is already in the end-of-event list of scene \""
210  << fName << "\"."
211  << G4endl;
212  }
213  return false;
214  }
215  fEndOfEventModelList.push_back (Model(pModel));
216  return true;
217 }
218 
220  G4int i, nModels = fEndOfRunModelList.size ();
221  for (i = 0; i < nModels; i++) {
222  if (pModel -> GetGlobalDescription () ==
223  fEndOfRunModelList[i].fpModel -> GetGlobalDescription ()) break;
224  }
225  if (i < nModels) {
226  if (warn) {
227  G4cout << "G4Scene::AddEndOfRunModel: a model \""
228  << pModel -> GetGlobalDescription ()
229  << "\"\n is already in the end-of-run list of scene \""
230  << fName << "\"."
231  << G4endl;
232  }
233  return false;
234  }
235  fEndOfRunModelList.push_back (pModel);
236  return true;
237 }
238 
239 std::ostream& operator << (std::ostream& os, const G4Scene& scene) {
240 
241  size_t i;
242 
243  os << "Scene data:";
244 
245  os << "\n Run-duration model list:";
246  if (scene.fRunDurationModelList.size () == 0) {
247  os << " none";
248  }
249  for (i = 0; i < scene.fRunDurationModelList.size (); i++) {
250  if (scene.fRunDurationModelList[i].fActive) os << "\n Active: ";
251  else os << "\n Inactive: ";
252  os << *(scene.fRunDurationModelList[i].fpModel);
253  }
254 
255  os << "\n End-of-event model list:";
256  if (scene.fEndOfEventModelList.size () == 0) {
257  os << " none";
258  }
259  for (i = 0; i < scene.fEndOfEventModelList.size (); i++) {
260  if (scene.fEndOfEventModelList[i].fActive) os << "\n Active: ";
261  else os << "\n Inactive: ";
262  os << *(scene.fEndOfEventModelList[i].fpModel);
263  }
264 
265  os << "\n End-of-run model list:";
266  if (scene.fEndOfRunModelList.size () == 0) {
267  os << " none";
268  }
269  for (i = 0; i < scene.fEndOfRunModelList.size (); i++) {
270  if (scene.fEndOfRunModelList[i].fActive) os << "\n Active: ";
271  else os << "\n Inactive: ";
272  os << *(scene.fEndOfRunModelList[i].fpModel);
273  }
274 
275  os << "\n Overall extent or bounding box: " << scene.fExtent;
276 
277  os << "\n Standard target point: " << scene.fStandardTargetPoint;
278 
279  os << "\n End of event action set to \"";
280  if (scene.fRefreshAtEndOfEvent) os << "refresh\"";
281  else {
282  os << "accumulate (maximum number of kept events: ";
283  if (scene.fMaxNumberOfKeptEvents >= 0) os << scene.fMaxNumberOfKeptEvents;
284  else os << "unlimited";
285  os << ")";
286  }
287 
288  os << "\n End of run action set to \"";
289  if (scene.fRefreshAtEndOfRun) os << "refresh";
290  else os << "accumulate";
291  os << "\"";
292 
293  return os;
294 }
295 
296 G4bool G4Scene::operator != (const G4Scene& scene) const {
297  if (
298  (fRunDurationModelList.size () !=
299  scene.fRunDurationModelList.size ()) ||
300  (fEndOfEventModelList.size () !=
301  scene.fEndOfEventModelList.size ()) ||
302  (fEndOfRunModelList.size () !=
303  scene.fEndOfRunModelList.size ()) ||
304  (fExtent != scene.fExtent) ||
309  ) return true;
310 
311  /* A complete comparison should, perhaps, include a comparison of
312  individual models, but it is not easy to implement operator!= for
313  all models. Also, it would be unfeasible to ask users to
314  implement opeerator!= if we ever get round to allowing
315  user-defined models. Moreover, there is no editing of G4Scene
316  objects, apart from changing fRefreshAtEndOfEvent, etc; as far as
317  models are concerned, all you can ever do is add them, so a test
318  on size (above) is enough.
319 
320  for (size_t i = 0; i < fRunDurationModelList.size (); i++) {
321  if (fRunDurationModelList[i] != scene.fRunDurationModelList[i])
322  return true;
323  }
324 
325  for (size_t i = 0; i < fEndOfEventModelList.size (); i++) {
326  if (fEndOfEventModelList[i] != scene.fEndOfEventModelList[i])
327  return true;
328  }
329 
330  for (size_t i = 0; i < fEndOfRunModelList.size (); i++) {
331  if (fEndOfRunModelList[i] != scene.fEndOfRunModelList[i])
332  return true;
333  }
334  */
335 
336  return false;
337 }