Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4Scene Class Reference

#include <G4Scene.hh>

Classes

struct  Model
 

Public Types

enum  { UNLIMITED = -1 }
 

Public Member Functions

 G4Scene (const G4String &name="scene-with-unspecified-name")
 
 ~G4Scene ()
 
G4bool operator== (const G4Scene &) const
 
G4bool operator!= (const G4Scene &) const
 
const G4StringGetName () const
 
G4bool IsEmpty () const
 
const std::vector< Model > & GetRunDurationModelList () const
 
const std::vector< Model > & GetEndOfEventModelList () const
 
const std::vector< Model > & GetEndOfRunModelList () const
 
const G4VisExtentGetExtent () const
 
const G4Point3DGetStandardTargetPoint () const
 
G4bool GetRefreshAtEndOfEvent () const
 
G4int GetMaxNumberOfKeptEvents () const
 
G4bool GetRefreshAtEndOfRun () const
 
G4bool AddRunDurationModel (G4VModel *, G4bool warn=false)
 
G4bool AddWorldIfEmpty (G4bool warn=false)
 
G4bool AddEndOfEventModel (G4VModel *, G4bool warn=false)
 
G4bool AddEndOfRunModel (G4VModel *, G4bool warn=false)
 
void SetName (const G4String &)
 
std::vector< Model > & SetRunDurationModelList ()
 
std::vector< Model > & SetEndOfEventModelList ()
 
std::vector< Model > & SetEndOfRunModelList ()
 
void SetRefreshAtEndOfEvent (G4bool)
 
void SetMaxNumberOfKeptEvents (G4int)
 
void SetRefreshAtEndOfRun (G4bool)
 
void CalculateExtent ()
 

Friends

std::ostream & operator<< (std::ostream &os, const G4Scene &d)
 

Detailed Description

Definition at line 48 of file G4Scene.hh.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
UNLIMITED 

Definition at line 54 of file G4Scene.hh.

54{UNLIMITED = -1};
@ UNLIMITED
Definition: G4Scene.hh:54

Constructor & Destructor Documentation

◆ G4Scene()

G4Scene::G4Scene ( const G4String name = "scene-with-unspecified-name")

Definition at line 41 of file G4Scene.cc.

41 :
42 fName (name),
43 fRefreshAtEndOfEvent(true),
44 fRefreshAtEndOfRun(true),
45 fMaxNumberOfKeptEvents(100)
46{} // Note all other data members have default initial values.

◆ ~G4Scene()

G4Scene::~G4Scene ( )

Definition at line 48 of file G4Scene.cc.

48{}

Member Function Documentation

◆ AddEndOfEventModel()

G4bool G4Scene::AddEndOfEventModel ( G4VModel pModel,
G4bool  warn = false 
)

Definition at line 205 of file G4Scene.cc.

205 {
206 G4int i, nModels = fEndOfEventModelList.size ();
207 for (i = 0; i < nModels; i++) {
208 if (pModel -> GetGlobalDescription () ==
209 fEndOfEventModelList[i].fpModel -> GetGlobalDescription ()) break;
210 }
211 if (i < nModels) {
212 if (warn) {
213 G4cout << "G4Scene::AddEndOfEventModel: a model \""
214 << pModel -> GetGlobalDescription ()
215 << "\"\n is already in the end-of-event list of scene \""
216 << fName << "\"."
217 << G4endl;
218 }
219 return false;
220 }
221 fEndOfEventModelList.push_back (Model(pModel));
222 return true;
223}
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout

◆ AddEndOfRunModel()

G4bool G4Scene::AddEndOfRunModel ( G4VModel pModel,
G4bool  warn = false 
)

Definition at line 225 of file G4Scene.cc.

225 {
226 G4int i, nModels = fEndOfRunModelList.size ();
227 for (i = 0; i < nModels; i++) {
228 if (pModel -> GetGlobalDescription () ==
229 fEndOfRunModelList[i].fpModel -> GetGlobalDescription ()) break;
230 }
231 if (i < nModels) {
232 if (warn) {
233 G4cout << "G4Scene::AddEndOfRunModel: a model \""
234 << pModel -> GetGlobalDescription ()
235 << "\"\n is already in the end-of-run list of scene \""
236 << fName << "\"."
237 << G4endl;
238 }
239 return false;
240 }
241 fEndOfRunModelList.push_back (pModel);
242 return true;
243}

◆ AddRunDurationModel()

G4bool G4Scene::AddRunDurationModel ( G4VModel pModel,
G4bool  warn = false 
)

Definition at line 50 of file G4Scene.cc.

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
93
94 return true;
95}
void CalculateExtent()
Definition: G4Scene.cc:109
const G4String & GetGlobalTag() const

Referenced by AddWorldIfEmpty(), G4VisCommandSceneAddVolume::SetNewValue(), G4VisCommandsTouchable::SetNewValue(), and G4VisCommandViewerCentreOn::SetNewValue().

◆ AddWorldIfEmpty()

G4bool G4Scene::AddWorldIfEmpty ( G4bool  warn = false)

Definition at line 169 of file G4Scene.cc.

