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