G4VSceneHandler.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 // John Allison  19th July 1996.
00031 //
00032 // Class description
00033 //
00034 // Abstract interface class for graphics scene handlers.
00035 // Inherits from G4VGraphicsScene, in the intercoms category, which is
00036 // a minimal abstract interface for the GEANT4 kernel.
00037 
00038 #ifndef G4VSCENEHANDLER_HH
00039 #define G4VSCENEHANDLER_HH
00040 
00041 #include "globals.hh"
00042 
00043 #include "G4VGraphicsScene.hh"
00044 #include "G4ViewerList.hh"
00045 #include "G4ViewParameters.hh"
00046 #include "G4THitsMap.hh"
00047 
00048 class G4Scene;
00049 class G4VViewer;
00050 class G4Colour;
00051 class G4Visible;
00052 class G4ModelingParameters;
00053 class G4VModel;
00054 class G4VGraphicsSystem;
00055 class G4LogicalVolume;
00056 class G4VPhysicalVolume;
00057 class G4Material;
00058 class G4Event;
00059 class G4AttHolder;
00060 
00061 class G4VSceneHandler: public G4VGraphicsScene {
00062 
00063   friend class G4VViewer;
00064   friend std::ostream& operator << (std::ostream& os, const G4VSceneHandler& s);
00065 
00066 public: // With description
00067 
00068   enum MarkerSizeType {world, screen};
00069 
00070   G4VSceneHandler (G4VGraphicsSystem& system,
00071                    G4int id,
00072                    const G4String& name = "");
00073 
00074   virtual ~G4VSceneHandler ();
00075 
00077   // Methods for adding raw GEANT4 objects to the scene handler.  They
00078   // must always be called in the triplet PreAddSolid, AddSolid and
00079   // PostAddSolid.  The transformation and visualization attributes
00080   // must be set by the call to PreAddSolid.  If your graphics system
00081   // is sophisticated enough to handle a particular solid shape as a
00082   // primitive, in your derived class write a function to override one
00083   // or more of the following.  See the implementation of
00084   // G4VSceneHandler::AddSolid (const G4Box& box) for more
00085   // suggestions.  If not, please implement the base class invocation.
00086 
00087   virtual void PreAddSolid (const G4Transform3D& objectTransformation,
00088                             const G4VisAttributes&);
00089   // objectTransformation is the transformation in the world
00090   // coordinate system of the object about to be added, and visAttribs
00091   // is its visualization attributes.
00092   // IMPORTANT: invoke this from your polymorphic versions, e.g.:
00093   // void MyXXXSceneHandler::PreAddSolid
00094   //  (const G4Transform3D& objectTransformation,
00095   //   const G4VisAttributes& visAttribs) {
00096   //   G4VSceneHandler::PreAddSolid (objectTransformation, visAttribs);
00097   //   ...
00098   // }
00099 
00100   virtual void PostAddSolid ();
00101   // IMPORTANT: invoke this from your polymorphic versions, e.g.:
00102   // void MyXXXSceneHandler::PostAddSolid () {
00103   //   ...
00104   //   G4VSceneHandler::PostAddSolid ();
00105   // }
00106 
00107   virtual void AddSolid (const G4Box&);
00108   virtual void AddSolid (const G4Cons&);
00109   virtual void AddSolid (const G4Tubs&);
00110   virtual void AddSolid (const G4Trd&);
00111   virtual void AddSolid (const G4Trap&);
00112   virtual void AddSolid (const G4Sphere&);
00113   virtual void AddSolid (const G4Para&);
00114   virtual void AddSolid (const G4Torus&);
00115   virtual void AddSolid (const G4Polycone&);
00116   virtual void AddSolid (const G4Polyhedra&);
00117   virtual void AddSolid (const G4VSolid&);  // For solids not above.
00118 
00120   // Methods for adding "compound" GEANT4 objects to the scene
00121   // handler.  These methods may either (a) invoke "user code" that
00122   // uses the "user interface", G4VVisManager (see, for example,
00123   // G4VSceneHandler, which for trajectories uses
00124   // G4VTrajectory::DrawTrajectory, via G4TrajectoriesModel in the
00125   // Modeling Category) or (b) invoke AddPrimitives below (between
00126   // calls to Begin/EndPrimitives) or (c) use graphics-system-specific
00127   // code or (d) any combination of the above.
00128 
00129   virtual void AddCompound (const G4VTrajectory&);
00130   virtual void AddCompound (const G4VHit&);
00131   virtual void AddCompound (const G4VDigi&);
00132   virtual void AddCompound (const G4THitsMap<G4double>&);
00133 
00135   // Functions for adding primitives.
00136 
00137   virtual void BeginModeling ();
00138   // IMPORTANT: invoke this from your polymorphic versions, e.g.:
00139   // void MyXXXSceneHandler::BeginModeling () {
00140   //   G4VSceneHandler::BeginModeling ();
00141   //   ...
00142   // }
00143 
00144   virtual void EndModeling ();
00145   // IMPORTANT: invoke this from your polymorphic versions, e.g.:
00146   // void MyXXXSceneHandler::EndModeling () {
00147   //   ...
00148   //   G4VSceneHandler::EndModeling ();
00149   // }
00150 
00151   virtual void BeginPrimitives
00152   (const G4Transform3D& objectTransformation);
00153   // IMPORTANT: invoke this from your polymorphic versions, e.g.:
00154   // void MyXXXSceneHandler::BeginPrimitives
00155   // (const G4Transform3D& objectTransformation) {
00156   //   G4VSceneHandler::BeginPrimitives (objectTransformation);
00157   //   ...
00158   // }
00159 
00160   virtual void EndPrimitives ();
00161   // IMPORTANT: invoke this from your polymorphic versions, e.g.:
00162   // void MyXXXSceneHandler::EndPrimitives () {
00163   //   ...
00164   //   G4VSceneHandler::EndPrimitives ();
00165   // }
00166 
00167   virtual void BeginPrimitives2D
00168   (const G4Transform3D& objectTransformation);
00169   // The x,y coordinates of the primitives passed to AddPrimitive are
00170   // intrepreted as screen coordinates, -1 < x,y < 1.  The
00171   // z-coordinate is ignored.
00172   // IMPORTANT: invoke this from your polymorphic versions, e.g.:
00173   // void MyXXXSceneHandler::BeginPrimitives2D
00174   // (const G4Transform3D& objectTransformation) {
00175   //   G4VSceneHandler::BeginPrimitives2D ();
00176   //   ...
00177   // }
00178 
00179   virtual void EndPrimitives2D ();
00180   // IMPORTANT: invoke this from your polymorphic versions, e.g.:
00181   // void MyXXXSceneHandler::EndPrimitives2D () {
00182   //   ...
00183   //   G4VSceneHandler::EndPrimitives2D ();
00184   // }
00185 
00186   virtual void AddPrimitive (const G4Polyline&)   = 0;
00187   virtual void AddPrimitive (const G4Scale&);
00188   // Default implementation in this class but can be over-ridden.
00189   virtual void AddPrimitive (const G4Text&)       = 0;
00190   virtual void AddPrimitive (const G4Circle&)     = 0;      
00191   virtual void AddPrimitive (const G4Square&)     = 0;      
00192   virtual void AddPrimitive (const G4Polymarker&);
00193   // Default implementation in this class but can be over-ridden.
00194   virtual void AddPrimitive (const G4Polyhedron&) = 0;  
00195   virtual void AddPrimitive (const G4NURBS&)      = 0;       
00196 
00198   // Access functions.
00199   const G4String&     GetName           () const;
00200   G4int               GetSceneHandlerId () const;
00201   G4int               GetViewCount      () const;
00202   G4VGraphicsSystem*  GetGraphicsSystem () const;
00203   G4Scene*            GetScene          () const;
00204   const G4ViewerList& GetViewerList     () const;
00205   G4VModel*           GetModel          () const;
00206   G4VViewer*          GetCurrentViewer  () const;
00207   G4bool              GetMarkForClearingTransientStore () const;
00208   G4bool              IsReadyForTransients () const;
00209   G4bool              GetTransientsDrawnThisEvent () const;
00210   G4bool              GetTransientsDrawnThisRun   () const;
00211   const G4Transform3D& GetObjectTransformation    () const;
00212   void                SetName          (const G4String&);
00213   void          SetCurrentViewer (G4VViewer*);
00214   virtual void        SetScene         (G4Scene*);
00215   G4ViewerList& SetViewerList    ();  // Non-const so you can change.
00216   void          SetModel         (G4VModel*);
00217   void          SetMarkForClearingTransientStore (G4bool);
00218   // Sets flag which will cause transient store to be cleared at the
00219   // next call to BeginPrimitives().  Maintained by vis manager.
00220   void          SetTransientsDrawnThisEvent      (G4bool);
00221   void          SetTransientsDrawnThisRun        (G4bool);
00222   void          SetObjectTransformation          (const G4Transform3D&);
00223   // Maintained by vis manager.
00224 
00226   // Public utility functions.
00227 
00228   const G4Colour& GetColour (const G4Visible&);
00229   const G4Colour& GetColor  (const G4Visible&);
00230   // Returns colour of G4Visible object, or default global colour.
00231 
00232   const G4Colour& GetTextColour (const G4Text&);
00233   const G4Colour& GetTextColor  (const G4Text&);
00234   // Returns colour of G4Text object, or default text colour.
00235 
00236   G4double GetLineWidth(const G4VisAttributes*);
00237   // Returns line width of G4VisAttributes multiplied by GlobalLineWidthScale.
00238 
00239   G4ViewParameters::DrawingStyle GetDrawingStyle (const G4VisAttributes*);
00240   // Returns drawing style from current view parameters, unless the user
00241   // has forced through the vis attributes, thereby over-riding the
00242   // current view parameter.
00243 
00244   G4bool GetAuxEdgeVisible (const G4VisAttributes*);
00245   // Returns auxiliary edge visibility from current view parameters,
00246   // unless the user has forced through the vis attributes, thereby
00247   // over-riding the current view parameter.
00248 
00249   G4int GetNoOfSides(const G4VisAttributes*);
00250   // Returns no. of sides (lines segments per circle) from current
00251   // view parameters, unless the user has forced through the vis
00252   // attributes, thereby over-riding the current view parameter.
00253 
00254   G4double GetMarkerSize (const G4VMarker&, MarkerSizeType&);
00255   // Returns applicable marker size (diameter) and type (in second
00256   // argument).  Uses global default marker if marker sizes are not
00257   // set.  Multiplies by GlobalMarkerScale.
00258 
00259   G4double GetMarkerDiameter (const G4VMarker&, MarkerSizeType&);
00260   // Alias for GetMarkerSize.
00261 
00262   G4double GetMarkerRadius (const G4VMarker&, MarkerSizeType&);
00263   // GetMarkerSize / 2.
00264 
00265   G4ModelingParameters* CreateModelingParameters ();
00266   // Only the scene handler and view know what the Modeling Parameters should
00267   // be.  For historical reasons, the GEANT4 Visualization Environment
00268   // maintains its own Scene Data and View Parameters, which must be
00269   // converted, when needed, to Modeling Parameters.
00270 
00271   void DrawEvent(const G4Event*);
00272   // Checks scene's end-of-event model list and draws trajectories,
00273   // hits, etc.
00274 
00275   void DrawEndOfRunModels();
00276   // Draws end-of-run models.
00277 
00279   // Administration functions.
00280 
00281   G4int IncrementViewCount ();
00282 
00283   virtual void ClearStore ();
00284   // Clears graphics database (display lists) if any.
00285 
00286   virtual void ClearTransientStore ();
00287   // Clears transient part of graphics database (display lists) if any.
00288 
00289   void AddViewerToList      (G4VViewer* pView);  // Add view to view List.
00290   void RemoveViewerFromList (G4VViewer* pView);  // Remove view from view List.
00291 
00292 protected:
00293 
00295   // Core routine for looping over models, redrawing stored events, etc.
00296   // Overload with care (see, for example,
00297   // G4OpenGLScenehandler::ProcessScene).
00298   virtual void ProcessScene ();
00299 
00301   // Default routine used by default AddSolid ().
00302   virtual void RequestPrimitives (const G4VSolid& solid);
00303 
00305   // Other internal routines...
00306 
00307   virtual G4VSolid* CreateSectionSolid ();
00308   virtual G4VSolid* CreateCutawaySolid ();
00309   // Generic clipping using the BooleanProcessor in graphics_reps is
00310   // implemented in this class.  Subclasses that implement their own
00311   // clipping should provide an override that returns zero.
00312 
00313   void LoadAtts(const G4Visible&, G4AttHolder*);
00314   // Load G4AttValues and G4AttDefs associated with the G4Visible
00315   // object onto the G4AttHolder object.  It checks fpModel, and also
00316   // loads the G4AttValues and G4AttDefs from G4PhysicalVolumeModel,
00317   // G4VTrajectory, G4VTrajectoryPoint, G4VHit or G4VDigi, as
00318   // appropriate.  The G4AttHolder object is an object of a class that
00319   // publicly inherits G4AttHolder - see, e.g., SoG4Polyhedron in the
00320   // Open Inventor driver.  G4AttHolder deletes G4AttValues in its
00321   // destructor to ensure proper clean-up of G4AttValues.
00322 
00324   // Data members
00325 
00326   G4VGraphicsSystem& fSystem;          // Graphics system.
00327   const G4int        fSceneHandlerId;  // Id of this instance.
00328   G4String           fName;
00329   G4int              fViewCount;       // To determine view ids.
00330   G4ViewerList       fViewerList;      // Viewers.
00331   G4VViewer*         fpViewer;         // Current viewer.
00332   G4Scene*           fpScene;          // Scene for this scene handler.
00333   G4bool             fMarkForClearingTransientStore;
00334   G4bool             fReadyForTransients;  // I.e., not processing the
00335                                            // run-duration part of scene.
00336   G4bool             fTransientsDrawnThisEvent;  // Maintained by vis
00337   G4bool             fTransientsDrawnThisRun;    // manager.
00338   G4bool             fProcessingSolid; // True if within Pre/PostAddSolid.
00339   G4bool             fProcessing2D;    // True for 2D.
00340   G4VModel*          fpModel;          // Current model.
00341   G4Transform3D fObjectTransformation; // Current accumulated
00342                                        // object transformation.
00343   G4int              fNestingDepth;    // For Begin/EndPrimitives.
00344   const G4VisAttributes* fpVisAttribs; // Working vis attributes.
00345   const G4Transform3D fIdentityTransformation;
00346 
00347 private:
00348 
00349   G4VSceneHandler (const G4VSceneHandler&);
00350   G4VSceneHandler& operator = (const G4VSceneHandler&);
00351 };
00352 
00353 #include "G4VSceneHandler.icc"
00354 
00355 #endif

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