ROOT  6.06/09
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:
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);
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 
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;}
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 
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 
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's back box.
Rgl::Range_t GetYRange() const
Camera for TGLPlotPainter and sub-classes.
Definition: TGLPlotCamera.h:21
virtual void DrawPaletteAxis() const
Draw. Palette. Axis.
Bool_t IsInCut(const V *v) const
PlotTranslation(const TGLPlotPainter *painter)
Int_t GetNXBins() const
Number of X bins.
const Rgl::Range_t & GetZRangeScaled() const
Scaled range.
void MoveBox(Int_t px, Int_t py, Int_t axisID)
Move box cut along selected direction.
Double_t fXLength
const TGLLevelPalette & GetPalette() const
Bool_t PreparePalette() const
Initialize color palette.
void SetFactor(Double_t f)
Double_t GetXLength() const
X length.
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
Int_t GetLastXBin() const
const TF3 * fF3
Double_t fYOZSectionPos
virtual void ProcessEvent(Int_t event, Int_t px, Int_t py)=0
Rgl::Range_t fXRange
const Rgl::BinRange_t & GetXBins() const
X bins range.
const Rgl::Range_t & GetYRangeScaled() const
Scaled range.
Basic string class.
Definition: TString.h:137
Bool_t GetDrawAxes()
Int_t GetFirstZBin() 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's sizes.
void DrawPalette(const TGLPlotCamera *camera, const TGLLevelPalette &palette)
Draw. Palette.
void DrawPaletteAxis(const TGLPlotCamera *camera, const Range_t &minMax, Bool_t logZ)
Rgl::Range_t GetZRange() const
const TGLPlotCoordinates * fCoord
const Rgl::BinRange_t & GetZBins() const
Z bins range.
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.
Double_t GetZScale() const
Int_t GetFirstXBin() const
TPoint fMousePos
Bool_t SetRangesCartesian(const TH1 *hist, Bool_t errors=kFALSE, Bool_t zBins=kFALSE)
Set bin ranges, ranges, etc.
Rgl::BinRange_t fYBins
const Double_t gH2PolyScaleXY
virtual void ClearBuffers() const
Double_t GetZLength() const
Z length.
virtual void SetFrameColor(const TColor *frameColor)
Set plot's back box color.
TGLBoxCut(const TGLPlotBox *plotBox)
TGL2DArray< Double_t > fTexCoords
void SaveProjectionMatrix() const
#define ClassDef(name, id)
Definition: Rtypes.h:254
virtual ~TGLBoxCut()
Destructor.
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
void DrawSlice(Double_t pos) const
Draw slice.
TGLPlotCoordinates & operator=(const TGLPlotCoordinates &)
Double_t fXOZSectionPos
virtual Bool_t PlotSelected(Int_t px, Int_t py)
Read color buffer content to find selected object.
virtual void DrawSectionYOZ() const =0
const Rgl::Range_t & GetXRange() const
X range.
void SetDrawFront(Bool_t d)
Definition: TGLPlotBox.h:83
void SetYLog(Bool_t yLog)
If log changed, sections must be reset, set fModified.
TGLPlotBox fBackBox
ESliceAxis fAxisType
Rgl::Range_t fXRange
Implementation of a box around a histogram/function for plot-painters.
Definition: TGLPlotBox.h:30
Bool_t SetRangesSpherical(const TH1 *hist)
Set ranges spherical.
Double_t GetXScale() const
The 3-D histogram classes derived from the 1-D histogram classes.
Definition: TH3.h:35
Int_t GetNZBins() const
Number of Z bins.
Rgl::BinRange_t fZBins
virtual void StartPan(Int_t px, Int_t py)=0
Definition: TPoint.h:33
Bool_t GetZLog() const
Get Z log.
Bool_t SetRangesPolar(const TH1 *hist)
Set bin ranges, ranges, etc.
Double_t fPadTheta
void RestoreProjectionMatrix() const
void SetDrawBackBox(Bool_t b)
const Rgl::BinRange_t & GetYBins() const
Y bins range.
TGLPlotCamera * fCamera
Bool_t GetYLog() const
Get Y log.
void SetSliceWidth(Int_t width=1)
Set Slice width.
TGLPlotPainter(TH1 *hist, TGLPlotCamera *camera, TGLPlotCoordinates *coord, Bool_t xoySelectable, Bool_t xozSelectable, Bool_t yozSelectable)
Class to manage histogram axis.
Definition: TAxis.h:36
EGLCoordType
Definition: TGLUtil.h:45
void DrawBox(Bool_t selectionPass, Int_t selected) const
Draw cut as a semi-transparent box.
SVector< double, 2 > v
Definition: Dict.h:5
A 3-Dim function with parameters.
Definition: TF3.h:30
Int_t GetLastZBin() const
std::pair< Int_t, Int_t > BinRange_t
Definition: TGLUtil.h:1196
virtual void DrawSectionXOY() const =0
void SetPadColor(const TColor *color)
Used in a pad.
void DrawSections() const
Draw sections (if any).
Rgl::Range_t fYRange
ClassDef(TVirtualGLPainter, 0)
Helper class for plot-painters holding information about axis ranges, numbers of bins and flags if ce...
void ResetModified()
Reset modified.
TGLVertex3 fCenter
void SaveModelviewMatrix() const
Rgl::Range_t GetXRange() const
void SetXLog(Bool_t xLog)
If log changed, sections must be reset, set fModified.
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
std::vector< Double_t > fZLevels
Rgl::Range_t fYRangeScaled
virtual void AddOption(const TString &stringOption)=0
Bool_t IsActive() const
void SetActive(Bool_t a)
Turn the box cut on/off.
const TColor * fPadColor
void DrawSliceFrame(Int_t low, Int_t up) const
Draw slice frame.
void RestoreModelviewMatrix() const
void PrepareTexCoords(Double_t pos, Int_t sliceBegin, Int_t sliceEnd) const
Prepare TexCoords.
const TAxis * fAxis
void SetDrawFrontBox(Bool_t b)
double f(double x)
double Double_t
Definition: RtypesCore.h:55
virtual Bool_t InitGeometry()=0
int type
Definition: TGX11.cxx:120
void SetCoordType(EGLCoordType type)
If coord type was changed, plot must reset sections (if any), set fModified.
Int_t GetFirstYBin() const
Rgl::Range_t fZRange
Int_t GetNYBins() const
Number of Y bins.
The TH1 histogram class.
Definition: TH1.h:80
virtual void DrawSectionXOZ() const =0
The color creation and management class.
Definition: TColor.h:23
Bool_t SetRanges(const TH1 *hist, Bool_t errors=kFALSE, Bool_t zBins=kFALSE)
Set bin ranges, ranges.
virtual void DeInitGL() const =0
Double_t GetYLength() const
Y length.
Bool_t CutAxisSelected() 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.
EGLCoordType GetCoordType() const
Get coordinates type.
Double_t GetFactor() const
Get factor.
Double_t fXOYSectionPos
const Rgl::Range_t & GetYRange() const
Y range.
void PrintPlot() const
Generate PS using gl2ps.
Rgl::BinRange_t fXBins
const Rgl::Range_t & GetXRangeScaled() const
Scaled range.
const Float_t * fPhysicalShapeColor
Bool_t GetXLog() const
Get X log.
Double_t GetYScale() const
void SetZLog(Bool_t zLog)
If log changed, sections must be reset, set fModified.
const TGLPlotPainter * fPainter
void StartMovement(Int_t px, Int_t py)
Start cut's movement.
void MoveSection(Int_t px, Int_t py)
Create dynamic profile using selected plane.
Double_t fYLength
Rgl::Range_t fXRangeScaled
Bool_t Modified() const
Modified.
Int_t GetLastYBin() const
void FindMinMax(Int_t sliceBegin, Int_t sliceEnd) const
Find minimum and maximum for slice.
Bool_t SetRangesCylindrical(const TH1 *hist)
Set ranges cylindrical.
virtual void InitGL() const =0
TGLTH3Slice(const TString &sliceName, const TH3 *hist, const TGLPlotCoordinates *coord, const TGLPlotBox *box, ESliceAxis axis)
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
void DrawSliceTextured(Double_t pos) const
Draw slice textured.
const Bool_t kTRUE
Definition: Rtypes.h:91
TGLPlotCoordinates * fCoord
virtual void Paint()
Draw lego/surf/whatever you can.
virtual void DrawPlot() const =0
virtual ~TGLPlotCoordinates()
Destructor.
TGLBoxCut fBoxCut
void InvalidateSelection()
Selection must be updated.
void SetPhysicalShapeColor(const Float_t *rgba)
const TColor * GetPadColor() const
Get pad color.
void SetDrawAxes(Bool_t s)
const TGLPlotBox *const fPlotBox
const TGLPlotBox & RefBackBox() const
const Rgl::Range_t & GetZRange() const
Z range.
2D Histogram with Polygonal Bins
Definition: TH2Poly.h:70
Rgl::Range_t fYRange