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

Last change on this file since 954 was 954, checked in by garnier, 15 years ago

remise a jour

  • Property svn:mime-type set to text/cpp
File size: 6.8 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.23 2006/11/26 15:51:12 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
147std::ostream& operator << (std::ostream& os, const G4Scene& s) {
148
149  size_t i;
150
151  os << "Scene data:";
152
153  os << "\n  Run-duration model list:";
154  for (i = 0; i < s.fRunDurationModelList.size (); i++) {
155    os << "\n  " << *(s.fRunDurationModelList[i]);
156  }
157
158  os << "\n  End-of-event model list:";
159  for (i = 0; i < s.fEndOfEventModelList.size (); i++) {
160    os << "\n  " << *(s.fEndOfEventModelList[i]);
161  }
162
163  os << "\n  Extent or bounding box: " << s.fExtent;
164
165  os << "\n  Standard target point:  " << s.fStandardTargetPoint;
166
167  os << "\n  End of event action set to \"";
168  if (s.fRefreshAtEndOfEvent) os << "refresh\"";
169  else {
170    os << "accumulate (maximum number of kept events: ";
171    if (s.fMaxNumberOfKeptEvents >= 0) os << s.fMaxNumberOfKeptEvents;
172    else os << "unlimited";
173    os << ")";
174  }
175
176  os << "\n  End of run action set to \"";
177  if (s.fRefreshAtEndOfRun) os << "refresh";
178  else os << "accumulate";
179  os << "\"";
180
181  return os;
182}
183
184G4bool G4Scene::operator != (const G4Scene& s) const {
185  if (
186      (fRunDurationModelList.size () !=
187       s.fRunDurationModelList.size ())                 ||
188      (fExtent               != s.fExtent)              ||
189      !(fStandardTargetPoint == s.fStandardTargetPoint) ||
190      fRefreshAtEndOfEvent   != s.fRefreshAtEndOfEvent  ||
191      fRefreshAtEndOfRun     != s.fRefreshAtEndOfRun    ||
192      fMaxNumberOfKeptEvents != s.fMaxNumberOfKeptEvents
193      ) return true;
194
195  for (size_t i = 0; i < fRunDurationModelList.size (); i++) {
196    if (fRunDurationModelList[i] != s.fRunDurationModelList[i])
197      return true;
198  }
199
200  return false;
201}
Note: See TracBrowser for help on using the repository browser.