Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TGLPlotPainter.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  14/06/2006
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2004, 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_TGLPlotPainter
0013 #define ROOT_TGLPlotPainter
0014 
0015 #include <vector>
0016 
0017 #include "TVirtualGL.h"
0018 #include "TGLPlotBox.h"
0019 #include "TPoint.h"
0020 #include "TGLUtil.h"
0021 #include "TNamed.h"
0022 
0023 class TGLPlotCoordinates;
0024 class TGLPlotCamera;
0025 class TGL5DDataSet;
0026 class TString;
0027 class TColor;
0028 class TAxis;
0029 class TH1;
0030 class TH3;
0031 class TF3;
0032 
0033 /*
0034    Box cut. When attached to a plot, cuts away a part of it.
0035    Can be moved in a plot's own area in X/Y/Z directions.
0036 */
0037 
0038 class TGLBoxCut {
0039 private:
0040    Double_t                   fXLength;
0041    Double_t                   fYLength;
0042    Double_t                   fZLength;
0043    TGLVertex3                 fCenter;
0044    Rgl::Range_t               fXRange;
0045    Rgl::Range_t               fYRange;
0046    Rgl::Range_t               fZRange;
0047 
0048    const TGLPlotBox * const   fPlotBox;
0049    Bool_t                     fActive;
0050    Double_t                   fFactor;
0051 
0052    TPoint                     fMousePos;
0053 
0054 public:
0055    TGLBoxCut(const TGLPlotBox *plotBox);
0056    virtual ~TGLBoxCut();
0057 
0058    void   TurnOnOff();
0059    Bool_t IsActive()const{return fActive;}
0060    void   SetActive(Bool_t a);
0061 
0062    void   ResetBoxGeometry();
0063 
0064    void   SetFactor(Double_t f){fFactor = f;}
0065 
0066    void   DrawBox(Bool_t selectionPass, Int_t selected)const;
0067 
0068    void   StartMovement(Int_t px, Int_t py);
0069    void   MoveBox(Int_t px, Int_t py, Int_t axisID);
0070 
0071    Bool_t IsInCut(Double_t xMin, Double_t xMax, Double_t yMin, Double_t yMax,
0072                   Double_t zMin, Double_t zMax)const;
0073 
0074    template<class V>
0075    Bool_t IsInCut(const V * v) const
0076    {
0077       //Check, if box defined by xmin/xmax etc. is in cut.
0078       if (v[0] >= fXRange.first && v[0] < fXRange.second &&
0079           v[1] >= fYRange.first && v[1] < fYRange.second &&
0080           v[2] >= fZRange.first && v[2] < fZRange.second)
0081          return kTRUE;
0082       return kFALSE;
0083    }
0084 
0085    Rgl::Range_t GetXRange()const{return fXRange;}
0086    Rgl::Range_t GetYRange()const{return fYRange;}
0087    Rgl::Range_t GetZRange()const{return fZRange;}
0088 
0089 private:
0090    void AdjustBox();
0091 
0092    ClassDef(TGLBoxCut, 0)//Cuts away part of a plot.
0093 };
0094 
0095 /*
0096    2D contour for TH3 slicing.
0097 */
0098 
0099 class TGLTH3Slice : public TNamed {
0100 public:
0101    enum ESliceAxis {kXOZ, kYOZ, kXOY};
0102 
0103 private:
0104    ESliceAxis                fAxisType;
0105    const TAxis                    *fAxis;
0106    mutable TGLLevelPalette   fPalette;
0107 
0108    const TGLPlotCoordinates *fCoord;
0109    const TGLPlotBox         *fBox;
0110    Int_t                     fSliceWidth;
0111 
0112    const TH3                *fHist;
0113    const TF3                *fF3;
0114 
0115    mutable TGL2DArray<Double_t> fTexCoords;
0116 
0117    mutable Rgl::Range_t         fMinMax;
0118 
0119 public:
0120    TGLTH3Slice(const TString &sliceName,
0121                const TH3 *hist,
0122                const TGLPlotCoordinates *coord,
0123                const TGLPlotBox * box,
0124                ESliceAxis axis);
0125    TGLTH3Slice(const TString &sliceName,
0126                const TH3 *hist, const TF3 *fun,
0127                const TGLPlotCoordinates *coord,
0128                const TGLPlotBox * box,
0129                ESliceAxis axis);
0130 
0131    void   DrawSlice(Double_t pos)const;
0132    //SetSliceWidth must have "menu" comment.
0133    void   SetSliceWidth(Int_t width = 1); // *MENU*
0134 
0135    void   SetMinMax(const Rgl::Range_t &newRange)
0136    {
0137       fMinMax = newRange;
0138    }
0139 
0140    const TGLLevelPalette & GetPalette()const
0141    {
0142       return fPalette;
0143    }
0144 
0145 private:
0146    void   PrepareTexCoords(Double_t pos, Int_t sliceBegin, Int_t sliceEnd)const;
0147    void   FindMinMax(Int_t sliceBegin, Int_t sliceEnd)const;
0148    Bool_t PreparePalette()const;
0149    void   DrawSliceTextured(Double_t pos)const;
0150    void   DrawSliceFrame(Int_t low, Int_t up)const;
0151 
0152    ClassDefOverride(TGLTH3Slice, 0) // TH3 slice
0153 };
0154 
0155 
0156 /*
0157    TGLPlotPainter class defines interface to different plot painters.
0158 */
0159 
0160 class TGLPlotPainter;
0161 
0162 /*
0163 Object of this class, created on stack in DrawPlot member-functions,
0164 saves modelview matrix, moves plot to (0; 0; 0), and
0165 restores modelview matrix in dtor.
0166 */
0167 
0168 namespace Rgl {
0169 
0170 class PlotTranslation {
0171 public:
0172    PlotTranslation(const TGLPlotPainter *painter);
0173    ~PlotTranslation();
0174 
0175 private:
0176    const TGLPlotPainter *fPainter;
0177 };
0178 
0179 }
0180 
0181 class TGLPlotPainter : public TVirtualGLPainter {
0182    friend class Rgl::PlotTranslation;
0183 private:
0184    const TColor         *fPadColor;
0185 
0186 protected:
0187    const Float_t        *fPhysicalShapeColor;
0188 
0189    Double_t              fPadPhi;
0190    Double_t              fPadTheta;
0191    TH1                  *fHist;
0192    TAxis                *fXAxis;
0193    TAxis                *fYAxis;
0194    TAxis                *fZAxis;
0195 
0196    TGLPlotCoordinates   *fCoord;
0197    TGLPlotCamera        *fCamera;
0198    TGLSelectionBuffer    fSelection;
0199 
0200    Bool_t                fUpdateSelection;
0201    Bool_t                fSelectionPass;
0202    Int_t                 fSelectedPart;
0203    TPoint                fMousePosition;
0204    mutable Double_t      fXOZSectionPos;
0205    mutable Double_t      fYOZSectionPos;
0206    mutable Double_t      fXOYSectionPos;
0207    TGLPlotBox            fBackBox;
0208    TGLBoxCut             fBoxCut;
0209 
0210    std::vector<Double_t> fZLevels;
0211    Bool_t                fHighColor;
0212 
0213    enum ESelectionBase{
0214       kHighColorSelectionBase = 7,
0215       kTrueColorSelectionBase = 10
0216    };
0217 
0218    Int_t                 fSelectionBase;
0219    mutable Bool_t        fDrawPalette;
0220    Bool_t                fDrawAxes;
0221 
0222 public:
0223 /*   TGLPlotPainter(TH1 *hist, TGLPlotCamera *camera, TGLPlotCoordinates *coord, Int_t context,
0224                   Bool_t xoySelectable, Bool_t xozSelectable, Bool_t yozSelectable);
0225    TGLPlotPainter(TGLPlotCamera *camera, Int_t context);*/
0226    TGLPlotPainter(TH1 *hist, TGLPlotCamera *camera, TGLPlotCoordinates *coord,
0227                   Bool_t xoySelectable, Bool_t xozSelectable, Bool_t yozSelectable);
0228    TGLPlotPainter(TGL5DDataSet *data, TGLPlotCamera *camera, TGLPlotCoordinates *coord);
0229    TGLPlotPainter(TGLPlotCamera *camera);
0230 
0231    const TGLPlotBox& RefBackBox() const { return fBackBox; }
0232    void              SetPhysicalShapeColor(const Float_t *rgba)
0233    {
0234       fPhysicalShapeColor = rgba;
0235    }
0236 
0237    virtual void     InitGL()const = 0;
0238    virtual void     DeInitGL()const = 0;
0239    virtual void     DrawPlot()const = 0;
0240    void     Paint() override;
0241 
0242    //Checks, if mouse cursor is above plot.
0243    Bool_t   PlotSelected(Int_t px, Int_t py) override;
0244    //Init geometry does plot's specific initialization.
0245    virtual Bool_t   InitGeometry() = 0;
0246 
0247    virtual void     StartPan(Int_t px, Int_t py) = 0;
0248    //Pan function is already declared in TVirtualGLPainter.
0249 
0250    //Add string option, it can be a digit in "lego" or "surf".
0251    virtual void     AddOption(const TString &stringOption) = 0;
0252    //Function to process additional events (key presses, mouse clicks.)
0253    virtual void     ProcessEvent(Int_t event, Int_t px, Int_t py) = 0;
0254    //Used by GLpad
0255    void             SetPadColor(const TColor *color);
0256 
0257    virtual void     SetFrameColor(const TColor *frameColor);
0258    //Camera is external to painter, if zoom was changed, or camera
0259    //was rotated, selection must be invalidated.
0260    void             InvalidateSelection();
0261 
0262    enum ECutAxisID {
0263       kXAxis = 7,
0264       kYAxis = 8,
0265       kZAxis = 9
0266    };
0267 
0268    Bool_t           CutAxisSelected()const{return !fHighColor && fSelectedPart <= kZAxis && fSelectedPart >= kXAxis;}
0269 
0270    void SetDrawFrontBox(Bool_t b) {fBackBox.SetDrawFront(b);}
0271    void SetDrawBackBox(Bool_t b) {fBackBox.SetDrawBack(b);}
0272    void SetDrawAxes(Bool_t s) {fDrawAxes = s;}
0273    Bool_t GetDrawAxes() {return fDrawAxes;}
0274 
0275 protected:
0276    const TColor    *GetPadColor()const;
0277    //
0278    void             MoveSection(Int_t px, Int_t py);
0279    void             DrawSections()const;
0280    virtual void     DrawSectionXOZ()const = 0;
0281    virtual void     DrawSectionYOZ()const = 0;
0282    virtual void     DrawSectionXOY()const = 0;
0283 
0284    virtual void     DrawPaletteAxis()const;
0285 
0286    virtual void     ClearBuffers()const;
0287 
0288    void             PrintPlot()const;
0289 
0290    //Attention! After one of this methods was called,
0291    //the GL_MATRIX_MODE could become different from what
0292    //you had before the call: for example, SaveModelviewMatrix will
0293    //change it to GL_MODELVIEW.
0294    void             SaveModelviewMatrix()const;
0295    void             SaveProjectionMatrix()const;
0296 
0297    void             RestoreModelviewMatrix()const;
0298    void             RestoreProjectionMatrix()const;
0299 
0300    ClassDefOverride(TGLPlotPainter, 0) //Base for gl plots
0301 };
0302 
0303 /*
0304    Auxiliary class, which holds different
0305    information about plot's current coordinate system
0306 */
0307 
0308 class TH2Poly;
0309 
0310 class TGLPlotCoordinates {
0311 private:
0312    EGLCoordType    fCoordType;
0313 
0314    Rgl::BinRange_t fXBins;
0315    Rgl::BinRange_t fYBins;
0316    Rgl::BinRange_t fZBins;
0317 
0318    Double_t        fXScale;
0319    Double_t        fYScale;
0320    Double_t        fZScale;
0321 
0322    Rgl::Range_t    fXRange;
0323    Rgl::Range_t    fYRange;
0324    Rgl::Range_t    fZRange;
0325 
0326    Rgl::Range_t    fXRangeScaled;
0327    Rgl::Range_t    fYRangeScaled;
0328    Rgl::Range_t    fZRangeScaled;
0329 
0330    Bool_t          fXLog;
0331    Bool_t          fYLog;
0332    Bool_t          fZLog;
0333 
0334    Bool_t          fModified;
0335    Double_t        fFactor;
0336 
0337 public:
0338    TGLPlotCoordinates();
0339    virtual ~TGLPlotCoordinates();
0340 
0341    void         SetCoordType(EGLCoordType type);
0342    EGLCoordType GetCoordType()const;
0343 
0344    void   SetXLog(Bool_t xLog);
0345    Bool_t GetXLog()const;
0346 
0347    void   SetYLog(Bool_t yLog);
0348    Bool_t GetYLog()const;
0349 
0350    void   SetZLog(Bool_t zLog);
0351    Bool_t GetZLog()const;
0352 
0353    void   ResetModified();
0354    Bool_t Modified()const;
0355    //
0356    Bool_t SetRanges(const TH1 *hist, Bool_t errors = kFALSE, Bool_t zBins = kFALSE);
0357    //
0358    Bool_t SetRanges(TH2Poly *hist);
0359    //
0360    Bool_t SetRanges(const TAxis *xAxis, const TAxis *yAxis, const TAxis *zAxis);
0361 
0362    Int_t  GetNXBins()const;
0363    Int_t  GetNYBins()const;
0364    Int_t  GetNZBins()const;
0365 
0366    const Rgl::BinRange_t &GetXBins()const;
0367    const Rgl::BinRange_t &GetYBins()const;
0368    const Rgl::BinRange_t &GetZBins()const;
0369 
0370    const Rgl::Range_t    &GetXRange()const;
0371    Double_t               GetXLength()const;
0372    const Rgl::Range_t    &GetYRange()const;
0373    Double_t               GetYLength()const;
0374    const Rgl::Range_t    &GetZRange()const;
0375    Double_t               GetZLength()const;
0376 
0377    const Rgl::Range_t    &GetXRangeScaled()const;
0378    const Rgl::Range_t    &GetYRangeScaled()const;
0379    const Rgl::Range_t    &GetZRangeScaled()const;
0380 
0381    Double_t GetXScale()const{return fXScale;}
0382    Double_t GetYScale()const{return fYScale;}
0383    Double_t GetZScale()const{return fZScale;}
0384 
0385    Int_t    GetFirstXBin()const{return fXBins.first;}
0386    Int_t    GetLastXBin()const{return fXBins.second;}
0387    Int_t    GetFirstYBin()const{return fYBins.first;}
0388    Int_t    GetLastYBin()const{return fYBins.second;}
0389    Int_t    GetFirstZBin()const{return fZBins.first;}
0390    Int_t    GetLastZBin()const{return fZBins.second;}
0391 
0392    Double_t GetFactor()const;
0393 
0394 private:
0395    Bool_t SetRangesPolar(const TH1 *hist);
0396    Bool_t SetRangesCylindrical(const TH1 *hist);
0397    Bool_t SetRangesSpherical(const TH1 *hist);
0398 
0399    Bool_t SetRangesCartesian(const TH1 *hist, Bool_t errors = kFALSE, Bool_t zBins = kFALSE);
0400 
0401    TGLPlotCoordinates(const TGLPlotCoordinates &);
0402    TGLPlotCoordinates &operator = (const TGLPlotCoordinates &);
0403 
0404    ClassDef(TGLPlotCoordinates, 0)//Auxilary class, holds plot dimensions.
0405 };
0406 
0407 class TGLLevelPalette;
0408 
0409 namespace Rgl {
0410 
0411 void DrawPalette(const TGLPlotCamera *camera, const TGLLevelPalette &palette);
0412 void DrawPalette(const TGLPlotCamera *camera, const TGLLevelPalette &palette,
0413                  const std::vector<Double_t> &levels);
0414 void DrawPaletteAxis(const TGLPlotCamera *camera, const Range_t &minMax, Bool_t logZ);
0415 
0416 //Polygonal histogram (TH2Poly) is slightly stretched along x and y.
0417 extern const Double_t gH2PolyScaleXY;
0418 
0419 }
0420 
0421 #endif