Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TGLPadUtils.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // @(#)root/gl:$Id$
0002 // Author:  Timur Pocheptsov  06/05/2009
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2009, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TGLPadUtils
0013 #define ROOT_TGLPadUtils
0014 
0015 #include <vector>
0016 #include <list>
0017 
0018 #include "RStipples.h"
0019 #include "TPoint.h"
0020 #include "RtypesCore.h"
0021 
0022 class TGLPadPainter;//For friend declarations.
0023 
0024 /*
0025 
0026 All code here and in corresponding *.cxx file is only
0027 for TGLPadPainter. So, it can be limited or wrong
0028 for something else, but it's OK for TGLPadPainter.
0029 
0030 */
0031 
0032 namespace Rgl {
0033 namespace Pad {
0034 /*
0035 Auxiliary class to converts ROOT's polygon stipples from
0036 RStipples.h into GL's stipples and hold them in a fStipples array.
0037 */
0038 class PolygonStippleSet {
0039    friend class ::TGLPadPainter;
0040    friend class FillAttribSet;
0041 private:
0042    std::vector<unsigned char> fStipples;
0043 
0044    static const UInt_t fgBitSwap[];
0045    static UInt_t SwapBits(UInt_t bits);
0046 
0047    enum EGeometry {
0048       kRowSize = 4,//For gl, stipple is a 32x32 pixel pattern. So, 4 GLubyte objects form a single line of a stipple.
0049       kNRows = 32,
0050       kStippleSize = kNRows * kRowSize//4 * 32 == 32 lines.
0051    };
0052 
0053    enum EBitMasks {
0054       kLow4   = 0xf,
0055       kUp4    = 0xf0,
0056       k16Bits = 0xff
0057    };
0058 public:
0059    PolygonStippleSet();
0060 };
0061 
0062 /*
0063 RAII class to enable/disable selected stipple.
0064 */
0065 class FillAttribSet {
0066    UInt_t fStipple;
0067    Float_t fAlpha;
0068 public:
0069    FillAttribSet(const PolygonStippleSet & set, Bool_t ignoreStipple);
0070    ~FillAttribSet();
0071 };
0072 
0073 /*
0074 "ROOT like" line stipples.
0075 */
0076 
0077 extern const UShort_t gLineStipples[];
0078 extern const UInt_t gMaxStipple;
0079 
0080 /*
0081 Set/unset line attributes.
0082 */
0083 class LineAttribSet {
0084 private:
0085    Bool_t fSmooth;
0086    UInt_t fStipple;
0087    Bool_t fSetWidth;
0088    Float_t fAlpha;
0089 public:
0090    LineAttribSet(Bool_t smooth, UInt_t stipple, Double_t maxWidth, Bool_t setWidth);
0091    ~LineAttribSet();
0092 };
0093 
0094 /*
0095 Marker painter. Most markers can be painted by standlone functions.
0096 For circles, it can be usefull to precalculate the marker geometry
0097 and use it for poly-markers.
0098 */
0099 /*
0100 Marker painter. Most markers can be painted by standlone functions.
0101 For circles, it can be usefull to precalculate the marker geometry
0102 and use it for poly-markers.
0103 */
0104 class MarkerPainter {
0105 private:
0106    //Different TArrMarker styles.
0107    mutable TPoint fStar[8];
0108    mutable TPoint fCross[4];
0109 
0110    mutable std::vector<TPoint> fCircle;
0111 
0112    enum {
0113       kSmallCirclePts = 80,
0114       kLargeCirclePts = 150
0115    };
0116 
0117 public:
0118    //Each function draw n markers.
0119    void DrawDot(UInt_t n, const TPoint *xy)const;
0120    void DrawPlus(UInt_t n, const TPoint *xy)const;
0121    void DrawStar(UInt_t n, const TPoint *xy)const;
0122    void DrawX(UInt_t n, const TPoint *xy)const;
0123    void DrawFullDotSmall(UInt_t n, const TPoint *xy)const;
0124    void DrawFullDotMedium(UInt_t n, const TPoint *xy)const;
0125 
0126    void DrawCircle(UInt_t n, const TPoint *xy)const;
0127    void DrawFullDotLarge(UInt_t n, const TPoint *xy)const;
0128 
0129    void DrawFullSquare(UInt_t n, const TPoint *xy)const;
0130    void DrawFullTrianlgeUp(UInt_t n, const TPoint *xy)const;
0131    void DrawFullTrianlgeDown(UInt_t n, const TPoint *xy)const;
0132    void DrawDiamond(UInt_t n, const TPoint *xy)const;
0133    void DrawFullDiamond(UInt_t n, const TPoint *xy)const;
0134    void DrawOpenTrianlgeDown(UInt_t n, const TPoint *xy)const;
0135    void DrawFullCross(UInt_t n, const TPoint *xy)const;
0136    void DrawOpenCross(UInt_t n, const TPoint *xy)const;
0137    void DrawFullStar(UInt_t n, const TPoint *xy)const;
0138    void DrawOpenStar(UInt_t n, const TPoint *xy)const;
0139    void DrawOpenSquareDiagonal(UInt_t n, const TPoint *xy)const;
0140    void DrawOpenDiamondCross(UInt_t n, const TPoint *xy)const;
0141    void DrawOpenThreeTriangles(UInt_t n, const TPoint *xy)const;
0142    void DrawOctagonCross(UInt_t n, const TPoint *xy)const;
0143    void DrawFullThreeTriangles(UInt_t n, const TPoint *xy)const;
0144    void DrawOpenFourTrianglesX(UInt_t n, const TPoint *xy)const;
0145    void DrawFullFourTrianglesX(UInt_t n, const TPoint *xy)const;
0146    void DrawOpenDoubleDiamond(UInt_t n, const TPoint *xy)const;
0147    void DrawFullDoubleDiamond(UInt_t n, const TPoint *xy)const;
0148    void DrawOpenFourTrianglesPlus(UInt_t n, const TPoint *xy)const;
0149    void DrawFullFourTrianglesPlus(UInt_t n, const TPoint *xy)const;
0150    void DrawOpenCrossX(UInt_t n, const TPoint *xy)const;
0151    void DrawFullCrossX(UInt_t n, const TPoint *xy)const;
0152    void DrawFourSquaresX(UInt_t n, const TPoint *xy)const;
0153    void DrawFourSquaresPlus(UInt_t n, const TPoint *xy)const;
0154 };
0155 
0156 //
0157 // OpenGL's tesselator calls callback functions glBegin(MODE), glVertex3(v), glEnd(),
0158 // where v can be new vertex (or existing) and MODE is a type of mesh patch.
0159 // MeshPatch_t is a class to save such a tesselation
0160 // (instead of using glVertex and glBegin to draw.
0161 //
0162 struct MeshPatch_t {
0163    MeshPatch_t(Int_t type) : fPatchType(type)
0164    {}
0165 
0166    Int_t                 fPatchType; //GL_QUADS, GL_QUAD_STRIP, etc.
0167    std::vector<Double_t> fPatch;     //vertices.
0168 };
0169 
0170 typedef std::list<MeshPatch_t> Tesselation_t;
0171 
0172 class Tesselator {
0173 
0174 
0175 public:
0176    Tesselator(Bool_t dump = kFALSE);
0177 
0178    ~Tesselator();
0179 
0180    void *GetTess()const
0181    {
0182       return fTess;
0183    }
0184 
0185    static void SetDump(Tesselation_t *t)
0186    {
0187       fVs = t;
0188    }
0189 
0190    static Tesselation_t *GetDump()
0191    {
0192       return fVs;
0193    }
0194 
0195 private:
0196 
0197    void *fTess;
0198 
0199    static Tesselation_t *fVs;//the current tesselator's dump.
0200 };
0201 
0202 /*
0203 In future, this should be an interface to per-pad FBO.
0204 Currently, in only save sizes and coordinates (?)
0205 */
0206 class OffScreenDevice {
0207    friend class ::TGLPadPainter;
0208 public:
0209    OffScreenDevice(UInt_t w, UInt_t h, UInt_t x, UInt_t y, Bool_t top);
0210 
0211 private:
0212    UInt_t fW;
0213    UInt_t fH;
0214    UInt_t fX;
0215    UInt_t fY;
0216    Bool_t fTop;
0217 };
0218 
0219 void ExtractRGBA(Color_t colorIndex, Float_t *rgba);
0220 
0221 class GLLimits {
0222 public:
0223    GLLimits();
0224 
0225    Double_t GetMaxLineWidth()const;
0226    Double_t GetMaxPointSize()const;
0227 private:
0228    mutable Double_t fMaxLineWidth;
0229    mutable Double_t fMaxPointSize;
0230 };
0231 
0232 //We have a lot of Rect_t/Point_t/TGLRect/TGLBoundingBox blah-blah-blah.
0233 //What we do not have is a rectangle with floating point types.
0234 
0235 template<class ValueType>
0236 struct BoundingRect {
0237    ValueType fXMin = ValueType();
0238    ValueType fYMin = ValueType();
0239    ValueType fWidth = ValueType();
0240    ValueType fHeight = ValueType();
0241    //Sometimes it's more convenient:
0242    ValueType fXMax = ValueType();
0243    ValueType fYMax = ValueType();
0244 };
0245 
0246 //It's explicitly instantiated for signed integer/fp types (in *.cxx).
0247 template<class ValueType>
0248 BoundingRect<ValueType> FindBoundingRect(Int_t nPoints, const ValueType *xs, const ValueType *ys);
0249 
0250 
0251 }//namespace Pad
0252 }//namespace Rgl
0253 
0254 #endif