G4VisManager.hh

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // 
00030 
00031 // Class Description:
00032 //
00033 // The GEANT4 Visualization Manager - John Allison 02/Jan/1996.
00034 //
00035 // G4VisManager is a "Singleton", i.e., only one instance of it or any
00036 // derived class may exist.  A G4Exception is thrown if an attempt is
00037 // made to instantiate more than one.
00038 //
00039 // It is also an abstract class, so the user must derive his/her own
00040 // class from G4VisManager, implement the pure virtual function
00041 // RegisterGraphicsSystems, and instantiate an object of the derived
00042 // class - for an example see
00043 // visualization/include/G4VisExecutive.hh/icc.
00044 //
00045 // The recommended way for users to obtain a pointer to the vis
00046 // manager is with G4VVisManager::GetConcreteInstance (), being always
00047 // careful to test for non-zero.  This pointer is non-zero only when
00048 // (a) an object of the derived class exists and (b) when there is a
00049 // valid viewer available.
00050 //
00051 // Graphics system registration is normally done through the protected
00052 // pure virtual function RegisterGraphicsSystems called from
00053 // Initialise ().  You can also use the public function
00054 // RegisterGraphicsSystem (new MyGraphicsSystem) if you have your own
00055 // graphics system. A graphics system is, in effect, a factory for
00056 // scene handlers and viewers.
00057 //
00058 // The VisManager creates and manages graphics systems, scenes, scene
00059 // handlers, viewers and some models and model makers.  You can have
00060 // any number.  It has the concept of a "current viewer", and the
00061 // "current scene handler", the "current scene" and the "current
00062 // graphics system" which go with it.  You can select the current
00063 // viewer.  Most of the the operations of the VisManager take place
00064 // with the current viewer, in particular, the Draw operations.
00065 //
00066 // Each scene comprises drawable objects such as detector components
00067 // and trajectories, hits and digis when appropriate.  A scene handler
00068 // translates a scene into graphics-system-specific function calls
00069 // and, possibly, a graphics-system-dependent database - display
00070 // lists, scene graphs, etc.  Each viewer has its "view parameters"
00071 // (see class description of G4ViewParameters for available parameters
00072 // and also for a description of the concept of a "standard view" and
00073 // all that).
00074 //
00075 // A friend class G4VisStateDependent is "state dependent", i.e., it
00076 // is notified on change of state (G4ApplicationState).  This is used
00077 // to message the G4VisManager to draw hits, digis and trajectories in
00078 // the current scene at the end of event, as required.
00079 
00080 #ifndef G4VISMANAGER_HH
00081 #define G4VISMANAGER_HH
00082 
00083 #include "G4VVisManager.hh"
00084 
00085 #include "globals.hh"
00086 #include "G4GraphicsSystemList.hh"
00087 #include "G4ModelingParameters.hh"
00088 #include "G4NullModel.hh"
00089 #include "G4SceneHandlerList.hh"
00090 #include "G4SceneList.hh"
00091 #include "G4TrajectoriesModel.hh"
00092 #include "G4Transform3D.hh"
00093 #include "G4UImessenger.hh"
00094 
00095 #include <iostream>
00096 #include <vector>
00097 #include <map>
00098 
00099 class G4Scene;
00100 class G4UIcommand;
00101 class G4UImessenger;
00102 class G4VisStateDependent;
00103 class G4VTrajectoryModel;
00104 class G4VUserVisAction;
00105 template <typename> class G4VFilter;
00106 template <typename> class G4VisFilterManager;
00107 template <typename> class G4VisModelManager;
00108 template <typename> class G4VModelFactory;
00109 class G4Event;
00110 
00111 // Useful typedef's
00112 typedef G4VModelFactory<G4VTrajectoryModel> G4TrajDrawModelFactory;
00113 typedef G4VModelFactory<G4VFilter<G4VTrajectory> > G4TrajFilterFactory;
00114 typedef G4VModelFactory<G4VFilter<G4VHit> > G4HitFilterFactory;
00115 typedef G4VModelFactory<G4VFilter<G4VDigi> > G4DigiFilterFactory;
00116 
00117 class G4VisManager: public G4VVisManager {
00118 
00119   // Friends - classes and functions which need access to private
00120   // members of G4VisManager.  This is mainly to obtain access to
00121   // GetInstance (), which is private.  The correct way for normal
00122   // users to obtain a pointer to the vis manager is with
00123   // G4VVisManager::GetConcreteInstance (), always testing for
00124   // non-zero.
00125 
00126   // Odd friends that need access to the G4VisManager...
00127   friend class G4RTSteppingAction;
00128   friend class G4RayTrajectory;
00129   friend class G4RayTracerSceneHandler;
00130   friend class G4RTMessenger;
00131   friend class G4OpenGLViewerMessenger;
00132   friend class G4OpenGLXmViewerMessenger;
00133   friend class G4HepRepFileSceneHandler;
00134 
00135   // Management friends...
00136   friend class G4VSceneHandler;
00137   friend class G4VViewer;
00138   friend class G4VisStateDependent;
00139   friend class G4VisCommandList;
00140 
00141   // operator << friends...
00142   friend std::ostream& operator << (std::ostream&, const G4VGraphicsSystem&);
00143   friend std::ostream& operator << (std::ostream&, const G4VSceneHandler&);
00144 
00145 public: // With description
00146 
00147   enum Verbosity {
00148     quiet,         // Nothing is printed.
00149     startup,       // Startup and endup messages are printed...
00150     errors,        // ...and errors...
00151     warnings,      // ...and warnings...
00152     confirmations, // ...and confirming messages...
00153     parameters,    // ...and parameters of scenes and views...
00154     all            // ...and everything available.
00155   };
00156   // Simple graded message scheme.
00157 
00158 protected: // With description
00159 
00160   G4VisManager (const G4String& verbosityString = "warnings");
00161   // The constructor is protected so that an object of the derived
00162   // class may be constructed.
00163 
00164 public: // With description
00165 
00166   virtual ~G4VisManager ();
00167 
00168 private:
00169 
00170   // Private copy constructor and assigment operator - copying and
00171   // assignment not allowed.  Keeps CodeWizard happy.
00172   G4VisManager (const G4VisManager&);
00173   G4VisManager& operator = (const G4VisManager&);
00174 
00175   static G4VisManager* GetInstance ();
00176   // Returns pointer to itself.  Throws a G4Exception if called before
00177   // instantiation.  Private so that only friends can use; the normal
00178   // user should instead use G4VVisManager::GetConcreteInstance () to
00179   // get a "higher level" pointer for general use - but always test
00180   // for non-zero.
00181 
00182 public: // With description
00183 
00184   void Initialise ();
00185   void Initialize ();  // Alias Initialise ().
00186 
00187   // Optional registration of user vis actions.  Added to scene with
00188   // /vis/scene/add/userAction.
00189   void RegisterRunDurationUserVisAction
00190   (const G4String& name, G4VUserVisAction*,
00191    const G4VisExtent& = G4VisExtent::NullExtent);
00192   void RegisterEndOfEventUserVisAction
00193   (const G4String& name, G4VUserVisAction*,
00194    const G4VisExtent& = G4VisExtent::NullExtent);
00195   void RegisterEndOfRunUserVisAction
00196   (const G4String& name, G4VUserVisAction*,
00197    const G4VisExtent& = G4VisExtent::NullExtent);
00198 
00199   G4bool RegisterGraphicsSystem (G4VGraphicsSystem*);
00200   // Register an individual graphics system.  Normally this is done in
00201   // a sub-class implementation of the protected virtual function,
00202   // RegisterGraphicsSystems.  See, e.g., G4VisExecutive.icc.
00203 
00204   void RegisterModelFactory(G4TrajDrawModelFactory* factory);
00205   // Register trajectory draw model factory. Assumes ownership of factory.
00206 
00207   void RegisterModel(G4VTrajectoryModel* model);
00208   // Register trajectory model. Assumes ownership of model.
00209 
00210   void RegisterModelFactory(G4TrajFilterFactory* factory);
00211   // Register trajectory filter model factory. Assumes ownership of factory.
00212 
00213   void RegisterModel(G4VFilter<G4VTrajectory>* filter);
00214   // Register trajectory filter model. Assumes ownership of model.
00215 
00216   void RegisterModelFactory(G4HitFilterFactory* factory);
00217   // Register trajectory hit model factory. Assumes ownership of factory.
00218 
00219   void RegisterModel(G4VFilter<G4VHit>* filter);
00220   // Register trajectory hit model. Assumes ownership of model.
00221 
00222   void RegisterModelFactory(G4DigiFilterFactory* factory);
00223   // Register trajectory digi model factory. Assumes ownership of factory.
00224 
00225   void RegisterModel(G4VFilter<G4VDigi>* filter);
00226   // Register trajectory digi model. Assumes ownership of model.
00227 
00228   void SelectTrajectoryModel(const G4String& model);
00229   // Set default trajectory model. Useful for use in compiled code
00230 
00231   void RegisterMessenger(G4UImessenger* messenger);
00232   // Register messenger. Assumes ownership of messenger.
00233 
00235   // Now functions that implement the pure virtual functions of
00236   // G4VVisManager for drawing various visualization primitives, useful
00237   // for representing hits, digis, etc.
00238 
00239   void Draw (const G4Circle&,
00240     const G4Transform3D& objectTransformation = G4Transform3D());
00241 
00242   void Draw (const G4NURBS&,
00243     const G4Transform3D& objectTransformation = G4Transform3D());
00244 
00245   void Draw (const G4Polyhedron&,
00246     const G4Transform3D& objectTransformation = G4Transform3D());
00247 
00248   void Draw (const G4Polyline&,
00249     const G4Transform3D& objectTransformation = G4Transform3D());
00250 
00251   void Draw (const G4Polymarker&,
00252     const G4Transform3D& objectTransformation = G4Transform3D());
00253 
00254   void Draw (const G4Scale&,
00255     const G4Transform3D& objectTransformation = G4Transform3D());
00256 
00257   void Draw (const G4Square&,
00258     const G4Transform3D& objectTransformation = G4Transform3D());
00259 
00260   void Draw (const G4Text&,
00261     const G4Transform3D& objectTransformation = G4Transform3D());
00262 
00263   void Draw2D (const G4Circle&,
00264     const G4Transform3D& objectTransformation = G4Transform3D());
00265 
00266   void Draw2D (const G4NURBS&,
00267     const G4Transform3D& objectTransformation = G4Transform3D());
00268 
00269   void Draw2D (const G4Polyhedron&,
00270     const G4Transform3D& objectTransformation = G4Transform3D());
00271 
00272   void Draw2D (const G4Polyline&,
00273     const G4Transform3D& objectTransformation = G4Transform3D());
00274 
00275   void Draw2D (const G4Polymarker&,
00276     const G4Transform3D& objectTransformation = G4Transform3D());
00277 
00278   void Draw2D (const G4Square&,
00279     const G4Transform3D& objectTransformation = G4Transform3D());
00280 
00281   void Draw2D (const G4Text&,
00282     const G4Transform3D& objectTransformation = G4Transform3D());
00283 
00285   // Now functions that implement the pure virtual functions of
00286   // G4VVisManager for drawing a GEANT4 object.  Note that the
00287   // visualization attributes needed in some cases override any
00288   // visualization attributes that are associated with the object
00289   // itself - thus you can, for example, change the colour of a
00290   // physical volume.
00291 
00292   void Draw (const G4VHit&);
00293 
00294   void Draw (const G4VDigi&);
00295 
00296   void Draw (const G4VTrajectory&, G4int i_mode);
00297   // i_mode is a parameter that can be used to control the drawing of
00298   // the trajectory.  See, e.g., G4VTrajectory::DrawTrajectory.
00299   // i_mode defaults to 0 by inheritance from G4VVisManager.
00300 
00301   void Draw (const G4LogicalVolume&, const G4VisAttributes&,
00302     const G4Transform3D& objectTransformation = G4Transform3D());
00303 
00304   void Draw (const G4VPhysicalVolume&, const G4VisAttributes&,
00305     const G4Transform3D& objectTransformation = G4Transform3D());
00306 
00307   void Draw (const G4VSolid&, const G4VisAttributes&,
00308     const G4Transform3D& objectTransformation = G4Transform3D());
00309 
00311   // Optional methods that you may use to bracket a series of Draw
00312   // messages that have identical objectTransformation to improve
00313   // drawing speed.  Use Begin/EndDraw for a series of Draw messages,
00314   // Begin/EndDraw2D for a series of Draw2D messages.  Do not mix Draw
00315   // and Draw2D messages.
00316 
00317   void BeginDraw
00318   (const G4Transform3D& objectTransformation = G4Transform3D());
00319 
00320   void EndDraw ();
00321 
00322   void BeginDraw2D
00323   (const G4Transform3D& objectTransformation = G4Transform3D());
00324 
00325   void EndDraw2D ();
00326 
00328   // Now other pure virtual functions of G4VVisManager...
00329 
00330   void GeometryHasChanged ();
00331   // Used by run manager to notify change.
00332 
00333   void NotifyHandlers();
00334   // Notify scene handlers (G4VGraphicsScene objects) that the scene
00335   // has changed so that they may rebuild their graphics database, if
00336   // any, and redraw all views.
00337 
00338   void DispatchToModel(const G4VTrajectory&);
00339   void DispatchToModel(const G4VTrajectory&, G4int i_mode);
00340   // Draw the trajectory.
00341 
00342   G4bool FilterTrajectory(const G4VTrajectory&);
00343   G4bool FilterHit(const G4VHit&);
00344   G4bool FilterDigi(const G4VDigi&);
00345 
00347   // Administration routines.
00348 
00349   void CreateSceneHandler (G4String name = "");
00350   // Creates scene handler for the current system.
00351 
00352   void CreateViewer  (G4String name = "",G4String XGeometry = "");
00353   // Creates viewer for the current scene handler.
00354 
00355 private:
00356 
00357   void BeginOfRun ();
00358 
00359   void BeginOfEvent ();
00360 
00361   void EndOfEvent ();
00362   // This is called on change of state (G4ApplicationState).  It is
00363   // used to draw hits, digis and trajectories if included in the
00364   // current scene at the end of event, as required.
00365 
00366   void EndOfRun ();
00367 
00368 public: // With description
00369 
00371   // Access functions.
00372 
00373   void Enable();
00374   void Disable();
00375   // Global enable/disable functions.
00376 
00377   const G4VTrajectoryModel* CurrentTrajDrawModel() const;
00378 
00379   struct UserVisAction {
00380     UserVisAction(const G4String& name, G4VUserVisAction* pUserVisAction)
00381       :fName(name), fpUserVisAction(pUserVisAction) {}
00382     G4String fName;
00383     G4VUserVisAction* fpUserVisAction;
00384   };
00385   const std::vector<UserVisAction>& GetRunDurationUserVisActions () const;
00386   const std::vector<UserVisAction>& GetEndOfEventUserVisActions  () const;
00387   const std::vector<UserVisAction>& GetEndOfRunUserVisActions    () const;
00388   const std::map<G4VUserVisAction*,G4VisExtent>& GetUserVisActionExtents () const;
00389   G4VGraphicsSystem*           GetCurrentGraphicsSystem    () const;
00390   G4Scene*                     GetCurrentScene             () const;
00391   G4VSceneHandler*             GetCurrentSceneHandler      () const;
00392   G4VViewer*                   GetCurrentViewer            () const;
00393   const G4GraphicsSystemList&  GetAvailableGraphicsSystems ();
00394   // The above is non-const because it checks and updates the List by
00395   // calling RegisterGraphicsSystems() if no graphics systems are
00396   // already registered.
00397   const G4SceneHandlerList&    GetAvailableSceneHandlers   () const;
00398   const G4SceneList&           GetSceneList                () const;
00399   static Verbosity             GetVerbosity                ();
00400   G4bool                       GetTransientsDrawnThisRun   () const;
00401   G4bool                       GetTransientsDrawnThisEvent () const;
00402   const G4Event*               GetRequestedEvent           () const;
00403   G4bool                       GetAbortReviewKeptEvents    () const;
00404   const G4ViewParameters&      GetDefaultViewParameters    () const;
00405 
00406   void SetUserAction
00407   (G4VUserVisAction* pVisAction,
00408    const G4VisExtent& = G4VisExtent::NullExtent);  // Register run-duration.
00409   void SetUserActionExtent (const G4VisExtent&);  //Legacy: deprecated.
00410   void              SetCurrentGraphicsSystem    (G4VGraphicsSystem*);
00411   void              SetCurrentScene             (G4Scene*);
00412   void              SetCurrentSceneHandler      (G4VSceneHandler*);
00413   void              SetCurrentViewer            (G4VViewer*);
00414   G4SceneHandlerList& SetAvailableSceneHandlers ();  // Returns lvalue.
00415   G4SceneList&      SetSceneList                ();  // Returns lvalue.
00416   void              SetVerboseLevel             (G4int);
00417   void              SetVerboseLevel             (const G4String&);
00418   void              SetVerboseLevel             (Verbosity);
00419   void              SetEventRefreshing          (G4bool);
00420   void              ResetTransientsDrawnFlags   ();
00421   // If non-zero, requested event is used in G4VSceneHandler::ProcessScene.
00422   void              SetRequestedEvent           (const G4Event*);
00423   void              SetAbortReviewKeptEvents    (G4bool);
00424   void              SetDefaultViewParameters    (const G4ViewParameters&);
00425 
00427   // Utility functions.
00428 
00429   G4String ViewerShortName (const G4String& viewerName) const;
00430   // Returns shortened version of viewer name, i.e., up to first space,
00431   // if any.
00432 
00433   G4VViewer* GetViewer (const G4String& viewerName) const;
00434   // Returns zero if not found.  Can use long or short name, but find
00435   // is done on short name.
00436 
00437   static Verbosity GetVerbosityValue(const G4String&);
00438   // Returns verbosity given a string.  (Uses first character only.)
00439 
00440   static Verbosity GetVerbosityValue(G4int);
00441   // Returns verbosity given an integer.  If integer is out of range,
00442   // selects verbosity at extreme of range.
00443 
00444   static G4String VerbosityString(Verbosity);
00445   // Converts the verbosity into a string for suitable for printing.
00446   
00447   static std::vector<G4String> VerbosityGuidanceStrings;
00448   // Guidance on the use of visualization verbosity.
00449 
00450 protected:
00451 
00452   virtual void RegisterGraphicsSystems () = 0;
00453   // The sub-class must implement and make successive calls to
00454   // RegisterGraphicsSystem.
00455 
00456   virtual void RegisterModelFactories();
00457   // Sub-class must register desired models
00458 
00459   void RegisterMessengers              ();   // Command messengers.
00460 
00461   const G4int           fVerbose;
00462   // fVerbose is kept for backwards compatibility for some user
00463   // examples.  (It is used in the derived user vis managers to print
00464   // available graphics systems.)  It is initialised to 1 in the
00465   // constructor and cannot be changed.
00466 
00467   void PrintAvailableGraphicsSystems   () const;
00468 
00469 private:
00470 
00471   // Function templates to implement the Draw methods (to avoid source
00472   // code duplication).
00473   template <class T> void DrawT
00474   (const T& graphics_primitive, const G4Transform3D& objectTransform);
00475   template <class T> void DrawT2D
00476   (const T& graphics_primitive, const G4Transform3D& objectTransform);
00477 
00478   void PrintAvailableModels            (Verbosity) const;
00479   void PrintAvailableColours           (Verbosity) const;
00480   void PrintAvailableUserVisActions   (Verbosity) const;
00481   void PrintInvalidPointers            () const;
00482   G4bool IsValidView ();
00483   // True if view is valid.  Prints messages and sanitises various data.
00484   void ClearTransientStoreIfMarked();
00485   // Clears transient store of current scene handler if it is marked
00486   // for clearing.  Assumes view is valid.
00487 
00488   static G4VisManager*  fpInstance;         // Pointer to single instance. 
00489   G4bool                fInitialised;
00490   std::vector<UserVisAction> fRunDurationUserVisActions;
00491   std::vector<UserVisAction> fEndOfEventUserVisActions;
00492   std::vector<UserVisAction> fEndOfRunUserVisActions;
00493   std::map<G4VUserVisAction*,G4VisExtent> fUserVisActionExtents;
00494   G4VGraphicsSystem*    fpGraphicsSystem;   // Current graphics system.
00495   G4Scene*              fpScene;            // Current scene.
00496   G4VSceneHandler*      fpSceneHandler;     // Current scene handler.
00497   G4VViewer*            fpViewer;           // Current viewer.
00498   G4GraphicsSystemList  fAvailableGraphicsSystems;
00499   G4SceneList           fSceneList;
00500   G4SceneHandlerList    fAvailableSceneHandlers;
00501   static Verbosity            fVerbosity;
00502   std::vector<G4UImessenger*> fMessengerList;
00503   std::vector<G4UIcommand*>   fDirectoryList;
00504   G4VisStateDependent*  fpStateDependent;   // Friend state dependent class.
00505   G4TrajectoriesModel   dummyTrajectoriesModel;  // For passing drawing mode.
00506   G4bool                fEventRefreshing;
00507   G4bool                fTransientsDrawnThisRun;
00508   G4bool                fTransientsDrawnThisEvent;
00509   G4bool                fEventKeepingSuspended;
00510   G4bool                fKeptLastEvent;
00511   const G4Event*        fpRequestedEvent; // If non-zero, scene handler uses.
00512   G4bool                fAbortReviewKeptEvents;
00513   G4ViewParameters      fDefaultViewParameters;
00514   G4bool                fIsDrawGroup;
00515   G4int                 fDrawGroupNestingDepth;
00516 
00517   // Trajectory draw model manager
00518   G4VisModelManager<G4VTrajectoryModel>* fpTrajDrawModelMgr;
00519   
00520   // Trajectory filter model manager
00521   G4VisFilterManager<G4VTrajectory>* fpTrajFilterMgr;
00522 
00523   // Hit filter model manager
00524   G4VisFilterManager<G4VHit>* fpHitFilterMgr;
00525 
00526   // Digi filter model manager
00527   G4VisFilterManager<G4VDigi>* fpDigiFilterMgr;
00528 
00529 };
00530 
00531 #include "G4VisManager.icc"
00532 
00533 #endif

Generated on Mon May 27 17:50:16 2013 for Geant4 by  doxygen 1.4.7