G4VViewer.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  27th March 1996
00031 //
00032 // Class description
00033 //
00034 // Abstract interface class for graphics viewers.
00035 
00036 #ifndef G4VVIEWER_HH
00037 #define G4VVIEWER_HH
00038 
00039 #include "globals.hh"
00040 
00041 #include "G4ViewParameters.hh"
00042 
00043 class G4VSceneHandler;
00044 
00045 class G4VViewer {
00046 
00047 public: // With description
00048 
00049   friend std::ostream& operator << (std::ostream& os, const G4VViewer& v);
00050 
00051   G4VViewer (G4VSceneHandler&, G4int id, const G4String& name = "");
00052   virtual ~G4VViewer ();
00053 
00054   virtual void Initialise ();
00055   // Called immediately after construction for those operations that
00056   // must await complete contruction of viewer and all its bases.  For
00057   // example, if this class (G4VViewer) is inherited virtually, as in
00058   // the OpenGL sub-category, it will not be fully constructed until
00059   // *after* the the derived viewer (this is the rule about order of
00060   // construction for virtual inheritance), so the derived viewer may
00061   // not use information in G4VViewer in its contructor.  Hence such
00062   // code must be in Initialise().
00063 
00065   // View manipulation functions.
00066 
00067   virtual void ResetView ();
00068   // Reset view parameters to default, including sub-class parameters, if any.
00069   // The sub-class should always invoke the base class implementation, i.e:
00070   // virtual void SubClass::ResetView () {
00071   //   G4VViewer::ResetView();
00072   //   // Then reset sub-class parameters
00073   //   ...
00074 
00075   virtual void SetView () = 0;
00076   // Take view parameters and work out model/view transformation,
00077   // projection transformation, lighting, etc.
00078 
00079   virtual void ClearView () = 0;
00080   // Clear screen/viewing buffers.
00081 
00082   virtual void DrawView () = 0;
00083   // Draw view of the scene currently attached to the scene handler -
00084   // see example of a minimal function at end of this file.
00085   
00086   void RefreshView ();
00087   // Simply invokes SetView, ClearView, DrawView.
00088 
00089   virtual void ShowView ();
00090   // Show view (for graphics systems which require to process
00091   // all drawn objects before finalising the view).
00092 
00093   virtual void FinishView ();
00094   // Called at the end of drawing scene.  Used to flush streams, or
00095   // swap buffers.  (Perhaps it is inappropriately named, perhaps its
00096   // function could be incorporated into EndModeling ().  It marks the
00097   // end of scene drawing; be aware hits and digi drawing may Follow.
00098   // It is not yet the end of all drawing; that is signalled by
00099   // ShowView ().)
00100 
00102   // Access functions.
00103   const G4String&         GetName           () const;
00104   const G4String&         GetShortName      () const;
00105   void                    SetName           (const G4String&);
00106   G4int                   GetViewId         () const;
00107   G4VSceneHandler*        GetSceneHandler   () const;
00108   const G4ViewParameters& GetViewParameters        () const;
00109   const G4ViewParameters& GetDefaultViewParameters () const;
00110   void SetViewParameters         (const G4ViewParameters& vp);
00111   void SetDefaultViewParameters  (const G4ViewParameters& vp);
00112 
00114   // Public utility functions.
00115 
00116   const G4VisAttributes*  GetApplicableVisAttributes
00117                                             (const G4VisAttributes*) const;
00118 
00119   void SetNeedKernelVisit (G4bool need);
00120   // Sets individual need-visit flag.
00121 
00122   void NeedKernelVisit ();
00123   // Flags all views the need to re-visit the GEANT4 kernel to refresh
00124   // the scene.
00125 
00126   void ProcessView ();
00127   // Used by DrawView ().  Invokes SetView ().  The basic logic is here.
00128 
00129 protected:
00130 
00132   // Data members
00133   G4VSceneHandler&        fSceneHandler;     // Abstract scene for this view.
00134   G4int            fViewId;    // Id of this instance.
00135   G4String         fName;
00136   G4String         fShortName; // Up to first ' ' character, if any.
00137   G4ViewParameters fVP;        // View parameters.
00138   G4ViewParameters fDefaultVP; // Default view parameters.
00139 
00141   // Other parameters.
00142   G4bool           fNeedKernelVisit;  // See DrawView() for comments.
00143 };
00144 
00145 #include "G4VViewer.icc"
00146 
00147 /*********************************************
00148 
00149 Here is a minimal DrawView () as it might be implemented in the
00150 concrete viewer.
00151 
00152 void G4VViewer::DrawView () {  // Default - concrete view usually overrides.
00153 
00154   // First, a view should decide when to re-visit the G4 kernel.
00155   // Sometimes it might not be necessary, e.g., if the scene is stored
00156   // in a graphical database (e.g., OpenGL's display lists) and only
00157   // the viewing angle has changed.  But graphics systems without a
00158   // graphical database will always need to visit the G4 kernel.
00159 
00160   NeedKernelVisit ();  // Default is - always visit G4 kernel.
00161   // Note: this routine sets the fNeedKernelVisit flag of *all* the views of
00162   // the scene.
00163 
00164   ProcessView ();             // The basic logic is here.
00165 
00166   // Then a view may have more to do, e.g., display the graphical
00167   // database.  That code should come here before finally...
00168 
00169   FinishView ();              // Flush streams and/or swap buffers.
00170 }
00171 
00172 *********************************************/
00173 
00174 #endif

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