source: trunk/source/visualization/management/src/G4VisManager.cc@ 1180

Last change on this file since 1180 was 1170, checked in by garnier, 16 years ago

update contre CVS

  • Property svn:mime-type set to text/cpp
File size: 53.3 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// $Id: G4VisManager.cc,v 1.122 2009/11/04 12:58:00 allison Exp $
27// GEANT4 tag $Name: $
28//
29//
30// GEANT4 Visualization Manager - John Allison 02/Jan/1996.
31
32#include "G4VisManager.hh"
33
34#include "G4VisCommands.hh"
35#include "G4VisCommandsCompound.hh"
36#include "G4VisCommandsGeometry.hh"
37#include "G4VisCommandsGeometrySet.hh"
38#include "G4VisCommandsScene.hh"
39#include "G4VisCommandsSceneAdd.hh"
40#include "G4VisCommandsSceneHandler.hh"
41#include "G4VisCommandsViewer.hh"
42#include "G4VisCommandsViewerSet.hh"
43#include "G4UImanager.hh"
44#include "G4VisStateDependent.hh"
45#include "G4UIdirectory.hh"
46#include "G4VisFeaturesOfFukuiRenderer.hh"
47#include "G4VisFeaturesOfDAWNFILE.hh"
48#include "G4VisFeaturesOfOpenGL.hh"
49#include "G4VisFeaturesOfOpenInventor.hh"
50#include "G4VGraphicsSystem.hh"
51#include "G4VSceneHandler.hh"
52#include "G4VViewer.hh"
53#include "G4VPhysicalVolume.hh"
54#include "G4LogicalVolume.hh"
55#include "G4VSolid.hh"
56#include "G4Vector3D.hh"
57#include "G4Point3D.hh"
58#include "G4RotationMatrix.hh"
59#include "G4Polyline.hh"
60#include "G4Polyhedron.hh"
61#include "G4NURBS.hh"
62#include "G4NullModel.hh"
63#include "G4ModelingParameters.hh"
64#include "G4TransportationManager.hh"
65#include "G4VisCommandModelCreate.hh"
66#include "G4VisCommandsListManager.hh"
67#include "G4VisModelManager.hh"
68#include "G4VModelFactory.hh"
69#include "G4VisFilterManager.hh"
70#include "G4VTrajectoryModel.hh"
71#include "G4TrajectoryDrawByCharge.hh"
72#include "Randomize.hh"
73#include "G4RunManager.hh"
74#include "G4EventManager.hh"
75#include "G4Run.hh"
76#include "G4Event.hh"
77#include <sstream>
78
79G4VisManager* G4VisManager::fpInstance = 0;
80
81G4VisManager::G4VisManager ():
82 fVerbose (1),
83 fInitialised (false),
84 fpUserVisAction (0),
85 fpGraphicsSystem (0),
86 fpScene (0),
87 fpSceneHandler (0),
88 fpViewer (0),
89 fVerbosity (warnings),
90 fpStateDependent (0),
91 fEventRefreshing (false),
92 fTransientsDrawnThisRun (false),
93 fTransientsDrawnThisEvent (false),
94 fEventKeepingSuspended (false),
95 fKeptLastEvent (false),
96 fpRequestedEvent (0),
97 fAbortReviewKeptEvents (false)
98 // All other objects use default constructors.
99{
100 fpTrajDrawModelMgr = new G4VisModelManager<G4VTrajectoryModel>("/vis/modeling/trajectories");
101 fpTrajFilterMgr = new G4VisFilterManager<G4VTrajectory>("/vis/filtering/trajectories");
102 fpHitFilterMgr = new G4VisFilterManager<G4VHit>("/vis/filtering/hits");
103
104 VerbosityGuidanceStrings.push_back
105 ("Simple graded message scheme - digit or string (1st character defines):");
106 VerbosityGuidanceStrings.push_back
107 (" 0) quiet, // Nothing is printed.");
108 VerbosityGuidanceStrings.push_back
109 (" 1) startup, // Startup and endup messages are printed...");
110 VerbosityGuidanceStrings.push_back
111 (" 2) errors, // ...and errors...");
112 VerbosityGuidanceStrings.push_back
113 (" 3) warnings, // ...and warnings...");
114 VerbosityGuidanceStrings.push_back
115 (" 4) confirmations, // ...and confirming messages...");
116 VerbosityGuidanceStrings.push_back
117 (" 5) parameters, // ...and parameters of scenes and views...");
118 VerbosityGuidanceStrings.push_back
119 (" 6) all // ...and everything available.");
120
121 if (fpInstance) {
122 G4Exception
123 ("G4VisManager: attempt to Construct more than one VisManager.");
124 }
125 else {
126
127 fpInstance = this;
128 SetConcreteInstance(this);
129
130 fpStateDependent = new G4VisStateDependent (this);
131 // No need to delete this; G4StateManager does this.
132
133 if (fVerbosity >= startup) {
134 G4cout << "Visualization Manager instantiating..." << G4endl;
135 }
136
137 // Note: The specific graphics systems must be instantiated in a
138 // higher level library to avoid circular dependencies. Also,
139 // some specifically need additional external libararies that the
140 // user must supply. Therefore we ask the user to implement
141 // RegisterGraphicsSystems() and RegisterModelFactories()
142 // in a subclass. We have to wait for the subclass to instantiate
143 // so RegisterGraphicsSystems() cannot be called from this
144 // constructor; it is called from Initialise(). So we ask the
145 // user:
146 // (a) to write a subclass and implement RegisterGraphicsSystems()
147 // and RegisterModelFactories(). See
148 // visualization/include/G4VisExecutive.hh/icc as an example.
149 // (b) instantiate the subclass.
150 // (c) invoke the Initialise() method of the subclass.
151 // For example:
152 // ...
153 // #ifdef G4VIS_USE
154 // // Instantiate and initialise Visualization Manager.
155 // G4VisManager* visManager = new G4VisExecutive;
156 // visManager -> SetVerboseLevel (Verbose);
157 // visManager -> Initialise ();
158 // #endif
159 // // (Don't forget to delete visManager;)
160 // ...
161
162 // Make top level command directory...
163 G4UIcommand* directory;
164 directory = new G4UIdirectory ("/vis/");
165 directory -> SetGuidance ("Visualization commands.");
166 fDirectoryList.push_back (directory);
167
168 // Instantiate top level basic commands
169 G4VVisCommand::SetVisManager (this); // Sets shared pointer
170 RegisterMessenger(new G4VisCommandVerbose);
171 RegisterMessenger(new G4VisCommandInitialize);
172 }
173}
174
175G4VisManager::~G4VisManager () {
176 printf("G4VisManager::~G4VisManager DELETING \n");
177 fpInstance = 0;
178 size_t i;
179 for (i = 0; i < fSceneList.size (); ++i) {
180 printf("G4VisManager::~G4VisManager DELETING 1 \n");
181 delete fSceneList[i];
182 }
183 for (i = 0; i < fAvailableSceneHandlers.size (); ++i) {
184 printf("G4VisManager::~G4VisManager DELETING 2\n");
185 if (fAvailableSceneHandlers[i] != NULL) {
186 delete fAvailableSceneHandlers[i];
187 }
188 }
189 for (i = 0; i < fAvailableGraphicsSystems.size (); ++i) {
190 printf("G4VisManager::~G4VisManager DELETING 3\n");
191 if (fAvailableGraphicsSystems[i]) {
192 delete fAvailableGraphicsSystems[i];
193 }
194 }
195 if (fVerbosity >= startup) {
196 G4cout << "Graphics systems deleted." << G4endl;
197 G4cout << "Visualization Manager deleting..." << G4endl;
198 }
199 for (i = 0; i < fMessengerList.size (); ++i) {
200 printf("G4VisManager::~G4VisManager DELETING 4\n");
201 delete fMessengerList[i];
202 }
203 for (i = 0; i < fDirectoryList.size (); ++i) {
204 printf("G4VisManager::~G4VisManager DELETING 5\n");
205 delete fDirectoryList[i];
206 }
207
208 printf("G4VisManager::~G4VisManager DELETING 6\n");
209 delete fpTrajDrawModelMgr;
210 printf("G4VisManager::~G4VisManager DELETING 7\n");
211 delete fpTrajFilterMgr;
212 printf("G4VisManager::~G4VisManager DELETING 8\n");
213 delete fpHitFilterMgr;
214 printf("G4VisManager::~G4VisManager DELETING 9\n");
215}
216
217G4VisManager* G4VisManager::GetInstance () {
218 if (!fpInstance) {
219 G4Exception
220 ("G4VisManager::GetInstance: VisManager not yet instantiated!");
221 }
222 return fpInstance;
223}
224
225void G4VisManager::Initialise () {
226
227 if (fInitialised && fVerbosity >= warnings) {
228 G4cout << "WARNING: G4VisManager::Initialise: already initialised."
229 << G4endl;
230 return;
231 }
232
233 if (fVerbosity >= startup) {
234 G4cout << "Visualization Manager initialising..." << G4endl;
235 }
236
237 if (fVerbosity >= parameters) {
238 G4cout <<
239 "\nYou have instantiated your own Visualization Manager, inheriting"
240 "\n G4VisManager and implementing RegisterGraphicsSystems(), in which"
241 "\n you should, normally, instantiate drivers which do not need"
242 "\n external packages or libraries, and, optionally, drivers under"
243 "\n control of environment variables."
244 "\n Also you should implement RegisterModelFactories()."
245 "\n See visualization/include/G4VisExecutive.hh/icc, for example."
246 "\n In your main() you will have something like:"
247 "\n #ifdef G4VIS_USE"
248 "\n G4VisManager* visManager = new G4VisExecutive;"
249 "\n visManager -> SetVerboseLevel (Verbose);"
250 "\n visManager -> Initialize ();"
251 "\n #endif"
252 "\n (Don't forget to delete visManager;)"
253 "\n"
254 << G4endl;
255 }
256
257 if (fVerbosity >= startup) {
258 G4cout << "Registering graphics systems..." << G4endl;
259 }
260
261 RegisterGraphicsSystems ();
262
263 if (fVerbosity >= startup) {
264 G4cout <<
265 "\nYou have successfully registered the following graphics systems."
266 << G4endl;
267 PrintAvailableGraphicsSystems ();
268 G4cout << G4endl;
269 }
270
271 // Make command directories for commands instantiated in the
272 // modeling subcategory...
273 G4UIcommand* directory;
274 directory = new G4UIdirectory ("/vis/modeling/");
275 directory -> SetGuidance ("Modeling commands.");
276 fDirectoryList.push_back (directory);
277 directory = new G4UIdirectory ("/vis/modeling/trajectories/");
278 directory -> SetGuidance ("Trajectory model commands.");
279 fDirectoryList.push_back (directory);
280 directory = new G4UIdirectory ("/vis/modeling/trajectories/create/");
281 directory -> SetGuidance ("Create trajectory models and messengers.");
282 fDirectoryList.push_back (directory);
283
284 // Filtering command directory
285 directory = new G4UIdirectory ("/vis/filtering/");
286 directory -> SetGuidance ("Filtering commands.");
287 fDirectoryList.push_back (directory);
288 directory = new G4UIdirectory ("/vis/filtering/trajectories/");
289 directory -> SetGuidance ("Trajectory filtering commands.");
290 fDirectoryList.push_back (directory);
291 directory = new G4UIdirectory ("/vis/filtering/trajectories/create/");
292 directory -> SetGuidance ("Create trajectory filters and messengers.");
293 fDirectoryList.push_back (directory);
294 directory = new G4UIdirectory ("/vis/filtering/hits/");
295 directory -> SetGuidance ("Hit filtering commands.");
296 fDirectoryList.push_back (directory);
297 directory = new G4UIdirectory ("/vis/filtering/hits/create/");
298 directory -> SetGuidance ("Create hit filters and messengers.");
299 fDirectoryList.push_back (directory);
300
301 RegisterMessengers ();
302
303 if (fVerbosity >= startup) {
304 G4cout << "Registering model factories..." << G4endl;
305 }
306
307 RegisterModelFactories();
308
309 if (fVerbosity >= startup) {
310 G4cout <<
311 "\nYou have successfully registered the following model factories."
312 << G4endl;
313 PrintAvailableModels (fVerbosity);
314 G4cout << G4endl;
315 }
316
317 fInitialised = true;
318}
319
320void G4VisManager::Enable() {
321 if (IsValidView ()) {
322 if (fVerbosity >= confirmations) {
323 G4cout << "G4VisManager::Enable: visualization enabled." << G4endl;
324 }
325 }
326 else {
327 if (fVerbosity >= warnings) {
328 G4cout <<
329 "G4VisManager::Enable: WARNING: visualization remains disabled for"
330 "\n above reasons. Rectifying with valid vis commands will"
331 "\n automatically enable."
332 << G4endl;
333 }
334 }
335}
336
337void G4VisManager::Disable() {
338 SetConcreteInstance(0);
339 if (fVerbosity >= confirmations) {
340 G4cout <<
341 "G4VisManager::Disable: visualization disabled."
342 "\n The pointer returned by GetConcreteInstance will be zero."
343 "\n Note that it will become enabled after some valid vis commands."
344 << G4endl;
345 }
346}
347
348const G4GraphicsSystemList& G4VisManager::GetAvailableGraphicsSystems () {
349 G4int nSystems = fAvailableGraphicsSystems.size ();
350 if (nSystems == 0) {
351 if (fVerbosity >= warnings) {
352 G4cout << "G4VisManager::GetAvailableGraphicsSystems: WARNING: no"
353 "\n graphics system available!"
354 "\n 1) Did you have environment variables G4VIS_BUILD_xxxx_DRIVER set"
355 "\n when you compiled/built the visualization code?"
356 "\n 2) Did you instantiate your own Visualization Manager and forget"
357 "\n to implement RegisterGraphicsSystems correctly?"
358 "\n 3) You can register your own graphics system, e.g.,"
359 "\n visManager->RegisterGraphicsSystem(new MyGraphicsSystem);)"
360 "\n after instantiating your vis manager and before"
361 "\n visManager->Initialize()."
362 << G4endl;
363 }
364 }
365 return fAvailableGraphicsSystems;
366}
367
368G4bool G4VisManager::RegisterGraphicsSystem (G4VGraphicsSystem* pSystem) {
369 G4bool happy = true;
370 if (pSystem) {
371 fAvailableGraphicsSystems.push_back (pSystem);
372 if (fVerbosity >= confirmations) {
373 G4cout << "G4VisManager::RegisterGraphicsSystem: "
374 << pSystem -> GetName ();
375 if (pSystem -> GetNickname () != "") {
376 G4cout << " (" << pSystem -> GetNickname () << ")";
377 }
378 G4cout << " registered." << G4endl;
379 }
380 }
381 else {
382 if (fVerbosity >= errors) {
383 G4cout << "G4VisManager::RegisterGraphicsSystem: null pointer!"
384 << G4endl;
385 }
386 happy=false;
387 }
388 return happy;
389}
390
391
392
393const G4VTrajectoryModel*
394G4VisManager::CurrentTrajDrawModel() const
395{
396 assert (0 != fpTrajDrawModelMgr);
397
398 const G4VTrajectoryModel* model = fpTrajDrawModelMgr->Current();
399
400 if (0 == model) {
401 // No model was registered with the trajectory model manager.
402 // Use G4TrajectoryDrawByCharge as a default.
403 fpTrajDrawModelMgr->Register(new G4TrajectoryDrawByCharge("AutoGenerated"));
404
405 if (fVerbosity >= warnings) {
406 G4cout<<"G4VisManager: Using G4TrajectoryDrawByCharge as default trajectory model."<<G4endl;
407 G4cout<<"See commands in /vis/modeling/trajectories/ for other options."<<G4endl;
408 }
409 }
410
411 model = fpTrajDrawModelMgr->Current();
412 assert (0 != model); // Should definitely exist now
413
414 return model;
415}
416
417void G4VisManager::RegisterModel(G4VTrajectoryModel* model)
418{
419 fpTrajDrawModelMgr->Register(model);
420}
421
422void
423G4VisManager::RegisterModelFactory(G4TrajDrawModelFactory* factory)
424{
425 fpTrajDrawModelMgr->Register(factory);
426}
427
428void G4VisManager::RegisterModel(G4VFilter<G4VTrajectory>* model)
429{
430 fpTrajFilterMgr->Register(model);
431}
432
433void
434G4VisManager::RegisterModelFactory(G4TrajFilterFactory* factory)
435{
436 fpTrajFilterMgr->Register(factory);
437}
438
439void G4VisManager::RegisterModel(G4VFilter<G4VHit>* model)
440{
441 fpHitFilterMgr->Register(model);
442}
443
444void
445G4VisManager::RegisterModelFactory(G4HitFilterFactory* factory)
446{
447 fpHitFilterMgr->Register(factory);
448}
449
450void G4VisManager::SelectTrajectoryModel(const G4String& model)
451{
452 fpTrajDrawModelMgr->SetCurrent(model);
453}
454
455void G4VisManager::Draw (const G4Circle& circle,
456 const G4Transform3D& objectTransform) {
457 if (IsValidView ()) {
458 ClearTransientStoreIfMarked();
459 fpSceneHandler -> BeginPrimitives (objectTransform);
460 fpSceneHandler -> AddPrimitive (circle);
461 fpSceneHandler -> EndPrimitives ();
462 }
463}
464
465void G4VisManager::Draw (const G4NURBS& nurbs,
466 const G4Transform3D& objectTransform) {
467 if (IsValidView ()) {
468 ClearTransientStoreIfMarked();
469 fpSceneHandler -> BeginPrimitives (objectTransform);
470 fpSceneHandler -> AddPrimitive (nurbs);
471 fpSceneHandler -> EndPrimitives ();
472 }
473}
474
475void G4VisManager::Draw (const G4Polyhedron& polyhedron,
476 const G4Transform3D& objectTransform) {
477 if (IsValidView ()) {
478 ClearTransientStoreIfMarked();
479 fpSceneHandler -> BeginPrimitives (objectTransform);
480 fpSceneHandler -> AddPrimitive (polyhedron);
481 fpSceneHandler -> EndPrimitives ();
482 }
483}
484
485void G4VisManager::Draw (const G4Polyline& line,
486 const G4Transform3D& objectTransform) {
487 if (IsValidView ()) {
488 ClearTransientStoreIfMarked();
489 fpSceneHandler -> BeginPrimitives (objectTransform);
490 fpSceneHandler -> AddPrimitive (line);
491 fpSceneHandler -> EndPrimitives ();
492 }
493}
494
495void G4VisManager::Draw (const G4Polymarker& polymarker,
496 const G4Transform3D& objectTransform) {
497 if (IsValidView ()) {
498 ClearTransientStoreIfMarked();
499 fpSceneHandler -> BeginPrimitives (objectTransform);
500 fpSceneHandler -> AddPrimitive (polymarker);
501 fpSceneHandler -> EndPrimitives ();
502 }
503}
504
505void G4VisManager::Draw (const G4Scale& scale,
506 const G4Transform3D& objectTransform) {
507 if (IsValidView ()) {
508 ClearTransientStoreIfMarked();
509 fpSceneHandler -> BeginPrimitives (objectTransform);
510 fpSceneHandler -> AddPrimitive (scale);
511 fpSceneHandler -> EndPrimitives ();
512 }
513}
514
515void G4VisManager::Draw (const G4Square& square,
516 const G4Transform3D& objectTransform) {
517 if (IsValidView ()) {
518 ClearTransientStoreIfMarked();
519 fpSceneHandler -> BeginPrimitives (objectTransform);
520 fpSceneHandler -> AddPrimitive (square);
521 fpSceneHandler -> EndPrimitives ();
522 }
523}
524
525void G4VisManager::Draw (const G4Text& text,
526 const G4Transform3D& objectTransform) {
527 if (IsValidView ()) {
528 ClearTransientStoreIfMarked();
529 fpSceneHandler -> BeginPrimitives (objectTransform);
530 fpSceneHandler -> AddPrimitive (text);
531 fpSceneHandler -> EndPrimitives ();
532 }
533}
534
535void G4VisManager::Draw2D (const G4Circle& circle,
536 const G4Transform3D& objectTransform)
537{
538 if (IsValidView()) {
539 ClearTransientStoreIfMarked();
540 fpSceneHandler -> BeginPrimitives2D(objectTransform);
541 fpSceneHandler -> AddPrimitive(circle);
542 fpSceneHandler -> EndPrimitives2D();
543 }
544}
545
546void G4VisManager::Draw2D (const G4NURBS& nurbs,
547 const G4Transform3D& objectTransform)
548{
549 if (IsValidView()) {
550 ClearTransientStoreIfMarked();
551 fpSceneHandler -> BeginPrimitives2D(objectTransform);
552 fpSceneHandler -> AddPrimitive(nurbs);
553 fpSceneHandler -> EndPrimitives2D();
554 }
555}
556
557void G4VisManager::Draw2D (const G4Polyhedron& polyhedron,
558 const G4Transform3D& objectTransform)
559{
560 if (IsValidView()) {
561 ClearTransientStoreIfMarked();
562 fpSceneHandler -> BeginPrimitives2D(objectTransform);
563 fpSceneHandler -> AddPrimitive(polyhedron);
564 fpSceneHandler -> EndPrimitives2D();
565 }
566}
567
568void G4VisManager::Draw2D (const G4Polyline& line,
569 const G4Transform3D& objectTransform)
570{
571 if (IsValidView()) {
572 ClearTransientStoreIfMarked();
573 fpSceneHandler -> BeginPrimitives2D(objectTransform);
574 fpSceneHandler -> AddPrimitive(line);
575 fpSceneHandler -> EndPrimitives2D();
576 }
577}
578
579void G4VisManager::Draw2D (const G4Polymarker& polymarker,
580 const G4Transform3D& objectTransform)
581{
582 if (IsValidView()) {
583 ClearTransientStoreIfMarked();
584 fpSceneHandler -> BeginPrimitives2D(objectTransform);
585 fpSceneHandler -> AddPrimitive(polymarker);
586 fpSceneHandler -> EndPrimitives2D();
587 }
588}
589
590void G4VisManager::Draw2D (const G4Square& square,
591 const G4Transform3D& objectTransform)
592{
593 if (IsValidView()) {
594 ClearTransientStoreIfMarked();
595 fpSceneHandler -> BeginPrimitives2D(objectTransform);
596 fpSceneHandler -> AddPrimitive(square);
597 fpSceneHandler -> EndPrimitives2D();
598 }
599}
600
601void G4VisManager::Draw2D (const G4Text& text,
602 const G4Transform3D& objectTransform)
603{
604 if (IsValidView()) {
605 ClearTransientStoreIfMarked();
606 fpSceneHandler -> BeginPrimitives2D(objectTransform);
607 fpSceneHandler -> AddPrimitive(text);
608 fpSceneHandler -> EndPrimitives2D();
609 }
610}
611
612void G4VisManager::Draw (const G4VHit& hit) {
613 if (IsValidView ()) {
614 ClearTransientStoreIfMarked();
615 fpSceneHandler -> AddCompound (hit);
616 }
617}
618
619void G4VisManager::Draw (const G4VTrajectory& traj,
620 G4int i_mode) {
621 if (IsValidView ()) {
622 ClearTransientStoreIfMarked();
623 fpSceneHandler -> SetModel (&dummyTrajectoriesModel);
624 dummyTrajectoriesModel.SetDrawingMode(i_mode);
625 fpSceneHandler -> AddCompound (traj);
626 }
627}
628
629void G4VisManager::Draw (const G4LogicalVolume& logicalVol,
630 const G4VisAttributes& attribs,
631 const G4Transform3D& objectTransform) {
632 // Find corresponding solid.
633 G4VSolid* pSol = logicalVol.GetSolid ();
634 Draw (*pSol, attribs, objectTransform);
635}
636
637void G4VisManager::Draw (const G4VSolid& solid,
638 const G4VisAttributes& attribs,
639 const G4Transform3D& objectTransform) {
640 if (IsValidView ()) {
641 ClearTransientStoreIfMarked();
642 fpSceneHandler -> PreAddSolid (objectTransform, attribs);
643 solid.DescribeYourselfTo (*fpSceneHandler);
644 fpSceneHandler -> PostAddSolid ();
645 }
646}
647
648void G4VisManager::Draw (const G4VPhysicalVolume& physicalVol,
649 const G4VisAttributes& attribs,
650 const G4Transform3D& objectTransform) {
651 // Find corresponding logical volume and solid.
652 G4LogicalVolume* pLV = physicalVol.GetLogicalVolume ();
653 G4VSolid* pSol = pLV -> GetSolid ();
654 Draw (*pSol, attribs, objectTransform);
655}
656
657void G4VisManager::CreateSceneHandler (G4String name) {
658 if (!fInitialised) Initialise ();
659 if (fpGraphicsSystem) {
660 G4VSceneHandler* pSceneHandler =
661 fpGraphicsSystem -> CreateSceneHandler (name);
662 if (pSceneHandler) {
663 fAvailableSceneHandlers.push_back (pSceneHandler);
664 fpSceneHandler = pSceneHandler; // Make current.
665 }
666 else {
667 if(fVerbosity >= errors) {
668 G4cout << "ERROR in G4VisManager::CreateSceneHandler during "
669 << fpGraphicsSystem -> GetName ()
670 << " scene handler creation.\n No action taken."
671 << G4endl;
672 }
673 }
674 }
675 else PrintInvalidPointers ();
676}
677
678void G4VisManager::CreateViewer (G4String name,G4String XGeometry) {
679
680 if (!fInitialised) Initialise ();
681
682 if (!fpSceneHandler) {
683 PrintInvalidPointers ();
684 return;
685 }
686
687 G4VViewer* p = fpGraphicsSystem -> CreateViewer (*fpSceneHandler, name);
688
689 if (!p) {
690 if (fVerbosity >= errors) {
691 G4cout << "ERROR in G4VisManager::CreateViewer during "
692 << fpGraphicsSystem -> GetName ()
693 << " viewer creation.\n No action taken."
694 << G4endl;
695 }
696 return;
697 }
698
699 if (p -> GetViewId() < 0) {
700 if (fVerbosity >= errors) {
701 G4cout << "ERROR in G4VisManager::CreateViewer during "
702 << fpGraphicsSystem -> GetName ()
703 << " viewer initialisation.\n No action taken."
704 << G4endl;
705 }
706 return;
707 }
708
709 // Viewer is created, now we can set geometry parameters
710 // Before 12/2008, it was done in G4VViewer.cc but it did not have to be there!
711
712 G4ViewParameters initialvp = p -> GetViewParameters();
713 initialvp.SetXGeometryString(XGeometry); //parse string and store parameters
714 p -> SetViewParameters(initialvp);
715 p -> Initialise (); // (Viewer itself may change view parameters further.)
716
717 fpViewer = p; // Make current.
718 fpSceneHandler -> AddViewerToList (fpViewer);
719 fpSceneHandler -> SetCurrentViewer (fpViewer);
720 if (fVerbosity >= confirmations) {
721 G4cout << "G4VisManager::CreateViewer: new viewer created."
722 << G4endl;
723 }
724
725 const G4ViewParameters& vp = fpViewer->GetViewParameters();
726 if (fVerbosity >= parameters) {
727 G4cout << " view parameters are:\n " << vp << G4endl;
728 }
729
730 if (vp.IsCulling () && vp.IsCullingInvisible ()) {
731 static G4bool warned = false;
732 if (fVerbosity >= confirmations) {
733 if (!warned) {
734 G4cout <<
735 "NOTE: objects with visibility flag set to \"false\""
736 " will not be drawn!"
737 "\n \"/vis/viewer/set/culling global false\" to Draw such objects."
738 "\n Also see other \"/vis/viewer/set\" commands."
739 << G4endl;
740 warned = true;
741 }
742 }
743 }
744 if (vp.IsCullingCovered ()) {
745 static G4bool warned = false;
746 if (fVerbosity >= warnings) {
747 if (!warned) {
748 G4cout <<
749 "WARNING: covered objects in solid mode will not be rendered!"
750 "\n \"/vis/viewer/set/culling coveredDaughters false\" to reverse this."
751 "\n Also see other \"/vis/viewer/set\" commands."
752 << G4endl;
753 warned = true;
754 }
755 }
756 }
757}
758
759void G4VisManager::GeometryHasChanged () {
760 if (fVerbosity >= confirmations) {
761 G4cout << "G4VisManager::GeometryHasChanged() called." << G4endl;
762 }
763
764 // Change the world...
765 G4VPhysicalVolume* pWorld =
766 G4TransportationManager::GetTransportationManager ()
767 -> GetNavigatorForTracking () -> GetWorldVolume ();
768 if (!pWorld) {
769 if (fVerbosity >= warnings) {
770 G4cout << "WARNING: There is no world volume!" << G4endl;
771 }
772 }
773
774 // Check scenes.
775 G4SceneList& sceneList = fSceneList;
776 G4int iScene, nScenes = sceneList.size ();
777 for (iScene = 0; iScene < nScenes; iScene++) {
778 G4Scene* pScene = sceneList [iScene];
779 std::vector<G4VModel*>& modelList = pScene -> SetRunDurationModelList ();
780
781 if (modelList.size ()) {
782 G4bool modelInvalid;
783 do { // Remove, if required, one at a time.
784 modelInvalid = false;
785 std::vector<G4VModel*>::iterator iterModel;
786 for (iterModel = modelList.begin();
787 iterModel != modelList.end();
788 ++iterModel) {
789 modelInvalid = !((*iterModel) -> Validate (fVerbosity >= warnings));
790 if (modelInvalid) {
791 // Model invalid - remove and break.
792 if (fVerbosity >= warnings) {
793 G4cout << "WARNING: Model \""
794 << (*iterModel) -> GetGlobalDescription ()
795 <<
796 "\" is no longer valid - being removed\n from scene \""
797 << pScene -> GetName () << "\""
798 << G4endl;
799 }
800 modelList.erase (iterModel);
801 break;
802 }
803 }
804 } while (modelInvalid);
805
806 if (modelList.size () == 0) {
807 if (fVerbosity >= warnings) {
808 G4cout << "WARNING: No models left in this scene \""
809 << pScene -> GetName ()
810 << "\"."
811 << G4endl;
812 }
813 }
814 else {
815 pScene->CalculateExtent();
816 G4UImanager::GetUIpointer () ->
817 ApplyCommand (G4String("/vis/scene/notifyHandlers " + pScene->GetName()));
818 }
819 }
820 }
821
822 // Check the manager's current scene...
823 if (fpScene && fpScene -> GetRunDurationModelList ().size () == 0) {
824 if (fVerbosity >= warnings) {
825 G4cout << "WARNING: The current scene \""
826 << fpScene -> GetName ()
827 << "\" has no models."
828 << G4endl;
829 }
830 }
831
832 }
833void G4VisManager::NotifyHandlers () {
834
835 if (fVerbosity >= confirmations) {
836 G4cout << "G4VisManager::NotifyHandler() called." << G4endl;
837 }
838
839 // Check scenes.
840 G4SceneList& sceneList = fSceneList;
841 G4int iScene, nScenes = sceneList.size ();
842 for (iScene = 0; iScene < nScenes; iScene++) {
843 G4Scene* pScene = sceneList [iScene];
844 std::vector<G4VModel*>& modelList = pScene -> SetRunDurationModelList ();
845
846 if (modelList.size ()) {
847 pScene->CalculateExtent();
848 G4UImanager::GetUIpointer () ->
849 ApplyCommand (G4String("/vis/scene/notifyHandlers " + pScene->GetName()));
850 }
851 }
852
853 // Check the manager's current scene...
854 if (fpScene && fpScene -> GetRunDurationModelList ().size () == 0) {
855 if (fVerbosity >= warnings) {
856 G4cout << "WARNING: The current scene \""
857 << fpScene -> GetName ()
858 << "\" has no models."
859 << G4endl;
860 }
861 }
862
863}
864
865G4bool G4VisManager::FilterTrajectory(const G4VTrajectory& trajectory)
866{
867 return fpTrajFilterMgr->Accept(trajectory);
868}
869
870G4bool G4VisManager::FilterHit(const G4VHit& hit)
871{
872 return fpHitFilterMgr->Accept(hit);
873}
874
875void G4VisManager::DispatchToModel(const G4VTrajectory& trajectory, G4int i_mode)
876{
877 G4bool visible(true);
878
879 // See if trajectory passes filter
880 G4bool passed = FilterTrajectory(trajectory);
881
882 if (!passed) {
883 // Draw invisible trajectory if trajectory failed filter and
884 // are filtering in soft mode
885 if (fpTrajFilterMgr->GetMode() == FilterMode::Soft) visible = false;
886 else {return;}
887 }
888
889 // Go on to draw trajectory
890 assert (0 != fpTrajDrawModelMgr);
891
892 const G4VTrajectoryModel* model = CurrentTrajDrawModel();
893
894 assert (0 != model); // Should exist
895
896 model->Draw(trajectory, i_mode, visible);
897}
898
899void G4VisManager::SetUserAction
900(G4VUserVisAction* pVisAction,
901 const G4VisExtent& extent) {
902 fpUserVisAction = pVisAction;
903 fUserVisActionExtent = extent;
904 if (extent.GetExtentRadius() <= 0.) {
905 if (fVerbosity >= warnings) {
906 G4cout <<
907 "WARNING: No extent set for user vis action. (You may"
908 "\n set it later when adding with /vis/scene/add/userAction.)"
909 << G4endl;
910 }
911 }
912}
913
914void G4VisManager::SetCurrentScene (G4Scene* pScene) {
915 if (pScene != fpScene) {
916 // A change of scene. Therefore reset transients drawn flags. All
917 // memory of previous transient proceessing thereby erased...
918 ResetTransientsDrawnFlags();
919 }
920 fpScene = pScene;
921}
922
923void G4VisManager::SetCurrentGraphicsSystem (G4VGraphicsSystem* pSystem) {
924 fpGraphicsSystem = pSystem;
925 if (fVerbosity >= confirmations) {
926 G4cout << "G4VisManager::SetCurrentGraphicsSystem: system now "
927 << pSystem -> GetName () << G4endl;
928 }
929 // If current scene handler is of same graphics system, leave unchanged.
930 // Else find the most recent scene handler of same graphics system.
931 // Or clear pointers.
932 if (!(fpSceneHandler && fpSceneHandler -> GetGraphicsSystem () == pSystem)) {
933 const G4SceneHandlerList& sceneHandlerList = fAvailableSceneHandlers;
934 G4int nSH = sceneHandlerList.size (); // No. of scene handlers.
935 G4int iSH;
936 for (iSH = nSH - 1; iSH >= 0; iSH--) {
937 if (sceneHandlerList [iSH] -> GetGraphicsSystem () == pSystem) break;
938 }
939 if (iSH >= 0) {
940 fpSceneHandler = sceneHandlerList [iSH];
941 if (fVerbosity >= confirmations) {
942 G4cout << " Scene Handler now "
943 << fpSceneHandler -> GetName () << G4endl;
944 }
945 if (fpScene != fpSceneHandler -> GetScene ()) {
946 fpScene = fpSceneHandler -> GetScene ();
947 if (fVerbosity >= confirmations) {
948 G4cout << " Scene now \""
949 << fpScene -> GetName () << "\"" << G4endl;
950 }
951 }
952 const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
953 if (viewerList.size ()) {
954 fpViewer = viewerList [0];
955 if (fVerbosity >= confirmations) {
956 G4cout << " Viewer now " << fpViewer -> GetName () << G4endl;
957 }
958 }
959 else {
960 fpViewer = 0;
961 }
962 }
963 else {
964 fpSceneHandler = 0;
965 fpViewer = 0;
966 }
967 }
968}
969
970void G4VisManager::SetCurrentSceneHandler (G4VSceneHandler* pSceneHandler) {
971 fpSceneHandler = pSceneHandler;
972 if (fVerbosity >= confirmations) {
973 G4cout << "G4VisManager::SetCurrentSceneHandler: scene handler now \""
974 << pSceneHandler -> GetName () << "\"" << G4endl;
975 }
976 if (fpScene != fpSceneHandler -> GetScene ()) {
977 fpScene = fpSceneHandler -> GetScene ();
978 if (fVerbosity >= confirmations) {
979 G4cout << " Scene now \""
980 << fpScene -> GetName () << "\"" << G4endl;
981 }
982 }
983 if (fpGraphicsSystem != pSceneHandler -> GetGraphicsSystem ()) {
984 fpGraphicsSystem = pSceneHandler -> GetGraphicsSystem ();
985 if (fVerbosity >= confirmations) {
986 G4cout << " Graphics system now \""
987 << fpGraphicsSystem -> GetName () << "\"" << G4endl;
988 }
989 }
990 const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
991 G4int nViewers = viewerList.size ();
992 if (nViewers) {
993 G4int iViewer;
994 for (iViewer = 0; iViewer < nViewers; iViewer++) {
995 if (fpViewer == viewerList [iViewer]) break;
996 }
997 if (iViewer >= nViewers) {
998 fpViewer = viewerList [0];
999 if (fVerbosity >= confirmations) {
1000 G4cout << " Viewer now \"" << fpViewer -> GetName () << "\""
1001 << G4endl;
1002 }
1003 }
1004 IsValidView (); // Checks.
1005 }
1006 else {
1007 fpViewer = 0;
1008 if (fVerbosity >= warnings) {
1009 G4cout <<
1010 "WARNING: No viewers for this scene handler - please create one."
1011 << G4endl;
1012 }
1013 }
1014}
1015
1016void G4VisManager::SetCurrentViewer (G4VViewer* pViewer) {
1017 fpViewer = pViewer;
1018 if (fVerbosity >= confirmations) {
1019 G4cout << "G4VisManager::SetCurrentViewer: viewer now "
1020 << pViewer -> GetName ()
1021 << G4endl;
1022 }
1023 fpSceneHandler = fpViewer -> GetSceneHandler ();
1024 fpSceneHandler -> SetCurrentViewer (pViewer);
1025 fpScene = fpSceneHandler -> GetScene ();
1026 fpGraphicsSystem = fpSceneHandler -> GetGraphicsSystem ();
1027 IsValidView (); // Checks.
1028}
1029
1030void G4VisManager::RegisterMessengers () {
1031
1032 // Instantiate individual messengers/commands (often - but not
1033 // always - one command per messenger).
1034
1035 G4UIcommand* directory;
1036
1037 // Top level commands...
1038 RegisterMessenger(new G4VisCommandAbortReviewKeptEvents);
1039 RegisterMessenger(new G4VisCommandEnable);
1040 RegisterMessenger(new G4VisCommandList);
1041 RegisterMessenger(new G4VisCommandReviewKeptEvents);
1042
1043 // Compound commands...
1044 RegisterMessenger(new G4VisCommandDrawTree);
1045 RegisterMessenger(new G4VisCommandDrawView);
1046 RegisterMessenger(new G4VisCommandDrawVolume);
1047 RegisterMessenger(new G4VisCommandOpen);
1048 RegisterMessenger(new G4VisCommandSpecify);
1049
1050 directory = new G4UIdirectory ("/vis/geometry/");
1051 directory -> SetGuidance("Operations on vis attributes of Geant4 geometry.");
1052 fDirectoryList.push_back (directory);
1053 RegisterMessenger(new G4VisCommandGeometryList);
1054 RegisterMessenger(new G4VisCommandGeometryRestore);
1055
1056 directory = new G4UIdirectory ("/vis/geometry/set/");
1057 directory -> SetGuidance("Set vis attributes of Geant4 geometry.");
1058 fDirectoryList.push_back (directory);
1059 RegisterMessenger(new G4VisCommandGeometrySetColour);
1060 RegisterMessenger(new G4VisCommandGeometrySetDaughtersInvisible);
1061 RegisterMessenger(new G4VisCommandGeometrySetLineStyle);
1062 RegisterMessenger(new G4VisCommandGeometrySetLineWidth);
1063 RegisterMessenger(new G4VisCommandGeometrySetForceAuxEdgeVisible);
1064 RegisterMessenger(new G4VisCommandGeometrySetForceLineSegmentsPerCircle);
1065 RegisterMessenger(new G4VisCommandGeometrySetForceSolid);
1066 RegisterMessenger(new G4VisCommandGeometrySetForceWireframe);
1067 RegisterMessenger(new G4VisCommandGeometrySetVisibility);
1068
1069 directory = new G4UIdirectory ("/vis/scene/");
1070 directory -> SetGuidance ("Operations on Geant4 scenes.");
1071 fDirectoryList.push_back (directory);
1072 RegisterMessenger(new G4VisCommandSceneCreate);
1073 RegisterMessenger(new G4VisCommandSceneEndOfEventAction);
1074 RegisterMessenger(new G4VisCommandSceneEndOfRunAction);
1075 RegisterMessenger(new G4VisCommandSceneList);
1076 RegisterMessenger(new G4VisCommandSceneNotifyHandlers);
1077 RegisterMessenger(new G4VisCommandSceneSelect);
1078
1079 directory = new G4UIdirectory ("/vis/scene/add/");
1080 directory -> SetGuidance ("Add model to current scene.");
1081 fDirectoryList.push_back (directory);
1082 RegisterMessenger(new G4VisCommandSceneAddAxes);
1083 RegisterMessenger(new G4VisCommandSceneAddEventID);
1084 RegisterMessenger(new G4VisCommandSceneAddGhosts);
1085 RegisterMessenger(new G4VisCommandSceneAddHits);
1086 RegisterMessenger(new G4VisCommandSceneAddLogicalVolume);
1087 RegisterMessenger(new G4VisCommandSceneAddLogo);
1088 RegisterMessenger(new G4VisCommandSceneAddPSHits);
1089 RegisterMessenger(new G4VisCommandSceneAddScale);
1090 RegisterMessenger(new G4VisCommandSceneAddText);
1091 RegisterMessenger(new G4VisCommandSceneAddTrajectories);
1092 RegisterMessenger(new G4VisCommandSceneAddUserAction);
1093 RegisterMessenger(new G4VisCommandSceneAddVolume);
1094
1095 directory = new G4UIdirectory ("/vis/sceneHandler/");
1096 directory -> SetGuidance ("Operations on Geant4 scene handlers.");
1097 fDirectoryList.push_back (directory);
1098 RegisterMessenger(new G4VisCommandSceneHandlerAttach);
1099 RegisterMessenger(new G4VisCommandSceneHandlerCreate);
1100 RegisterMessenger(new G4VisCommandSceneHandlerList);
1101 RegisterMessenger(new G4VisCommandSceneHandlerSelect);
1102
1103 directory = new G4UIdirectory ("/vis/viewer/");
1104 directory -> SetGuidance ("Operations on Geant4 viewers.");
1105 fDirectoryList.push_back (directory);
1106 RegisterMessenger(new G4VisCommandViewerAddCutawayPlane);
1107 RegisterMessenger(new G4VisCommandViewerChangeCutawayPlane);
1108 RegisterMessenger(new G4VisCommandViewerClear);
1109 RegisterMessenger(new G4VisCommandViewerClearCutawayPlanes);
1110 RegisterMessenger(new G4VisCommandViewerClearTransients);
1111 RegisterMessenger(new G4VisCommandViewerClone);
1112 RegisterMessenger(new G4VisCommandViewerCreate);
1113 RegisterMessenger(new G4VisCommandViewerDolly);
1114 RegisterMessenger(new G4VisCommandViewerFlush);
1115 RegisterMessenger(new G4VisCommandViewerList);
1116 RegisterMessenger(new G4VisCommandViewerPan);
1117 RegisterMessenger(new G4VisCommandViewerRebuild);
1118 RegisterMessenger(new G4VisCommandViewerRefresh);
1119 RegisterMessenger(new G4VisCommandViewerReset);
1120 RegisterMessenger(new G4VisCommandViewerScale);
1121 RegisterMessenger(new G4VisCommandViewerSelect);
1122 RegisterMessenger(new G4VisCommandViewerUpdate);
1123 RegisterMessenger(new G4VisCommandViewerZoom);
1124
1125 directory = new G4UIdirectory ("/vis/viewer/set/");
1126 directory -> SetGuidance ("Set view parameters of current viewer.");
1127 fDirectoryList.push_back (directory);
1128 RegisterMessenger(new G4VisCommandsViewerSet);
1129
1130 // List manager commands
1131 RegisterMessenger(new G4VisCommandListManagerList< G4VisModelManager<G4VTrajectoryModel> >
1132 (fpTrajDrawModelMgr, fpTrajDrawModelMgr->Placement()));
1133 RegisterMessenger(new G4VisCommandListManagerSelect< G4VisModelManager<G4VTrajectoryModel> >
1134 (fpTrajDrawModelMgr, fpTrajDrawModelMgr->Placement()));
1135
1136 // Trajectory filter manager commands
1137 RegisterMessenger(new G4VisCommandListManagerList< G4VisFilterManager<G4VTrajectory> >
1138 (fpTrajFilterMgr, fpTrajFilterMgr->Placement()));
1139 RegisterMessenger(new G4VisCommandManagerMode< G4VisFilterManager<G4VTrajectory> >
1140 (fpTrajFilterMgr, fpTrajFilterMgr->Placement()));
1141
1142 // Hit filter manager commands
1143 RegisterMessenger(new G4VisCommandListManagerList< G4VisFilterManager<G4VHit> >
1144 (fpHitFilterMgr, fpHitFilterMgr->Placement()));
1145 RegisterMessenger(new G4VisCommandManagerMode< G4VisFilterManager<G4VHit> >
1146 (fpHitFilterMgr, fpHitFilterMgr->Placement()));
1147}
1148
1149void G4VisManager::PrintAvailableGraphicsSystems () const {
1150 G4int nSystems = fAvailableGraphicsSystems.size ();
1151 G4cout << "Current available graphics systems are:";
1152 if (nSystems) {
1153 for (int i = 0; i < nSystems; i++) {
1154 const G4VGraphicsSystem* pSystem = fAvailableGraphicsSystems [i];
1155 G4cout << "\n " << pSystem -> GetName ();
1156 if (pSystem -> GetNickname () != "") {
1157 G4cout << " (" << pSystem -> GetNickname () << ")";
1158 }
1159 }
1160 }
1161 else {
1162 G4cout << "\n NONE!!! None registered - yet! Mmmmm!";
1163 }
1164 G4cout << G4endl;
1165}
1166
1167void G4VisManager::PrintAvailableModels (Verbosity verbosity) const
1168{
1169 {
1170 //fpTrajDrawModelMgr->Print(G4cout);
1171 G4cout << "Registered model factories:" << G4endl;
1172 const std::vector<G4VModelFactory<G4VTrajectoryModel>*>& factoryList =
1173 fpTrajDrawModelMgr->FactoryList();
1174 if (factoryList.empty()) G4cout << " None" << G4endl;
1175 else {
1176 std::vector<G4VModelFactory<G4VTrajectoryModel>*>::const_iterator i;
1177 for (i = factoryList.begin(); i != factoryList.end(); ++i)
1178 (*i)->Print(G4cout);
1179 }
1180 const G4VisListManager<G4VTrajectoryModel>* listManager =
1181 fpTrajDrawModelMgr->ListManager();
1182 const std::map<G4String, G4VTrajectoryModel*>& modelMap =
1183 listManager->Map();
1184 if (!modelMap.empty()) {
1185 G4cout << "\nRegistered models:" << G4endl;
1186 std::map<G4String, G4VTrajectoryModel*>::const_iterator i;
1187 for (i = modelMap.begin(); i != modelMap.end(); ++i) {
1188 G4cout << " " << i->second->Name();
1189 if (i->second == listManager->Current()) G4cout << " (Current)";
1190 G4cout << G4endl;
1191 if (verbosity >= parameters) i->second->Print(G4cout);
1192 }
1193 }
1194 }
1195
1196 G4cout << G4endl;
1197
1198 {
1199 //fpTrajFilterMgr->Print(G4cout);
1200 G4cout << "Registered filter factories:" << G4endl;
1201 const std::vector<G4VModelFactory<G4VFilter<G4VTrajectory> >*>&
1202 factoryList = fpTrajFilterMgr->FactoryList();
1203 if (factoryList.empty()) G4cout << " None" << G4endl;
1204 else {
1205 std::vector<G4VModelFactory<G4VFilter<G4VTrajectory> >*>::const_iterator i;
1206 for (i = factoryList.begin(); i != factoryList.end(); ++i)
1207 (*i)->Print(G4cout);
1208 }
1209 const std::vector<G4VFilter<G4VTrajectory>*>&
1210 filterList = fpTrajFilterMgr->FilterList();
1211 if (!filterList.empty()) {
1212 G4cout << "\nRegistered filters:" << G4endl;
1213 std::vector<G4VFilter<G4VTrajectory>*>::const_iterator i;
1214 for (i = filterList.begin(); i != filterList.end(); ++i) {
1215 G4cout << " " << (*i)->GetName() << G4endl;
1216 if (verbosity >= parameters) (*i)->PrintAll(G4cout);
1217 }
1218 }
1219 }
1220}
1221
1222void G4VisManager::PrintInvalidPointers () const {
1223 if (fVerbosity >= errors) {
1224 G4cout << "ERROR: G4VisManager::PrintInvalidPointers:";
1225 if (!fpGraphicsSystem) {
1226 G4cout << "\n null graphics system pointer.";
1227 }
1228 else {
1229 G4cout << "\n Graphics system is " << fpGraphicsSystem -> GetName ()
1230 << " but:";
1231 if (!fpScene)
1232 G4cout <<
1233 "\n Null scene pointer. Use \"/vis/drawVolume\" or"
1234 " \"/vis/scene/create\".";
1235 if (!fpSceneHandler)
1236 G4cout <<
1237 "\n Null scene handler pointer. Use \"/vis/open\" or"
1238 " \"/vis/sceneHandler/create\".";
1239 if (!fpViewer )
1240 G4cout <<
1241 "\n Null viewer pointer. Use \"/vis/viewer/create\".";
1242 }
1243 G4cout << G4endl;
1244 }
1245}
1246
1247void G4VisManager::BeginOfRun ()
1248{
1249 //G4cout << "G4VisManager::BeginOfRun" << G4endl;
1250 fKeptLastEvent = false;
1251 fEventKeepingSuspended = false;
1252 fTransientsDrawnThisRun = false;
1253 if (fpSceneHandler) fpSceneHandler->SetTransientsDrawnThisRun(false);
1254}
1255
1256void G4VisManager::BeginOfEvent ()
1257{
1258 //G4cout << "G4VisManager::BeginOfEvent" << G4endl;
1259 fTransientsDrawnThisEvent = false;
1260 if (fpSceneHandler) fpSceneHandler->SetTransientsDrawnThisEvent(false);
1261}
1262
1263void G4VisManager::EndOfEvent ()
1264{
1265 //G4cout << "G4VisManager::EndOfEvent" << G4endl;
1266
1267 // Don't call IsValidView unless there is a scene handler. This
1268 // avoids WARNING message at end of event and run when the user has
1269 // not instantiated a scene handler, e.g., in batch mode.
1270 G4bool valid = GetConcreteInstance() && fpSceneHandler && IsValidView();
1271 if (!valid) return;
1272
1273 G4RunManager* runManager = G4RunManager::GetRunManager();
1274 const G4Run* currentRun = runManager->GetCurrentRun();
1275
1276 G4EventManager* eventManager = G4EventManager::GetEventManager();
1277 const G4Event* currentEvent = eventManager->GetConstCurrentEvent();
1278 if (!currentEvent) return;
1279
1280 ClearTransientStoreIfMarked();
1281 fpSceneHandler->DrawEvent(currentEvent);
1282
1283 G4int nEventsToBeProcessed = 0;
1284 G4int nKeptEvents = 0;
1285 G4int eventID = -2; // (If no run manager, triggers ShowView as normal.)
1286 if (currentRun) {
1287 nEventsToBeProcessed = currentRun->GetNumberOfEventToBeProcessed();
1288 eventID = currentEvent->GetEventID();
1289 const std::vector<const G4Event*>* events =
1290 currentRun->GetEventVector();
1291 if (events) nKeptEvents = events->size();
1292 }
1293
1294 if (fpScene->GetRefreshAtEndOfEvent()) {
1295
1296 // Unless last event (in which case wait end of run)...
1297 if (eventID < nEventsToBeProcessed - 1) {
1298 fpViewer->ShowView();
1299 fpSceneHandler->SetMarkForClearingTransientStore(true);
1300 } else { // Last event...
1301 // Keep, but only if user has not kept any...
1302 if (!nKeptEvents) {
1303 eventManager->KeepTheCurrentEvent();
1304 fKeptLastEvent = true;
1305 }
1306 }
1307
1308 } else { // Accumulating events...
1309
1310 G4int maxNumberOfKeptEvents = fpScene->GetMaxNumberOfKeptEvents();
1311 if (maxNumberOfKeptEvents > 0 && nKeptEvents >= maxNumberOfKeptEvents) {
1312 fEventKeepingSuspended = true;
1313 static G4bool warned = false;
1314 if (!warned) {
1315 if (fVerbosity >= warnings) {
1316 G4cout <<
1317 "WARNING: G4VisManager::EndOfEvent: Automatic event keeping suspended."
1318 "\n The number of events exceeds the maximum, "
1319 << maxNumberOfKeptEvents <<
1320 ", that can be kept by the vis manager."
1321 << G4endl;
1322 }
1323 warned = true;
1324 }
1325 } else if (maxNumberOfKeptEvents != 0) {
1326 eventManager->KeepTheCurrentEvent();
1327 }
1328 }
1329}
1330
1331void G4VisManager::EndOfRun ()
1332{
1333 //G4cout << "G4VisManager::EndOfRun" << G4endl;
1334
1335 // Don't call IsValidView unless there is a scene handler. This
1336 // avoids WARNING message at end of event and run when the user has
1337 // not instantiated a scene handler, e.g., in batch mode.
1338 G4bool valid = GetConcreteInstance() && fpSceneHandler && IsValidView();
1339 if (valid) {
1340 if (!fpSceneHandler->GetMarkForClearingTransientStore()) {
1341 if (fpScene->GetRefreshAtEndOfRun()) {
1342 fpSceneHandler->DrawEndOfRunModels();
1343 fpViewer->ShowView();
1344 fpSceneHandler->SetMarkForClearingTransientStore(true);
1345 }
1346 }
1347
1348 if (fEventKeepingSuspended && fVerbosity >= warnings) {
1349 G4cout <<
1350 "WARNING: G4VisManager::EndOfRun: Automatic event keeping has been suspended."
1351 "\n The number of events in the run exceeded the maximum, "
1352 << fpScene->GetMaxNumberOfKeptEvents() <<
1353 ", that can be kept by the vis manager." <<
1354 "\n The number of events kept by the vis manager can be changed with"
1355 "\n \"/vis/scene/endOfEventAction accumulate <N>\", where N is the"
1356 "\n maximum number you wish to allow. N < 0 means \"unlimited\"."
1357 << G4endl;
1358 }
1359 }
1360 fEventRefreshing = false;
1361
1362 G4RunManager* runManager = G4RunManager::GetRunManager();
1363 const G4Run* currentRun = runManager->GetCurrentRun();
1364
1365 G4int nKeptEvents = 0;
1366 const std::vector<const G4Event*>* events =
1367 currentRun? currentRun->GetEventVector(): 0;
1368 if (events) nKeptEvents = events->size();
1369
1370 if (nKeptEvents && !fKeptLastEvent) {
1371 if (!valid && fVerbosity >= warnings) G4cout << "WARNING: ";
1372 if (fVerbosity >= warnings) {
1373 G4cout << nKeptEvents;
1374 if (nKeptEvents == 1) G4cout << " event has";
1375 else G4cout << " events have";
1376 G4cout << " been kept for refreshing and/or reviewing." << G4endl;
1377 }
1378 static G4bool warned = false;
1379 if (!valid && fVerbosity >= warnings && !warned) {
1380 G4cout <<
1381 " Only useful if before starting the run:"
1382 "\n a) trajectories are stored (\"/vis/scene/add/trajectories [smooth|rich]\"), or"
1383 "\n b) the Draw method of any hits is implemented."
1384 "\n To view trajectories and hits:"
1385 "\n open a viewer, draw a volume, \"/vis/scene/add/trajectories\""
1386 "\n \"/vis/scene/add/hits\" and, possibly, \"/vis/viewer/flush\"."
1387 "\n To see all events: \"/vis/scene/endOfEventAction accumulate\"."
1388 "\n To see events individually: \"/vis/reviewKeptEvents\"."
1389 << G4endl;
1390 warned = true;
1391 }
1392 }
1393}
1394
1395void G4VisManager::ClearTransientStoreIfMarked(){
1396 // Assumes valid view.
1397 if (fpSceneHandler->GetMarkForClearingTransientStore()) {
1398 fpSceneHandler->SetMarkForClearingTransientStore(false);
1399 fpSceneHandler->ClearTransientStore();
1400 }
1401 // Record if transients drawn. These local flags are only set
1402 // *after* ClearTransientStore. In the code in G4VSceneHandler
1403 // triggered by ClearTransientStore, use these flags so that
1404 // event refreshing is not done too early.
1405 fTransientsDrawnThisEvent = fpSceneHandler->GetTransientsDrawnThisEvent();
1406 fTransientsDrawnThisRun = fpSceneHandler->GetTransientsDrawnThisRun();
1407}
1408
1409void G4VisManager::ResetTransientsDrawnFlags()
1410{
1411 fTransientsDrawnThisRun = false;
1412 fTransientsDrawnThisEvent = false;
1413 G4SceneHandlerListConstIterator i;
1414 for (i = fAvailableSceneHandlers.begin();
1415 i != fAvailableSceneHandlers.end(); ++i) {
1416 (*i)->SetTransientsDrawnThisEvent(false);
1417 (*i)->SetTransientsDrawnThisRun(false);
1418 }
1419}
1420
1421G4String G4VisManager::ViewerShortName (const G4String& viewerName) const {
1422 G4String viewerShortName (viewerName);
1423 viewerShortName = viewerShortName (0, viewerShortName.find (' '));
1424 return viewerShortName.strip ();
1425}
1426
1427G4VViewer* G4VisManager::GetViewer (const G4String& viewerName) const {
1428 G4String viewerShortName = ViewerShortName (viewerName);
1429 size_t nHandlers = fAvailableSceneHandlers.size ();
1430 size_t iHandler, iViewer;
1431 G4VViewer* viewer = 0;
1432 G4bool found = false;
1433 for (iHandler = 0; iHandler < nHandlers; iHandler++) {
1434 G4VSceneHandler* sceneHandler = fAvailableSceneHandlers [iHandler];
1435 const G4ViewerList& viewerList = sceneHandler -> GetViewerList ();
1436 for (iViewer = 0; iViewer < viewerList.size (); iViewer++) {
1437 viewer = viewerList [iViewer];
1438 if (viewerShortName == viewer -> GetShortName ()) {
1439 found = true;
1440 break;
1441 }
1442 }
1443 if (found) break;
1444 }
1445 if (found) return viewer;
1446 else return 0;
1447}
1448
1449std::vector<G4String> G4VisManager::VerbosityGuidanceStrings;
1450
1451G4String G4VisManager::VerbosityString(Verbosity verbosity) {
1452 G4String s;
1453 switch (verbosity) {
1454 case quiet: s = "quiet (0)"; break;
1455 case startup: s = "startup (1)"; break;
1456 case errors: s = "errors (2)"; break;
1457 case warnings: s = "warnings (3)"; break;
1458 case confirmations: s = "confirmations (4)"; break;
1459 case parameters: s = "parameters (5)"; break;
1460 case all: s = "all (6)"; break;
1461 }
1462 return s;
1463}
1464
1465G4VisManager::Verbosity
1466G4VisManager::GetVerbosityValue(const G4String& verbosityString) {
1467 G4String s(verbosityString); s.toLower();
1468 Verbosity verbosity;
1469 if (s(0) == 'q') verbosity = quiet;
1470 else if (s(0) == 's') verbosity = startup;
1471 else if (s(0) == 'e') verbosity = errors;
1472 else if (s(0) == 'w') verbosity = warnings;
1473 else if (s(0) == 'c') verbosity = confirmations;
1474 else if (s(0) == 'p') verbosity = parameters;
1475 else if (s(0) == 'a') verbosity = all;
1476 else {
1477 G4int intVerbosity;
1478 std::istringstream is(s);
1479 is >> intVerbosity;
1480 if (!is) {
1481 G4cout << "ERROR: G4VisManager::GetVerbosityValue: invalid verbosity \""
1482 << verbosityString << "\"";
1483 for (size_t i = 0; i < VerbosityGuidanceStrings.size(); ++i) {
1484 G4cout << '\n' << VerbosityGuidanceStrings[i];
1485 }
1486 verbosity = warnings;
1487 G4cout << "\n Returning " << VerbosityString(verbosity)
1488 << G4endl;
1489 }
1490 else {
1491 verbosity = GetVerbosityValue(intVerbosity);
1492 }
1493 }
1494 return verbosity;
1495}
1496
1497G4VisManager::Verbosity G4VisManager::GetVerbosityValue(G4int intVerbosity) {
1498 Verbosity verbosity;
1499 if (intVerbosity < quiet) verbosity = quiet;
1500 else if (intVerbosity > all) verbosity = all;
1501 else verbosity = Verbosity(intVerbosity);
1502 return verbosity;
1503}
1504
1505void G4VisManager::SetVerboseLevel (G4int intVerbosity) {
1506 fVerbosity = GetVerbosityValue(intVerbosity);
1507}
1508
1509void G4VisManager::SetVerboseLevel (const G4String& verbosityString) {
1510 fVerbosity = GetVerbosityValue(verbosityString);
1511}
1512
1513G4bool G4VisManager::IsValidView () {
1514
1515 if (!fInitialised) Initialise ();
1516
1517 static G4bool noGSPrinting = true;
1518 if (!fpGraphicsSystem) {
1519 // Limit printing - we do not want printing if the user simply does
1520 // not want to use graphics, e.g., in batch mode.
1521 if (noGSPrinting) {
1522 noGSPrinting = false;
1523 if (fVerbosity >= warnings) {
1524 G4cout <<
1525 "WARNING: G4VisManager::IsValidView(): Attempt to draw when no graphics system"
1526 "\n has been instantiated. Use \"/vis/open\" or \"/vis/sceneHandler/create\"."
1527 "\n Alternatively, to avoid this message, suppress instantiation of vis"
1528 "\n manager (G4VisExecutive), possibly by setting G4VIS_NONE, and ensure"
1529 "\n drawing code is executed only if G4VVisManager::GetConcreteInstance()"
1530 "\n is non-zero."
1531 << G4endl;
1532 }
1533 }
1534 return false;
1535 }
1536
1537 if ((!fpScene) || (!fpSceneHandler) || (!fpViewer)) {
1538 if (fVerbosity >= errors) {
1539 G4cout <<
1540 "ERROR: G4VisManager::IsValidView(): Current view is not valid."
1541 << G4endl;
1542 PrintInvalidPointers ();
1543 }
1544 return false;
1545 }
1546
1547 if (fpScene != fpSceneHandler -> GetScene ()) {
1548 if (fVerbosity >= errors) {
1549 G4cout << "ERROR: G4VisManager::IsValidView ():";
1550 if (fpSceneHandler -> GetScene ()) {
1551 G4cout <<
1552 "\n The current scene \""
1553 << fpScene -> GetName ()
1554 << "\" is not handled by"
1555 "\n the current scene handler \""
1556 << fpSceneHandler -> GetName ()
1557 << "\""
1558 "\n (it currently handles scene \""
1559 << fpSceneHandler -> GetScene () -> GetName ()
1560 << "\")."
1561 "\n Either:"
1562 "\n (a) attach it to the scene handler with"
1563 "\n /vis/sceneHandler/attach "
1564 << fpScene -> GetName ()
1565 << ", or"
1566 "\n (b) create a new scene handler with "
1567 "\n /vis/sceneHandler/create <graphics-system>,"
1568 "\n in which case it should pick up the the new scene."
1569 << G4endl;
1570 }
1571 else {
1572 G4cout << "\n Scene handler \""
1573 << fpSceneHandler -> GetName ()
1574 << "\" has null scene pointer."
1575 "\n Attach a scene with /vis/sceneHandler/attach [<scene-name>]"
1576 << G4endl;
1577 }
1578 }
1579 return false;
1580 }
1581
1582 const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
1583 if (viewerList.size () == 0) {
1584 if (fVerbosity >= errors) {
1585 G4cout <<
1586 "ERROR: G4VisManager::IsValidView (): the current scene handler\n \""
1587 << fpSceneHandler -> GetName ()
1588 << "\" has no viewers. Do /vis/viewer/create."
1589 << G4endl;
1590 }
1591 return false;
1592 }
1593
1594 G4bool isValid = true;
1595 if (fpScene -> IsEmpty ()) { // Add world by default if possible...
1596 G4bool warn(fVerbosity >= warnings);
1597 G4bool successful = fpScene -> AddWorldIfEmpty (warn);
1598 if (!successful || fpScene -> IsEmpty ()) { // If still empty...
1599 if (fVerbosity >= errors) {
1600 G4cout << "ERROR: G4VisManager::IsViewValid ():";
1601 G4cout <<
1602 "\n Attempt at some drawing operation when scene is empty."
1603 "\n Maybe the geometry has not yet been defined."
1604 " Try /run/initialize."
1605 << G4endl;
1606 }
1607 isValid = false;
1608 }
1609 else {
1610 G4UImanager::GetUIpointer()->ApplyCommand ("/vis/scene/notifyHandlers");
1611 if (fVerbosity >= warnings) {
1612 G4cout <<
1613 "WARNING: G4VisManager: the scene was empty, \"world\" has been"
1614 "\n added and the scene handlers notified.";
1615 G4cout << G4endl;
1616 }
1617 }
1618 }
1619 if (isValid) SetConcreteInstance(this);
1620 return isValid;
1621}
1622
1623void
1624G4VisManager::RegisterModelFactories()
1625{
1626 if (fVerbosity >= warnings) {
1627 G4cout<<"G4VisManager: No model factories registered with G4VisManager."<<G4endl;
1628 G4cout<<"G4VisManager::RegisterModelFactories() should be overridden in derived"<<G4endl;
1629 G4cout<<"class. See G4VisExecutive for an example."<<G4endl;
1630 }
1631}
Note: See TracBrowser for help on using the repository browser.