source: trunk/source/visualization/management/src/G4Scene.cc @ 1346

Last change on this file since 1346 was 1346, checked in by garnier, 13 years ago

before tag

  • Property svn:mime-type set to text/cpp
File size: 7.7 KB
Line 
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,v 1.24 2009/11/04 12:49:16 allison Exp $
28// GEANT4 tag $Name:  $
29//
30//
31// Scene data  John Allison  19th July 1996.
32
33#include "G4Scene.hh"
34
35#include "G4Vector3D.hh"
36#include "G4BoundingSphereScene.hh"
37#include "G4VisAttributes.hh"
38#include "G4PhysicalVolumeModel.hh"
39#include "G4TransportationManager.hh"
40
41G4Scene::G4Scene (const G4String& name):
42  fName (name),
43  fRefreshAtEndOfEvent(true),
44  fRefreshAtEndOfRun(true),
45  fMaxNumberOfKeptEvents(0)
46{} // Note all other data members have default initial values.
47
48G4Scene::~G4Scene () {}
49
50G4bool G4Scene::AddRunDurationModel (G4VModel* pModel, G4bool warn) {
51  std::vector<G4VModel*>::const_iterator i;
52  for (i = fRunDurationModelList.begin ();
53       i != fRunDurationModelList.end (); ++i) {
54    if (pModel -> GetGlobalDescription () ==
55        (*i) -> GetGlobalDescription ()) break;
56  }
57  if (i != fRunDurationModelList.end ()) {
58    if (warn) {
59      G4cout << "G4Scene::AddRunDurationModel: model \""
60             << pModel -> GetGlobalDescription ()
61             << "\"\n  is already in the run-duration list of scene \""
62             << fName
63             << "\"."
64             << G4endl;
65    }
66    return false;
67  }
68  fRunDurationModelList.push_back (pModel);
69  CalculateExtent ();
70  return true;
71}
72
73void G4Scene::CalculateExtent () {
74  G4int nModels = fRunDurationModelList.size ();
75  G4BoundingSphereScene boundingSphereScene;
76  for (G4int i = 0; i < nModels; i++) {
77    const G4VisExtent& thisExtent =
78      fRunDurationModelList[i] -> GetExtent ();
79    G4Point3D thisCentre = thisExtent.GetExtentCentre ();
80    G4double thisRadius = thisExtent.GetExtentRadius ();
81    thisCentre.transform (fRunDurationModelList[i] -> GetTransformation ());
82    boundingSphereScene.AccrueBoundingSphere (thisCentre, thisRadius);
83  }
84  fExtent = boundingSphereScene.GetBoundingSphereExtent ();
85  fStandardTargetPoint = fExtent.GetExtentCentre ();
86}
87
88G4bool G4Scene::AddWorldIfEmpty (G4bool warn) {
89  G4bool successful = true;
90  if (IsEmpty ()) {
91    successful = false;
92    G4VPhysicalVolume* pWorld =
93      G4TransportationManager::GetTransportationManager ()
94      -> GetNavigatorForTracking () -> GetWorldVolume ();
95    if (pWorld) {
96      const G4VisAttributes* pVisAttribs =
97        pWorld -> GetLogicalVolume () -> GetVisAttributes ();
98      if (!pVisAttribs || pVisAttribs -> IsVisible ()) {
99        if (warn) {
100          G4cout <<
101            "Your \"world\" has no vis attributes or is marked as visible."
102            "\n  For a better view of the contents, mark the world as"
103            " invisible, e.g.,"
104            "\n  myWorldLogicalVol ->"
105            " SetVisAttributes (G4VisAttributes::Invisible);"
106                 << G4endl;
107        }
108      }
109      successful = AddRunDurationModel (new G4PhysicalVolumeModel (pWorld));
110      // Note: default depth and no modeling parameters.
111      if (successful) {
112        if (warn) {
113          G4cout <<
114    "G4Scene::AddWorldIfEmpty: The scene was empty of run-duration models."
115    "\n  \"world\" has been added.";
116          G4cout << G4endl;
117        }
118      }
119    }
120  }
121  return successful;
122}
123
124G4bool G4Scene::AddEndOfEventModel (G4VModel* pModel, G4bool warn) {
125  G4int i, nModels = fEndOfEventModelList.size ();
126  for (i = 0; i < nModels; i++) {
127    if (pModel -> GetGlobalDescription () ==
128        fEndOfEventModelList [i] -> GetGlobalDescription ()) break;
129  }
130  if (i < nModels) {
131    delete fEndOfEventModelList[i];
132    fEndOfEventModelList[i] = pModel;
133    if (warn) {
134      G4cout << "G4Scene::AddEndOfEventModel: a model \""
135             << pModel -> GetGlobalDescription ()
136             << "\"\n  is already in the end-of-event list of scene \""
137             << fName <<
138        "\".\n  The old model has been deleted; this new model replaces it."
139             << G4endl;
140    }
141    return true;  // Model replaced sucessfully.
142  }
143  fEndOfEventModelList.push_back (pModel);
144  return true;
145}
146
147G4bool G4Scene::AddEndOfRunModel (G4VModel* pModel, G4bool warn) {
148  G4int i, nModels = fEndOfRunModelList.size ();
149  for (i = 0; i < nModels; i++) {
150    if (pModel -> GetGlobalDescription () ==
151        fEndOfRunModelList [i] -> GetGlobalDescription ()) break;
152  }
153  if (i < nModels) {
154    delete fEndOfRunModelList[i];
155    fEndOfRunModelList[i] = pModel;
156    if (warn) {
157      G4cout << "G4Scene::AddEndOfRunModel: a model \""
158             << pModel -> GetGlobalDescription ()
159             << "\"\n  is already in the end-of-run list of scene \""
160             << fName <<
161        "\".\n  The old model has been deleted; this new model replaces it."
162             << G4endl;
163    }
164    return true;  // Model replaced sucessfully.
165  }
166  fEndOfRunModelList.push_back (pModel);
167  return true;
168}
169
170std::ostream& operator << (std::ostream& os, const G4Scene& s) {
171
172  size_t i;
173
174  os << "Scene data:";
175
176  os << "\n  Run-duration model list:";
177  for (i = 0; i < s.fRunDurationModelList.size (); i++) {
178    os << "\n  " << *(s.fRunDurationModelList[i]);
179  }
180
181  os << "\n  End-of-event model list:";
182  for (i = 0; i < s.fEndOfEventModelList.size (); i++) {
183    os << "\n  " << *(s.fEndOfEventModelList[i]);
184  }
185
186  os << "\n  End-of-run model list:";
187  for (i = 0; i < s.fEndOfRunModelList.size (); i++) {
188    os << "\n  " << *(s.fEndOfRunModelList[i]);
189  }
190
191  os << "\n  Extent or bounding box: " << s.fExtent;
192
193  os << "\n  Standard target point:  " << s.fStandardTargetPoint;
194
195  os << "\n  End of event action set to \"";
196  if (s.fRefreshAtEndOfEvent) os << "refresh\"";
197  else {
198    os << "accumulate (maximum number of kept events: ";
199    if (s.fMaxNumberOfKeptEvents >= 0) os << s.fMaxNumberOfKeptEvents;
200    else os << "unlimited";
201    os << ")";
202  }
203
204  os << "\n  End of run action set to \"";
205  if (s.fRefreshAtEndOfRun) os << "refresh";
206  else os << "accumulate";
207  os << "\"";
208
209  return os;
210}
211
212G4bool G4Scene::operator != (const G4Scene& s) const {
213  if (
214      (fRunDurationModelList.size () !=
215       s.fRunDurationModelList.size ())                 ||
216      (fExtent               != s.fExtent)              ||
217      !(fStandardTargetPoint == s.fStandardTargetPoint) ||
218      fRefreshAtEndOfEvent   != s.fRefreshAtEndOfEvent  ||
219      fRefreshAtEndOfRun     != s.fRefreshAtEndOfRun    ||
220      fMaxNumberOfKeptEvents != s.fMaxNumberOfKeptEvents
221      ) return true;
222
223  for (size_t i = 0; i < fRunDurationModelList.size (); i++) {
224    if (fRunDurationModelList[i] != s.fRunDurationModelList[i])
225      return true;
226  }
227
228  return false;
229}
Note: See TracBrowser for help on using the repository browser.