Logo ROOT   6.08/07
Reference Guide
TGLPlotPainter.h
Go to the documentation of this file.
1 // @(#)root/gl:$Id$
2 // Author: Timur Pocheptsov 14/06/2006
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, 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_TGLPlotPainter
13 #define ROOT_TGLPlotPainter
14 
15 #include <vector>
16 
17 #ifndef ROOT_TVirtualGL
18 #include "TVirtualGL.h"
19 #endif
20 #ifndef ROOT_TGLPlotBox
21 #include "TGLPlotBox.h"
22 #endif
23 #ifndef ROOT_TPoint
24 #include "TPoint.h"
25 #endif
26 #ifndef ROOT_TGLUtil
27 #include "TGLUtil.h"
28 #endif
29 #ifndef ROOT_TNamed
30 #include "TNamed.h"
31 #endif
32 
33 class TGLPlotCoordinates;
34 class TGLPlotCamera;
35 class TGL5DDataSet;
36 class TString;
37 class TColor;
38 class TAxis;
39 class TH1;
40 class TH3;
41 class TF3;
42 
43 /*
44  Box cut. When attached to a plot, cuts away a part of it.
45  Can be moved in a plot's own area in X/Y/Z directions.
46 */
47 
48 class TGLBoxCut {
49 private:
57 
58  const TGLPlotBox * const fPlotBox;
61 
63 
64 public:
65  TGLBoxCut(const TGLPlotBox *plotBox);
66  virtual ~TGLBoxCut();
67 
68  void TurnOnOff();
69  Bool_t IsActive()const{return fActive;}
70  void SetActive(Bool_t a);
71 
72  void ResetBoxGeometry();
73 
74  void SetFactor(Double_t f){fFactor = f;}
75 
76  void DrawBox(Bool_t selectionPass, Int_t selected)const;
77 
78  void StartMovement(Int_t px, Int_t py);
79  void MoveBox(Int_t px, Int_t py, Int_t axisID);
80 
81  Bool_t IsInCut(Double_t xMin, Double_t xMax, Double_t yMin, Double_t yMax,
82  Double_t zMin, Double_t zMax)const;
83 
84  template<class V>
85  Bool_t IsInCut(const V * v) const
86  {
87  //Check, if box defined by xmin/xmax etc. is in cut.
88  if (v[0] >= fXRange.first && v[0] < fXRange.second &&
89  v[1] >= fYRange.first && v[1] < fYRange.second &&
90  v[2] >= fZRange.first && v[2] < fZRange.second)
91  return kTRUE;
92  return kFALSE;
93  }
94 
95  Rgl::Range_t GetXRange()const{return fXRange;}
96  Rgl::Range_t GetYRange()const{return fYRange;}
97  Rgl::Range_t GetZRange()const{return fZRange;}
98 
99 private:
100  void AdjustBox();
101 
102  ClassDef(TGLBoxCut, 0)//Cuts away part of a plot.
103 };
104 
105 /*
106  2D contour for TH3 slicing.
107 */
108 
109 class TGLTH3Slice : public TNamed {
110 public:
111  enum ESliceAxis {kXOZ, kYOZ, kXOY};
112 
113 private:
115  const TAxis *fAxis;
117 
119  const TGLPlotBox *fBox;
121 
122  const TH3 *fHist;
123  const TF3 *fF3;
124 
126 
128 
129 public:
130  TGLTH3Slice(const TString &sliceName,
131  const TH3 *hist,
132  const TGLPlotCoordinates *coord,
133  const TGLPlotBox * box,
134  ESliceAxis axis);
135  TGLTH3Slice(const TString &sliceName,
136  const TH3 *hist, const TF3 *fun,
137  const TGLPlotCoordinates *coord,
138  const TGLPlotBox * box,
139  ESliceAxis axis);
140 
141  void DrawSlice(Double_t pos)const;
142  //SetSliceWidth must have "menu" comment.
143  void SetSliceWidth(Int_t width = 1); // *MENU*
144 
145  void SetMinMax(const Rgl::Range_t &newRange)
146  {
147  fMinMax = newRange;
148  }
149 
151  {
152  return fPalette;
153  }
154 
155 private:
156  void PrepareTexCoords(Double_t pos, Int_t sliceBegin, Int_t sliceEnd)const;
157  void FindMinMax(Int_t sliceBegin, Int_t sliceEnd)const;
158  Bool_t PreparePalette()const;
159  void DrawSliceTextured(Double_t pos)const;
160  void DrawSliceFrame(Int_t low, Int_t up)const;
161 
162  ClassDef(TGLTH3Slice, 0) // TH3 slice
163 };
164 
165 
166 /*
167  TGLPlotPainter class defines interface to different plot painters.
168 */
169 
170 class TGLPlotPainter;
171 
172 /*
173 Object of this class, created on stack in DrawPlot member-functions,
174 saves modelview matrix, moves plot to (0; 0; 0), and
175 restores modelview matrix in dtor.
176 */
177 
178 namespace Rgl {
179 
181 public:
182  PlotTranslation(const TGLPlotPainter *painter);
183  ~PlotTranslation();
184 
185 private:
187 };
188 
189 }
190 
192  friend class Rgl::PlotTranslation;
193 private:
195 
196 protected:
198 
205 
209 
219 
220  std::vector<Double_t> fZLevels;
222 
224  kHighColorSelectionBase = 7,
225  kTrueColorSelectionBase = 10
226  };
227 
231 
232 public:
233 /* TGLPlotPainter(TH1 *hist, TGLPlotCamera *camera, TGLPlotCoordinates *coord, Int_t context,
234  Bool_t xoySelectable, Bool_t xozSelectable, Bool_t yozSelectable);
235  TGLPlotPainter(TGLPlotCamera *camera, Int_t context);*/
236  TGLPlotPainter(TH1 *hist, TGLPlotCamera *camera, TGLPlotCoordinates *coord,
237  Bool_t xoySelectable, Bool_t xozSelectable, Bool_t yozSelectable);
239  TGLPlotPainter(TGLPlotCamera *camera);
240 
241  const TGLPlotBox& RefBackBox() const { return fBackBox; }
242  void SetPhysicalShapeColor(const Float_t *rgba)
243  {
244  fPhysicalShapeColor = rgba;
245  }
246 
247  virtual void InitGL()const = 0;
248  virtual void DeInitGL()const = 0;
249  virtual void DrawPlot()const = 0;
250  virtual void Paint();
251 
252  //Checks, if mouse cursor is above plot.
253  virtual Bool_t PlotSelected(Int_t px, Int_t py);
254  //Init geometry does plot's specific initialization.
255  virtual Bool_t InitGeometry() = 0;
256 
257  virtual void StartPan(Int_t px, Int_t py) = 0;
258  //Pan function is already declared in TVirtualGLPainter.
259 
260  //Add string option, it can be a digit in "lego" or "surf".
261  virtual void AddOption(const TString &stringOption) = 0;
262  //Function to process additional events (key presses, mouse clicks.)
263  virtual void ProcessEvent(Int_t event, Int_t px, Int_t py) = 0;
264  //Used by GLpad
265  void SetPadColor(const TColor *color);
266 
267  virtual void SetFrameColor(const TColor *frameColor);
268  //Camera is external to painter, if zoom was changed, or camera
269  //was rotated, selection must be invalidated.
270  void InvalidateSelection();
271 
272  enum ECutAxisID {
273  kXAxis = 7,
274  kYAxis = 8,
275  kZAxis = 9
276  };
277 
278  Bool_t CutAxisSelected()const{return !fHighColor && fSelectedPart <= kZAxis && fSelectedPart >= kXAxis;}
279 
280  void SetDrawFrontBox(Bool_t b) {fBackBox.SetDrawFront(b);}
281  void SetDrawBackBox(Bool_t b) {fBackBox.SetDrawBack(b);}
282  void SetDrawAxes(Bool_t s) {fDrawAxes = s;}
283  Bool_t GetDrawAxes() {return fDrawAxes;}
284 
285 protected:
286  const TColor *GetPadColor()const;
287  //
288  void MoveSection(Int_t px, Int_t py);
289  void DrawSections()const;
290  virtual void DrawSectionXOZ()const = 0;
291  virtual void DrawSectionYOZ()const = 0;
292  virtual void DrawSectionXOY()const = 0;
293 
294  virtual void DrawPaletteAxis()const;
295 
296  virtual void ClearBuffers()const;
297 
298  void PrintPlot()const;
299 
300  //Attention! After one of this methods was called,
301  //the GL_MATRIX_MODE could become different from what
302  //you had before the call: for example, SaveModelviewMatrix will
303  //change it to GL_MODELVIEW.
304  void SaveModelviewMatrix()const;
305  void SaveProjectionMatrix()const;
306 
307  void RestoreModelviewMatrix()const;
308  void RestoreProjectionMatrix()const;
309 
310  ClassDef(TGLPlotPainter, 0) //Base for gl plots
311 };
312 
313 /*
314  Auxiliary class, which holds different
315  information about plot's current coordinate system
316 */
317 
318 class TH2Poly;
319 
321 private:
323 
327 
331 
335 
339 
343 
346 
347 public:
349  virtual ~TGLPlotCoordinates();
350 
351  void SetCoordType(EGLCoordType type);
352  EGLCoordType GetCoordType()const;
353 
354  void SetXLog(Bool_t xLog);
355  Bool_t GetXLog()const;
356 
357  void SetYLog(Bool_t yLog);
358  Bool_t GetYLog()const;
359 
360  void SetZLog(Bool_t zLog);
361  Bool_t GetZLog()const;
362 
363  void ResetModified();
364  Bool_t Modified()const;
365  //
366  Bool_t SetRanges(const TH1 *hist, Bool_t errors = kFALSE, Bool_t zBins = kFALSE);
367  //
368  Bool_t SetRanges(TH2Poly *hist);
369  //
370  Bool_t SetRanges(const TAxis *xAxis, const TAxis *yAxis, const TAxis *zAxis);
371 
372  Int_t GetNXBins()const;
373  Int_t GetNYBins()const;
374  Int_t GetNZBins()const;
375 
376  const Rgl::BinRange_t &GetXBins()const;
377  const Rgl::BinRange_t &GetYBins()const;
378  const Rgl::BinRange_t &GetZBins()const;
379 
380  const Rgl::Range_t &GetXRange()const;
381  Double_t GetXLength()const;
382  const Rgl::Range_t &GetYRange()const;
383  Double_t GetYLength()const;
384  const Rgl::Range_t &GetZRange()const;
385  Double_t GetZLength()const;
386 
387  const Rgl::Range_t &GetXRangeScaled()const;
388  const Rgl::Range_t &GetYRangeScaled()const;
389  const Rgl::Range_t &GetZRangeScaled()const;
390 
391  Double_t GetXScale()const{return fXScale;}
392  Double_t GetYScale()const{return fYScale;}
393  Double_t GetZScale()const{return fZScale;}
394 
395  Int_t GetFirstXBin()const{return fXBins.first;}
396  Int_t GetLastXBin()const{return fXBins.second;}
397  Int_t GetFirstYBin()const{return fYBins.first;}
398  Int_t GetLastYBin()const{return fYBins.second;}
399  Int_t GetFirstZBin()const{return fZBins.first;}
400  Int_t GetLastZBin()const{return fZBins.second;}
401 
402  Double_t GetFactor()const;
403 
404 private:
405  Bool_t SetRangesPolar(const TH1 *hist);
406  Bool_t SetRangesCylindrical(const TH1 *hist);
407  Bool_t SetRangesSpherical(const TH1 *hist);
408 
409  Bool_t SetRangesCartesian(const TH1 *hist, Bool_t errors = kFALSE, Bool_t zBins = kFALSE);
410 
412  TGLPlotCoordinates &operator = (const TGLPlotCoordinates &);
413 
414  ClassDef(TGLPlotCoordinates, 0)//Auxilary class, holds plot dimensions.
415 };
416 
417 class TGLLevelPalette;
418 
419 namespace Rgl {
420 
421 void DrawPalette(const TGLPlotCamera *camera, const TGLLevelPalette &palette);
422 void DrawPalette(const TGLPlotCamera *camera, const TGLLevelPalette &palette,
423  const std::vector<Double_t> &levels);
424 void DrawPaletteAxis(const TGLPlotCamera *camera, const Range_t &minMax, Bool_t logZ);
425 
426 //Polygonal histogram (TH2Poly) is slightly stretched along x and y.
427 extern const Double_t gH2PolyScaleXY;
428 
429 }
430 
431 #endif
void ResetBoxGeometry()
Set geometry using plot&#39;s back box.
void DrawBox(Bool_t selectionPass, Int_t selected) const
Draw cut as a semi-transparent box.
Camera for TGLPlotPainter and sub-classes.
Definition: TGLPlotCamera.h:21
Int_t GetFirstXBin() const
void MoveBox(Int_t px, Int_t py, Int_t axisID)
Move box cut along selected direction.
Double_t fXLength
void SetFactor(Double_t f)
Bool_t fActive
float Float_t
Definition: RtypesCore.h:53
Double_t fFactor
std::pair< Double_t, Double_t > Range_t
Definition: TGLUtil.h:1197
const TF3 * fF3
Double_t fYOZSectionPos
Rgl::Range_t fXRange
Basic string class.
Definition: TString.h:137
Bool_t GetDrawAxes()
Rgl::Range_t GetZRange() const
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TArc * a
Definition: textangle.C:12
const Bool_t kFALSE
Definition: Rtypes.h:92
void TurnOnOff()
Turn the box cut on/off.
Rgl::Range_t fZRangeScaled
void AdjustBox()
Box cut is limited by plot&#39;s sizes.
void DrawPaletteAxis(const TGLPlotCamera *camera, const Range_t &minMax, Bool_t logZ)
const TGLPlotCoordinates * fCoord
void SetMinMax(const Rgl::Range_t &newRange)
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
A slice of a TH3.
TPoint fMousePos
Bool_t IsInCut(const V *v) const
Rgl::BinRange_t fYBins
Bool_t CutAxisSelected() const
const Double_t gH2PolyScaleXY
TGLBoxCut(const TGLPlotBox *plotBox)
Constructor.
TGL2DArray< Double_t > fTexCoords
#define ClassDef(name, id)
Definition: Rtypes.h:254
virtual ~TGLBoxCut()
Destructor.
Rgl::Range_t GetXRange() const
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
3 component (x/y/z) vertex class.
Definition: TGLUtil.h:86
void SetDrawBack(Bool_t d)
Definition: TGLPlotBox.h:86
Double_t fXOZSectionPos
Bool_t IsActive() const
void SetDrawFront(Bool_t d)
Definition: TGLPlotBox.h:83
Int_t GetFirstYBin() const
TGLPlotBox fBackBox
ESliceAxis fAxisType
Rgl::Range_t fXRange
Implementation of a box around a histogram/function for plot-painters.
Definition: TGLPlotBox.h:30
The 3-D histogram classes derived from the 1-D histogram classes.
Definition: TH3.h:35
Rgl::BinRange_t fZBins
Definition: TPoint.h:33
Double_t fPadTheta
void SetDrawBackBox(Bool_t b)
TGLPlotCamera * fCamera
Int_t GetLastYBin() const
Class to manage histogram axis.
Definition: TAxis.h:36
EGLCoordType
Definition: TGLUtil.h:45
SVector< double, 2 > v
Definition: Dict.h:5
Rgl::Range_t GetYRange() const
A 3-Dim function with parameters.
Definition: TF3.h:30
std::pair< Int_t, Int_t > BinRange_t
Definition: TGLUtil.h:1196
Rgl::Range_t fYRange
Helper class for plot-painters holding information about axis ranges, numbers of bins and flags if ce...
TGLVertex3 fCenter
EGLCoordType fCoordType
const TGLPlotBox * fBox
TGLLevelPalette fPalette
TGLSelectionBuffer fSelection
Base class for plot-painters that provide GL rendering of various 2D and 3D histograms, functions and parametric surfaces.
Rgl::Range_t fZRange
const TGLPlotBox & RefBackBox() const
std::vector< Double_t > fZLevels
Rgl::Range_t fYRangeScaled
void SetActive(Bool_t a)
Turn the box cut on/off.
const TColor * fPadColor
Double_t GetYScale() const
const TAxis * fAxis
void SetDrawFrontBox(Bool_t b)
double f(double x)
double Double_t
Definition: RtypesCore.h:55
int type
Definition: TGX11.cxx:120
Rgl::Range_t fZRange
The TH1 histogram class.
Definition: TH1.h:80
The color creation and management class.
Definition: TColor.h:23
Int_t GetFirstZBin() const
Int_t GetLastXBin() const
Double_t fXOYSectionPos
void DrawPalette(const TGLPlotCamera *camera, const TGLLevelPalette &palette, const std::vector< Double_t > &levels)
Draw. Palette.
Rgl::BinRange_t fXBins
const Float_t * fPhysicalShapeColor
const TGLPlotPainter * fPainter
void StartMovement(Int_t px, Int_t py)
Start cut&#39;s movement.
Double_t fYLength
Rgl::Range_t fXRangeScaled
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
Rgl::Range_t fMinMax
const TH3 * fHist
Used by plot-painters to determine the area of the plot that is cut away.
Bool_t fUpdateSelection
Double_t fZLength
Int_t GetLastZBin() const
const Bool_t kTRUE
Definition: Rtypes.h:91
TGLPlotCoordinates * fCoord
TGLBoxCut fBoxCut
void SetPhysicalShapeColor(const Float_t *rgba)
Double_t GetZScale() const
void SetDrawAxes(Bool_t s)
const TGLPlotBox *const fPlotBox
Double_t GetXScale() const
2D Histogram with Polygonal Bins
Definition: TH2Poly.h:68
const TGLLevelPalette & GetPalette() const
Bool_t IsInCut(Double_t xMin, Double_t xMax, Double_t yMin, Double_t yMax, Double_t zMin, Double_t zMax) const
Check, if box defined by xmin/xmax etc. is in cut.
Rgl::Range_t fYRange