Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGLAxisPainter.h
Go to the documentation of this file.
1 // @(#)root/gl:$Id$
2 // Author: Alja Mrak-Tadel 2009
3 
4 /*************************************************************************
5 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11 
12 #ifndef ROOT_TGLAxisPainter
13 #define ROOT_TGLAxisPainter
14 
15 #include "TGLUtil.h"
16 #include "TGLFontManager.h"
17 
18 class TAttAxis;
19 class TAxis;
20 class TH1;
21 class TPMERegexp;
22 class TGLRnrCtx;
23 
24 
25 //==============================================================================
26 // TGLAxisPainter
27 //==============================================================================
28 
29 class TGLAxisPainter
30 {
31 public:
32  typedef std::pair <Float_t, Float_t> Lab_t; // label <pos, value> pair
33  typedef std::vector<Lab_t> LabVec_t;
34  typedef std::pair <Float_t, Int_t> TM_t; // tick-mark <pos, order> pair
35  typedef std::vector<TM_t> TMVec_t; // vector od tick lines
36 
37 private:
38  TGLAxisPainter(const TGLAxisPainter&); // Not implemented
39  TGLAxisPainter& operator=(const TGLAxisPainter&); // Not implemented
40 
41  // Print format derived from attributers.
42  Int_t fExp;
43  Int_t fMaxDigits;
44  Int_t fDecimals;
45  TString fFormat;
46 
47  // Font derived from axis attributes.
48  TGLFont fLabelFont;
49  TGLFont fTitleFont;
50 
51  // Print format.
52  void LabelsLimits(const char *label, Int_t &first, Int_t &last) const;
53  void FormAxisValue(Double_t x, TString &s) const;
54 
55 protected:
56  TAttAxis *fAttAxis; // Model.
57  Bool_t fUseAxisColors; // Use colors from axes or from GL-rnr-ctx.
58  TGLFont::EMode fFontMode; // To be put into TAttAxis
59  LabVec_t fLabVec; // List of Labels position-value pairs
60  TMVec_t fTMVec; // List of tick-mark position-value pairs
61 
62  //
63  // Additional axis attributes required for GL rendering:
64 
65  // Orientation
66  TGLVector3 fDir;
67  TGLVector3 fTMOff[3];
68  Int_t fTMNDim;
69 
70  // Font.
71  Int_t fLabelPixelFontSize;
72  Double_t fLabel3DFontSize;
73  Int_t fTitlePixelFontSize;
74  Double_t fTitle3DFontSize;
75 
76  // Labels options. Allready exist in TAttAxis, but can't be set.
77  TGLFont::ETextAlignH_e fLabelAlignH;
78  TGLFont::ETextAlignV_e fLabelAlignV;
79  TGLVector3 fTitlePos;
80  TPMERegexp *fAllZeroesRE;
81 
82 public:
83  TGLAxisPainter();
84  virtual ~TGLAxisPainter();
85 
86  // GetSets.
87  Int_t GetTMNDim() const { return fTMNDim; }
88  void SetTMNDim(Int_t x) { fTMNDim = x; }
89 
90  TGLVector3& RefDir() { return fDir; }
91  TGLVector3& RefTMOff(Int_t i) { return fTMOff[i]; }
92 
93  TGLFont::EMode GetFontMode() const { return fFontMode; }
94  void SetFontMode(TGLFont::EMode m) { fFontMode=m; }
95 
96  // this setter not necessary
97  void SetLabelPixelFontSize(Int_t fs) { fLabelPixelFontSize=fs; }
98  Int_t GetLabelPixelFontSize() const { return fLabelPixelFontSize; }
99  void SetTitlePixelFontSize(Int_t fs) { fTitlePixelFontSize=fs; }
100  Int_t GetTitlePixelFontSize() const { return fTitlePixelFontSize; }
101 
102  TGLVector3& RefTitlePos() { return fTitlePos; }
103 
104 
105  void SetLabelAlign(TGLFont::ETextAlignH_e, TGLFont::ETextAlignV_e);
106 
107  LabVec_t& RefLabVec() { return fLabVec; }
108  TMVec_t& RefTMVec() { return fTMVec; }
109 
110  void SetAttAxis(TAttAxis* a) { fAttAxis = a; }
111  TAttAxis* GetAttAxis() { return fAttAxis; }
112 
113  void SetUseAxisColors(Bool_t x) { fUseAxisColors = x; }
114  Bool_t GetUseAxisColors() const { return fUseAxisColors; }
115 
116  // Utility.
117  void SetLabelFont(TGLRnrCtx &rnrCtx, const char* fontName, Int_t pixelSize = 64, Double_t font3DSize = -1);
118  void SetTitleFont(TGLRnrCtx &rnrCtx, const char* fontName, Int_t pixelSize = 64, Double_t font3DSize = -1);
119 
120  void SetTextFormat(Double_t min, Double_t max, Double_t binWidth);
121 
122  // Renderers.
123  void RnrText (const TString &txt, const TGLVector3 &pos, TGLFont::ETextAlignH_e aH, TGLFont::ETextAlignV_e aV, const TGLFont &font) const;
124  void RnrTitle(const TString &title, TGLVector3 &pos, TGLFont::ETextAlignH_e aH, TGLFont::ETextAlignV_e aV) const;
125  void RnrLabels() const;
126  void RnrLines() const;
127 
128  void PaintAxis(TGLRnrCtx& ctx, TAxis* ax);
129 
130  ClassDef(TGLAxisPainter, 0); // GL axis painter.
131 };
132 
133 
134 //==============================================================================
135 // TGLAxisPainterBox
136 //==============================================================================
137 
138 class TGLAxisPainterBox : public TGLAxisPainter
139 {
140 protected:
141  TGLVector3 fAxisTitlePos[3];
142  TAxis* fAxis[3];
143 
144 public:
145  TGLAxisPainterBox();
146  virtual ~TGLAxisPainterBox();
147 
148  void SetAxis3DTitlePos(TGLRnrCtx &rnrCtx);
149  void DrawAxis3D(TGLRnrCtx &rnrCtx);
150 
151  void PlotStandard(TGLRnrCtx &rnrCtx, TH1* histo, const TGLBoundingBox& bbox);
152 
153  ClassDef(TGLAxisPainterBox, 0); // Painter of GL axes for a 3D box.
154 };
155 
156 #endif