169 {
170 G4bool successful = true;
171 if (IsEmpty ()) {
172 successful = false;
173 G4VPhysicalVolume* pWorld =
175 -> GetNavigatorForTracking () -> GetWorldVolume ();
176 if (pWorld) {
177 const G4VisAttributes* pVisAttribs =
178 pWorld -> GetLogicalVolume () -> GetVisAttributes ();
179 if (!pVisAttribs || pVisAttribs -> IsVisible ()) {
180 if (warn) {
181 G4cout <<
182 "Your \"world\" has no vis attributes or is marked as visible."
183 "\n For a better view of the contents, mark the world as"
184 " invisible, e.g.,"
185 "\n myWorldLogicalVol ->"
186 " SetVisAttributes (G4VisAttributes::GetInvisible());"
187 << G4endl;
188 }
189 }
190 successful = AddRunDurationModel (new G4PhysicalVolumeModel (pWorld));
191 // Note: default depth and no modeling parameters.
192 if (successful) {
193 if (warn) {
194 G4cout <<
195 "G4Scene::AddWorldIfEmpty: The scene was empty of run-duration models."
196 "\n \"world\" has been added.";
197 G4cout << G4endl;
198 }
199 }
200 }
201 }
202 return successful;
203}
bool G4bool
Definition: G4Types.hh:86
G4bool AddRunDurationModel(G4VModel *, G4bool warn=false)
Definition: G4Scene.cc:50
G4bool IsEmpty() const
static G4TransportationManager * GetTransportationManager()

Referenced by G4RayTracerSceneHandler::G4RayTracerSceneHandler().

◆ CalculateExtent()

void G4Scene::CalculateExtent ( )

Definition at line 109 of file G4Scene.cc.

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 if (thisExtent != G4VisExtent::GetNullExtent()) {
119 boundingExtentScene.AccrueBoundingExtent(thisExtent);
120 }
121 } else {
122 PrintInvalidModel(model);
123 }
124 }
125 }
126
127 for (size_t i = 0; i < fEndOfEventModelList.size(); i++) {
128 if (fEndOfEventModelList[i].fActive) {
129 G4VModel* model = fEndOfEventModelList[i].fpModel;
130 if (model -> Validate()) { // Validates and also recomputes extent.
131 const G4VisExtent& thisExtent = model -> GetTransformedExtent ();
132 if (thisExtent != G4VisExtent::GetNullExtent()) {
133 boundingExtentScene.AccrueBoundingExtent(thisExtent);
134 }
135 } else {
136 PrintInvalidModel(model);
137 }
138 }
139 }
140
141 for (size_t i = 0; i < fEndOfRunModelList.size(); i++) {
142 if (fEndOfRunModelList[i].fActive) {
143 G4VModel* model = fEndOfRunModelList[i].fpModel;
144 if (model -> Validate()) { // Validates and also recomputes extent.
145 const G4VisExtent& thisExtent = model -> GetTransformedExtent ();
146 if (thisExtent != G4VisExtent::GetNullExtent()) {
147 boundingExtentScene.AccrueBoundingExtent(thisExtent);
148 }
149 } else {
150 PrintInvalidModel(model);
151 }
152 }
153 }
154
155 fExtent = boundingExtentScene.GetBoundingExtent ();
156 fStandardTargetPoint = fExtent.GetExtentCentre ();
157 if (fExtent.GetExtentRadius() <= 0.) {
159 ("G4Scene::CalculateExtent",
160 "visman0202", JustWarning,
161 "Scene has no extent. Please activate or add something."
162 "\nThe camera needs to have something to point at!"
163 "\nAdd a volume. (You may need \"/run/initialize\".)"
164 "\nOr use \"/vis/scene/add/extent\"."
165 "\n\"/vis/scene/list\" to see list of models.");
166 }
167}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
void AccrueBoundingExtent(const G4VisExtent &)
const G4VisExtent & GetBoundingExtent() const
static const G4VisExtent & GetNullExtent()
Definition: G4VisExtent.cc:60
G4double GetExtentRadius() const
Definition: G4VisExtent.cc:75
const G4Point3D & GetExtentCentre() const
Definition: G4VisExtent.cc:65

Referenced by AddRunDurationModel(), G4VisManager::GeometryHasChanged(), G4VisManager::NotifyHandlers(), and G4VisCommandSceneNotifyHandlers::SetNewValue().

◆ GetEndOfEventModelList()

const std::vector< Model > & G4Scene::GetEndOfEventModelList ( ) const

◆ GetEndOfRunModelList()

const std::vector< Model > & G4Scene::GetEndOfRunModelList ( ) const

◆ GetExtent()

◆ GetMaxNumberOfKeptEvents()

G4int G4Scene::GetMaxNumberOfKeptEvents ( ) const

◆ GetName()

◆ GetRefreshAtEndOfEvent()

◆ GetRefreshAtEndOfRun()

◆ GetRunDurationModelList()

◆ GetStandardTargetPoint()

◆ IsEmpty()

G4bool G4Scene::IsEmpty ( ) const

Referenced by AddWorldIfEmpty().

