Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-18 09:30:14

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