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