◆ operator!=()

G4bool G4Scene::operator!= ( const G4Scene scene) const

Definition at line 302 of file G4Scene.cc.

302 {
303 if (
304 (fRunDurationModelList.size () !=
305 scene.fRunDurationModelList.size ()) ||
306 (fEndOfEventModelList.size () !=
307 scene.fEndOfEventModelList.size ()) ||
308 (fEndOfRunModelList.size () !=
309 scene.fEndOfRunModelList.size ()) ||
310 (fExtent != scene.fExtent) ||
311 !(fStandardTargetPoint == scene.fStandardTargetPoint) ||
312 fRefreshAtEndOfEvent != scene.fRefreshAtEndOfEvent ||
313 fRefreshAtEndOfRun != scene.fRefreshAtEndOfRun ||
314 fMaxNumberOfKeptEvents != scene.fMaxNumberOfKeptEvents
315 ) return true;
316
317 /* A complete comparison should, perhaps, include a comparison of
318 individual models, but it is not easy to implement operator!= for
319 all models. Also, it would be unfeasible to ask users to
320 implement opeerator!= if we ever get round to allowing
321 user-defined models. Moreover, there is no editing of G4Scene
322 objects, apart from changing fRefreshAtEndOfEvent, etc; as far as
323 models are concerned, all you can ever do is add them, so a test
324 on size (above) is enough.
325
326 for (size_t i = 0; i < fRunDurationModelList.size (); i++) {
327 if (fRunDurationModelList[i] != scene.fRunDurationModelList[i])
328 return true;
329 }
330
331 for (size_t i = 0; i < fEndOfEventModelList.size (); i++) {
332 if (fEndOfEventModelList[i] != scene.fEndOfEventModelList[i])
333 return true;
334 }
335
336 for (size_t i = 0; i < fEndOfRunModelList.size (); i++) {
337 if (fEndOfRunModelList[i] != scene.fEndOfRunModelList[i])
338 return true;
339 }
340 */
341
342 return false;
343}

◆ operator==()

G4bool G4Scene::operator== ( const G4Scene ) const

◆ SetEndOfEventModelList()

std::vector< Model > & G4Scene::SetEndOfEventModelList ( )

◆ SetEndOfRunModelList()

std::vector< Model > & G4Scene::SetEndOfRunModelList ( )

◆ SetMaxNumberOfKeptEvents()

void G4Scene::SetMaxNumberOfKeptEvents ( G4int  )

◆ SetName()

void G4Scene::SetName ( const G4String )

◆ SetRefreshAtEndOfEvent()

void G4Scene::SetRefreshAtEndOfEvent ( G4bool  )

◆ SetRefreshAtEndOfRun()

void G4Scene::SetRefreshAtEndOfRun ( G4bool  )

◆ SetRunDurationModelList()

std::vector< Model > & G4Scene::SetRunDurationModelList ( )

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const G4Scene d 
)
friend

Definition at line 245 of file G4Scene.cc.

245 {
246
247 size_t i;
248
249 os << "Scene data:";
250
251 os << "\n Run-duration model list:";
252 if (scene.fRunDurationModelList.size () == 0) {
253 os << " none";
254 }
255 for (i = 0; i < scene.fRunDurationModelList.size (); i++) {
256 if (scene.fRunDurationModelList[i].fActive) os << "\n Active: ";
257 else os << "\n Inactive: ";
258 os << *(scene.fRunDurationModelList[i].fpModel);
259 }
260
261 os << "\n End-of-event model list:";
262 if (scene.fEndOfEventModelList.size () == 0) {
263 os << " none";
264 }
265 for (i = 0; i < scene.fEndOfEventModelList.size (); i++) {
266 if (scene.fEndOfEventModelList[i].fActive) os << "\n Active: ";
267 else os << "\n Inactive: ";
268 os << *(scene.fEndOfEventModelList[i].fpModel);
269 }
270
271 os << "\n End-of-run model list:";
272 if (scene.fEndOfRunModelList.size () == 0) {
273 os << " none";
274 }
275 for (i = 0; i < scene.fEndOfRunModelList.size (); i++) {
276 if (scene.fEndOfRunModelList[i].fActive) os << "\n Active: ";
277 else os << "\n Inactive: ";
278 os << *(scene.fEndOfRunModelList[i].fpModel);
279 }
280
281 os << "\n Overall extent or bounding box: " << scene.fExtent;
282
283 os << "\n Standard target point: " << scene.fStandardTargetPoint;
284
285 os << "\n End of event action set to \"";
286 if (scene.fRefreshAtEndOfEvent) os << "refresh\"";
287 else {
288 os << "accumulate (maximum number of kept events: ";
289 if (scene.fMaxNumberOfKeptEvents >= 0) os << scene.fMaxNumberOfKeptEvents;
290 else os << "unlimited";
291 os << ")";
292 }
293
294 os << "\n End of run action set to \"";
295 if (scene.fRefreshAtEndOfRun) os << "refresh";
296 else os << "accumulate";
297 os << "\"";
298
299 return os;
300}

The documentation for this class was generated from the following files: