TGLPadUtils.h

Go to the documentation of this file.
00001 // @(#)root/gl:$Id: TGLPadUtils.h 36532 2010-11-08 10:36:48Z couet $
00002 // Author:  Timur Pocheptsov  06/05/2009
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2009, 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_TGLPadUtils
00013 #define ROOT_TGLPadUtils
00014 
00015 #include <vector>
00016 #include <list>
00017 
00018 #ifndef ROOT_RStipples
00019 #include "RStipples.h"
00020 #endif
00021 #ifndef ROOT_TPoint
00022 #include "TPoint.h"
00023 #endif
00024 #ifndef ROOT_Rtypes
00025 #include "Rtypes.h"
00026 #endif
00027 
00028 class TGLPadPainter;//For friend declarations.
00029 
00030 /*
00031 
00032 All code here and in corresponding *.cxx file is only
00033 for TGLPadPainter. So, it can be limited or wrong
00034 for something else, but it's OK for TGLPadPainter.
00035 
00036 */
00037 
00038 namespace Rgl {
00039 namespace Pad {
00040 /*
00041 Auxiliary class to converts ROOT's polygon stipples from
00042 RStipples.h into GL's stipples and hold them in a fStipples array.
00043 */
00044 class PolygonStippleSet {
00045    friend class ::TGLPadPainter;
00046    friend class FillAttribSet;
00047 private:
00048    std::vector<unsigned char> fStipples;
00049    
00050    static const UInt_t fgBitSwap[];
00051    static UInt_t SwapBits(UInt_t bits);
00052       
00053    enum EGeometry {
00054       kRowSize = 4,//For gl, stipple is a 32x32 pixel pattern. So, 4 GLubyte objects form a single line of a stipple.
00055       kNRows = 32,
00056       kStippleSize = kNRows * kRowSize//4 * 32 == 32 lines.   
00057    };
00058    
00059    enum EBitMasks {
00060       kLow4   = 0xf,
00061       kUp4    = 0xf0,
00062       k16Bits = 0xff
00063    };
00064 public:
00065    PolygonStippleSet();
00066 };
00067 
00068 /*
00069 RAII class to enable/disable selected stipple.
00070 */
00071 class FillAttribSet {
00072    UInt_t fStipple;
00073 public:
00074    FillAttribSet(const PolygonStippleSet & set, Bool_t ignoreStipple);
00075    ~FillAttribSet();
00076 };
00077 
00078 /*
00079 "ROOT like" line stipples.
00080 */
00081 
00082 extern const UShort_t gLineStipples[];
00083 extern const UInt_t gMaxStipple;
00084 
00085 /*
00086 Set/unset line attributes.
00087 */
00088 class LineAttribSet {
00089 private:
00090    Bool_t fSmooth;
00091    UInt_t fStipple;
00092    Bool_t fSetWidth;
00093 public:
00094    LineAttribSet(Bool_t smooth, UInt_t stipple, Double_t maxWidth, Bool_t setWidth);
00095    ~LineAttribSet();
00096 };
00097 
00098 /*
00099 Marker painter. Most markers can be painted by standlone functions.
00100 For circles, it can be usefull to precalculate the marker geometry
00101 and use it for poly-markers.
00102 */
00103 /*
00104 Marker painter. Most markers can be painted by standlone functions.
00105 For circles, it can be usefull to precalculate the marker geometry
00106 and use it for poly-markers.
00107 */
00108 class MarkerPainter {
00109 private:
00110    //Different TArrMarker styles.
00111    mutable TPoint fStar[8];
00112    mutable TPoint fCross[4];
00113    
00114    mutable std::vector<TPoint> fCircle;
00115    
00116    enum {
00117       kSmallCirclePts = 80,
00118       kLargeCirclePts = 150
00119    };
00120    
00121 public:
00122    //Each function draw n markers.
00123    void DrawDot(UInt_t n, const TPoint *xy)const;
00124    void DrawPlus(UInt_t n, const TPoint *xy)const;
00125    void DrawStar(UInt_t n, const TPoint *xy)const;
00126    void DrawX(UInt_t n, const TPoint *xy)const;
00127    void DrawFullDotSmall(UInt_t n, const TPoint *xy)const;
00128    void DrawFullDotMedium(UInt_t n, const TPoint *xy)const;
00129    
00130    void DrawCircle(UInt_t n, const TPoint *xy)const;
00131    void DrawFullDotLarge(UInt_t n, const TPoint *xy)const;
00132    
00133    void DrawFullSquare(UInt_t n, const TPoint *xy)const;
00134    void DrawFullTrianlgeUp(UInt_t n, const TPoint *xy)const;
00135    void DrawFullTrianlgeDown(UInt_t n, const TPoint *xy)const;
00136    void DrawDiamond(UInt_t n, const TPoint *xy)const;
00137    void DrawCross(UInt_t n, const TPoint *xy)const;
00138    void DrawFullStar(UInt_t n, const TPoint *xy)const;
00139    void DrawOpenStar(UInt_t n, const TPoint *xy)const;
00140 
00141 };
00142 
00143 //
00144 // OpenGL's tesselator calls callback functions glBegin(MODE), glVertex3(v), glEnd(),
00145 // where v can be new vertex (or existing) and MODE is a type of mesh patch.
00146 // MeshPatch_t is a class to save such a tesselation
00147 // (instead of using glVertex and glBegin to draw.
00148 //
00149 struct MeshPatch_t {
00150    MeshPatch_t(Int_t type) : fPatchType(type)
00151    {}
00152 
00153    Int_t                 fPatchType; //GL_QUADS, GL_QUAD_STRIP, etc.
00154    std::vector<Double_t> fPatch;     //vertices.
00155 };
00156 
00157 typedef std::list<MeshPatch_t> Tesselation_t;
00158 
00159 class Tesselator {
00160 
00161 
00162 public:
00163    Tesselator(Bool_t dump = kFALSE);
00164 
00165    ~Tesselator();
00166    
00167    void *GetTess()const
00168    {
00169       return fTess;
00170    }
00171 
00172    static void SetDump(Tesselation_t *t)
00173    {
00174       fVs = t;
00175    }
00176 
00177    static Tesselation_t *GetDump()
00178    {
00179       return fVs;
00180    }
00181 
00182 private:
00183 
00184    void *fTess;
00185 
00186    static Tesselation_t *fVs;//the current tesselator's dump.
00187 };
00188 
00189 /*
00190 In future, this should be an interface to per-pad FBO.
00191 Currently, in only save sizes and coordinates (?)
00192 */
00193 class OffScreenDevice {
00194    friend class ::TGLPadPainter;
00195 public:
00196    OffScreenDevice(UInt_t w, UInt_t h, UInt_t x, UInt_t y, Bool_t top);
00197    
00198 private:
00199    UInt_t fW;
00200    UInt_t fH;
00201    UInt_t fX;
00202    UInt_t fY;
00203    Bool_t fTop;
00204 };
00205 
00206 void ExtractRGB(Color_t colorIndex, Float_t * rgb);
00207 
00208 class GLLimits {
00209 public:
00210    GLLimits();
00211 
00212    Double_t GetMaxLineWidth()const;
00213    Double_t GetMaxPointSize()const;
00214 private:
00215    mutable Double_t fMaxLineWidth;
00216    mutable Double_t fMaxPointSize;
00217 };
00218 
00219 }//namespace Pad
00220 }//namespace Rgl
00221 
00222 #endif

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