G4OpenGLStoredSceneHandler.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 // Andrew Walkden  10th February 1997
00031 // G4OpenGLStoredSceneHandler - creates OpenGL Display lists.
00032 
00033 #ifdef G4VIS_BUILD_OPENGL_DRIVER
00034 
00035 #ifndef G4OPENGLSTOREDSCENEHANDLER_HH
00036 #define G4OPENGLSTOREDSCENEHANDLER_HH
00037 
00038 #include "globals.hh"
00039 #include "G4OpenGLSceneHandler.hh"
00040 #include "G4Text.hh"
00041 #include <map>
00042 #include <vector>
00043 
00044 class G4OpenGLStored;
00045 
00046 class G4OpenGLStoredSceneHandler: public G4OpenGLSceneHandler {
00047 
00048   friend class G4OpenGLStoredViewer;  // ..allows access to P/TODLs.
00049 
00050 public:
00051 
00052   G4OpenGLStoredSceneHandler (G4VGraphicsSystem& system, const G4String& name = "");
00053   virtual ~G4OpenGLStoredSceneHandler ();
00054   void BeginPrimitives (const G4Transform3D& objectTransformation);
00055   void EndPrimitives ();
00056   void BeginPrimitives2D (const G4Transform3D& objectTransformation);
00057   void EndPrimitives2D ();
00058   void BeginModeling ();
00059   void EndModeling ();
00060   void AddPrimitive (const G4Polyline&);
00061   void AddPrimitive (const G4Polymarker&);
00062   void AddPrimitive (const G4Circle&);
00063   void AddPrimitive (const G4Square&);
00064   void AddPrimitive (const G4Text&);
00065   void AddPrimitive (const G4Scale&);
00066   void AddPrimitive (const G4Polyhedron&);
00067   void AddPrimitive (const G4NURBS&);
00068   void ClearStore ();
00069   void ClearTransientStore ();
00070 
00071   static G4int GetDisplayListLimit() {return fDisplayListLimit;}
00072   static void SetDisplayListLimit(G4int lim) {fDisplayListLimit = lim;}
00073 
00074 protected:
00075 
00076   G4bool AddPrimitivePreamble(const G4Visible& visible);
00077   // Return false if no further processing required.
00078 
00079   void AddPrimitivePostamble();
00080 
00081   // Two virtual functions for extra processing in a sub-class, for
00082   // example, to make a display tree.  They are to return true if the
00083   // visible object uses gl commands for drawing.  This is
00084   // predominantly true; a notable exception is Qt text.  In that
00085   // case, a display list does not need to be created; all relevant
00086   // information is assumed to be stored in the PO/TOList.
00087   virtual G4bool ExtraPOProcessing
00088   (const G4Visible&, size_t /*currentPOListIndex*/) {return true;}
00089   virtual G4bool ExtraTOProcessing
00090   (const G4Visible&, size_t /*currentTOListIndex*/) {return true;}
00091 
00092   static G4int  fSceneIdCount;   // static counter for OpenGLStored scenes.
00093   // Display list management.  All static since there's only one OGL store.
00094   static G4int  fDisplayListId;  // Workspace.
00095   static G4bool fMemoryForDisplayLists;  // avoid memory overflow
00096   static G4int  fDisplayListLimit;       // avoid memory overflow
00097   
00098   // PODL = Persistent Object Display List.
00099   // This "top PODL" was made redundant when the PO list was
00100   // "unwrapped" 27th October 2011, but keep it for now in case we
00101   // need to wrap it again.
00102   GLint  fTopPODL;              // List which calls the other PODLs.
00103 
00104   // G4Text plus transform and 2/3D.
00105   struct G4TextPlus {
00106     G4TextPlus(const G4Text& text): fG4Text(text), fProcessing2D(false) {}
00107     G4Text fG4Text;
00108     G4bool fProcessing2D;
00109   };
00110 
00111   // PO = Persistent Object, i.e., run-durantion object, e.g., geometry.
00112   struct PO {
00113     PO();
00114     PO(const PO&);
00115     PO(G4int id, const G4Transform3D& tr = G4Transform3D());
00116     ~PO();
00117     PO& operator= (const PO&);
00118     G4int fDisplayListId;
00119     G4Transform3D fTransform;
00120     GLuint fPickName;
00121     G4Colour fColour;
00122     G4TextPlus* fpG4TextPlus;
00123     G4bool fMarkerOrPolyline;
00124   };
00125   std::vector<PO> fPOList; 
00126   
00127   // TO = Transient Object, e.g., trajectories.
00128   struct TO {
00129     TO();
00130     TO(const TO&);
00131     TO(G4int id, const G4Transform3D& tr = G4Transform3D());
00132     ~TO();
00133     TO& operator= (const TO&);
00134     G4int fDisplayListId;
00135     G4Transform3D fTransform;
00136     GLuint fPickName;
00137     G4double fStartTime, fEndTime;  // Time range (e.g., for trajectory steps).
00138     G4Colour fColour;
00139     G4TextPlus* fpG4TextPlus;
00140     G4bool fMarkerOrPolyline;
00141   };
00142   std::vector<TO> fTOList; 
00143   
00144   // Stop-gap solution of structure re-use.
00145   // A proper implementation would use geometry hierarchy.
00146   std::map <const G4VSolid*, G4int, std::less <const G4VSolid*> > fSolidMap;
00147 
00148 };
00149 
00150 #endif
00151 
00152 #endif

Generated on Mon May 27 17:49:10 2013 for Geant4 by  doxygen 1.4.7