TGLScene.h

Go to the documentation of this file.
00001 // @(#)root/gl:$Id: TGLScene.h 32334 2010-02-12 11:52:13Z matevz $
00002 // Author:  Matevz Tadel, Feb 2007
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TGLScene_H
00013 #define ROOT_TGLScene_H
00014 
00015 #include "TGLSceneBase.h"
00016 #include "TGLSceneInfo.h"
00017 
00018 #include "Gtypes.h"
00019 
00020 #include <map>
00021 #include <vector>
00022 
00023 class TGLObject;
00024 class TGLCamera;
00025 class TGLLogicalShape;
00026 class TGLPhysicalShape;
00027 
00028 class TGLContextIdentity;
00029 
00030 class TGLScene : public TGLSceneBase
00031 {
00032 private:
00033    TGLScene(const TGLScene&);            // Not implemented
00034    TGLScene& operator=(const TGLScene&); // Not implemented
00035 
00036    // Compare physical-shape volumes/diagonals -- for draw-vec sorting
00037    static Bool_t ComparePhysicalVolumes(const TGLPhysicalShape* shape1,
00038                                         const TGLPhysicalShape* shape2);
00039    static Bool_t ComparePhysicalDiagonals(const TGLPhysicalShape* shape1,
00040                                           const TGLPhysicalShape* shape2);
00041 public:
00042    // Logical shapes
00043    typedef std::map<TObject*, TGLLogicalShape*>    LogicalShapeMap_t;
00044    typedef LogicalShapeMap_t::value_type           LogicalShapeMapValueType_t;
00045    typedef LogicalShapeMap_t::iterator             LogicalShapeMapIt_t;
00046    typedef LogicalShapeMap_t::const_iterator       LogicalShapeMapCIt_t;
00047 
00048    // Physical Shapes
00049    typedef std::map<UInt_t, TGLPhysicalShape*>     PhysicalShapeMap_t;
00050    typedef PhysicalShapeMap_t::value_type          PhysicalShapeMapValueType_t;
00051    typedef PhysicalShapeMap_t::iterator            PhysicalShapeMapIt_t;
00052    typedef PhysicalShapeMap_t::const_iterator      PhysicalShapeMapCIt_t;
00053 
00054 
00055    struct DrawElement_t
00056    {
00057       const TGLPhysicalShape* fPhysical; // Physical shape.
00058 
00059       Float_t    fPixelSize; // Size of largest lod-axis in pixels.
00060       Short_t    fPixelLOD;  // Size in LOD units.
00061       Short_t    fFinalLOD;  // Corrected with SceneLOD and quantized.
00062 
00063       DrawElement_t(const TGLPhysicalShape* pshp=0) :
00064          fPhysical(pshp), fPixelSize(0), fPixelLOD(0), fFinalLOD(0) {}
00065    };
00066 
00067    typedef std::vector<DrawElement_t>              DrawElementVec_t;
00068    typedef std::vector<DrawElement_t>::iterator    DrawElementVec_i;
00069 
00070    typedef std::vector<DrawElement_t*>             DrawElementPtrVec_t;
00071    typedef std::vector<DrawElement_t*>::iterator   DrawElementPtrVec_i;
00072 
00073    // List of physical shapes ordered by volume/diagonal
00074    typedef std::vector<const TGLPhysicalShape*>    ShapeVec_t;
00075    typedef ShapeVec_t::iterator                    ShapeVec_i;
00076 
00077    // ----------------------------------------------------------------
00078    // SceneInfo ... extended scene context
00079 
00080    class TSceneInfo : public TGLSceneInfo
00081    {
00082    private:
00083       Bool_t CmpDrawElements(const DrawElement_t& de1, const DrawElement_t& de2);
00084 
00085    protected:
00086       void ClearDrawElementVec(DrawElementVec_t& vec, Int_t maxSize);
00087       void ClearDrawElementPtrVec(DrawElementPtrVec_t& vec, Int_t maxSize);
00088 
00089    public:
00090       ShapeVec_t          fShapesOfInterest;
00091 
00092       DrawElementVec_t    fVisibleElements;
00093 
00094       UInt_t              fMinorStamp;
00095       DrawElementPtrVec_t fOpaqueElements;
00096       DrawElementPtrVec_t fTranspElements;
00097       DrawElementPtrVec_t fSelOpaqueElements;
00098       DrawElementPtrVec_t fSelTranspElements;
00099 
00100       TSceneInfo(TGLViewerBase* view=0, TGLScene* scene=0);
00101       virtual ~TSceneInfo();
00102 
00103       void ClearAfterRebuild();
00104       void ClearAfterUpdate();
00105 
00106       void Lodify(TGLRnrCtx& ctx);
00107 
00108       void PreDraw();
00109       void PostDraw();
00110 
00111       // ---------------
00112       // Draw statistics
00113 
00114       Int_t                     fOpaqueCnt;
00115       Int_t                     fTranspCnt;
00116       Int_t                     fAsPixelCnt;
00117       std::map<TClass*, UInt_t> fByShapeCnt;
00118 
00119       void ResetDrawStats();
00120       void UpdateDrawStats(const TGLPhysicalShape& shape, Short_t lod);
00121       void DumpDrawStats(); // Debug
00122    };
00123    friend class TSceneInfo; // for solaris cc
00124 
00125 
00126 protected:
00127    LogicalShapeMap_t      fLogicalShapes;  //!
00128    PhysicalShapeMap_t     fPhysicalShapes; //!
00129 
00130    virtual void DestroyPhysicalInternal(PhysicalShapeMapIt_t pit);
00131 
00132    // GLcontext
00133    TGLContextIdentity * fGLCtxIdentity;
00134    void ReleaseGLCtxIdentity();
00135 
00136    // Smart Refresh -- will go in this version
00137    Bool_t                    fInSmartRefresh;    //!
00138    mutable LogicalShapeMap_t fSmartRefreshCache; //!
00139 
00140    // State that requires recreation of display-lists
00141    Float_t                   fLastPointSizeScale;
00142    Float_t                   fLastLineWidthScale;
00143 
00144    // ----------------------------------------------------------------
00145    // ----------------------------------------------------------------
00146 
00147 public:
00148    TGLScene();
00149    virtual ~TGLScene();
00150 
00151    virtual void CalcBoundingBox() const;
00152 
00153    virtual TSceneInfo* CreateSceneInfo(TGLViewerBase* view);
00154    virtual void        RebuildSceneInfo(TGLRnrCtx& rnrCtx);
00155    virtual void        UpdateSceneInfo(TGLRnrCtx& rnrCtx);
00156    virtual void        LodifySceneInfo(TGLRnrCtx& rnrCtx);
00157 
00158 
00159    // Rendering
00160    virtual void PreDraw   (TGLRnrCtx& rnrCtx);
00161    // virtual void PreRender (TGLRnrCtx& rnrCtx);
00162    // virtual void Render    (TGLRnrCtx& rnrCtx);
00163    virtual void RenderOpaque    (TGLRnrCtx& rnrCtx);
00164    virtual void RenderTransp    (TGLRnrCtx& rnrCtx);
00165    virtual void RenderSelOpaque (TGLRnrCtx& rnrCtx);
00166    virtual void RenderSelTransp (TGLRnrCtx& rnrCtx);
00167    // virtual void PostRender(TGLRnrCtx& rnrCtx);
00168    virtual void PostDraw  (TGLRnrCtx& rnrCtx);
00169 
00170    virtual void RenderAllPasses(TGLRnrCtx&           rnrCtx,
00171                                 DrawElementPtrVec_t& elVec,
00172                                 Bool_t               check_timeout);
00173 
00174 
00175    virtual void RenderElements (TGLRnrCtx&           rnrCtx,
00176                                 DrawElementPtrVec_t& elVec,
00177                                 Bool_t               check_timeout,
00178                                 const TGLPlaneSet_t* clipPlanes = 0);
00179 
00180    // Selection
00181    virtual Bool_t ResolveSelectRecord(TGLSelectRecord& rec, Int_t curIdx);
00182 
00183    // Basic logical shape management
00184    virtual void              AdoptLogical(TGLLogicalShape& shape);
00185    virtual Bool_t            DestroyLogical(TObject* logid, Bool_t mustFind=kTRUE);
00186    virtual Int_t             DestroyLogicals();
00187    virtual TGLLogicalShape*  FindLogical(TObject* logid)  const;
00188 
00189    // Basic physical shape management
00190    virtual void              AdoptPhysical(TGLPhysicalShape& shape);
00191    virtual Bool_t            DestroyPhysical(UInt_t phid);
00192    virtual Int_t             DestroyPhysicals();
00193    virtual TGLPhysicalShape* FindPhysical(UInt_t phid) const;
00194 
00195    virtual UInt_t            GetMaxPhysicalID();
00196 
00197    // ----------------------------------------------------------------
00198    // Updates / removals of logical and physical shapes
00199 
00200    virtual Bool_t BeginUpdate();
00201    virtual void   EndUpdate(Bool_t minorChange=kTRUE, Bool_t sceneChanged=kTRUE, Bool_t updateViewers=kTRUE);
00202 
00203    virtual void UpdateLogical(TObject* logid);
00204 
00205    virtual void UpdatePhysical(UInt_t phid, Double_t* trans, UChar_t* col);
00206    virtual void UpdatePhysical(UInt_t phid, Double_t* trans, Color_t cidx=-1, UChar_t transp=0);
00207 
00208    virtual void UpdatePhysioLogical(TObject* logid, Double_t* trans, UChar_t* col);
00209    virtual void UpdatePhysioLogical(TObject* logid, Double_t* trans, Color_t cidx, UChar_t transp);
00210 
00211    // Temporary export for setting selected-state of physical shapes.
00212    LogicalShapeMap_t& RefLogicalShapes() { return fLogicalShapes; }
00213 
00214 
00215    // ----------------------------------------------------------------
00216    // SmartRefresh
00217 
00218    UInt_t            BeginSmartRefresh();
00219    void              EndSmartRefresh();
00220    TGLLogicalShape*  FindLogicalSmartRefresh(TObject* ID) const;
00221 
00222 
00223    // ----------------------------------------------------------------
00224    // GL-context holding display-list definitions
00225 
00226    TGLContextIdentity* GetGLCtxIdentity() const { return fGLCtxIdentity; }
00227 
00228 
00229    // ----------------------------------------------------------------
00230    // Helpers
00231 
00232    UInt_t SizeOfScene() const;
00233    void   DumpMapSizes() const;
00234 
00235    static void RGBAFromColorIdx(Float_t rgba[4], Color_t ci, Char_t transp=0);
00236 
00237    static Bool_t IsOutside(const TGLBoundingBox& box,
00238                            const TGLPlaneSet_t& planes);
00239 
00240    ClassDef(TGLScene, 0); // Standard ROOT OpenGL scene with logial/physical shapes.
00241 };
00242 
00243 
00244 #endif

Generated on Tue Jul 5 14:16:54 2011 for ROOT_528-00b_version by  doxygen 1.5.1