Logo ROOT   6.10/00
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 #include "TVirtualGL.h"
18 #include "TGLPlotBox.h"
19 #include "TPoint.h"
20 #include "TGLUtil.h"
21 #include "TNamed.h"
22 
23 class TGLPlotCoordinates;
24 class TGLPlotCamera;
25 class TGL5DDataSet;
26 class TString;
27 class TColor;
28 class TAxis;
29 class TH1;
30 class TH3;
31 class TF3;
32 
33 /*
34  Box cut. When attached to a plot, cuts away a part of it.
35  Can be moved in a plot's own area in X/Y/Z directions.
36 */
37 
38 class TGLBoxCut {
39 private:
47 
48  const TGLPlotBox * const fPlotBox;
51 
53 
54 public:
55  TGLBoxCut(const TGLPlotBox *plotBox);
56  virtual ~TGLBoxCut();
57 
58  void TurnOnOff();
59  Bool_t IsActive()const{return fActive;}
60  void SetActive(Bool_t a);
61 
62  void ResetBoxGeometry();
63 
65 
66  void DrawBox(Bool_t selectionPass, Int_t selected)const;
67 
68  void StartMovement(Int_t px, Int_t py);
69  void MoveBox(Int_t px, Int_t py, Int_t axisID);
70 
71  Bool_t IsInCut(Double_t xMin, Double_t xMax, Double_t yMin, Double_t yMax,
72  Double_t zMin, Double_t zMax)const;
73 
74  template<class V>
75  Bool_t IsInCut(const V * v) const
76  {
77  //Check, if box defined by xmin/xmax etc. is in cut.
78  if (v[0] >= fXRange.first && v[0] < fXRange.second &&
79  v[1] >= fYRange.first && v[1] < fYRange.second &&
80  v[2] >= fZRange.first && v[2] < fZRange.second)
81  return kTRUE;
82  return kFALSE;
83  }
84 
85  Rgl::Range_t GetXRange()const{return fXRange;}
86  Rgl::Range_t GetYRange()const{return fYRange;}
87  Rgl::Range_t GetZRange()const{return fZRange;}
88 
89 private:
90  void AdjustBox();
91 
92  ClassDef(TGLBoxCut, 0)//Cuts away part of a plot.
93 };
94 
95 /*
96  2D contour for TH3 slicing.
97 */
98 
99 class TGLTH3Slice : public TNamed {
100 public:
102 
103 private:
105  const TAxis *fAxis;
107 
109  const TGLPlotBox *fBox;
111 
112  const TH3 *fHist;
113  const TF3 *fF3;
114 
116 
118 
119 public:
120  TGLTH3Slice(const TString &sliceName,
121  const TH3 *hist,
122  const TGLPlotCoordinates *coord,
123  const TGLPlotBox * box,
124  ESliceAxis axis);
125  TGLTH3Slice(const TString &sliceName,
126  const TH3 *hist, const TF3 *fun,
127  const TGLPlotCoordinates *coord,
128  const TGLPlotBox * box,
129  ESliceAxis axis);
130 
131  void DrawSlice(Double_t pos)const;
132  //SetSliceWidth must have "menu" comment.
133  void SetSliceWidth(Int_t width = 1); // *MENU*
134 
135  void SetMinMax(const Rgl::Range_t &newRange)
136  {
137  fMinMax = newRange;
138  }
139 
141  {
142  return fPalette;
143  }
144 
145 private:
146  void PrepareTexCoords(Double_t pos, Int_t sliceBegin, Int_t sliceEnd)const;
147  void FindMinMax(Int_t sliceBegin, Int_t sliceEnd)const;
148  Bool_t PreparePalette()const;
149  void DrawSliceTextured(Double_t pos)const;
150  void DrawSliceFrame(Int_t low, Int_t up)const;
151 
152  ClassDef(TGLTH3Slice, 0) // TH3 slice
153 };
154 
155 
156 /*
157  TGLPlotPainter class defines interface to different plot painters.
158 */
159 
160 class TGLPlotPainter;
161 
162 /*
163 Object of this class, created on stack in DrawPlot member-functions,
164 saves modelview matrix, moves plot to (0; 0; 0), and
165 restores modelview matrix in dtor.
166 */
167 
168 namespace Rgl {
169 
171 public:
172  PlotTranslation(const TGLPlotPainter *painter);
174 
175 private:
177 };
178 
179 }
180 
182  friend class Rgl::PlotTranslation;
183 private:
185 
186 protected:
188 
195 
199 
209 
210  std::vector<Double_t> fZLevels;
212 
216  };
217 
221 
222 public:
223 /* TGLPlotPainter(TH1 *hist, TGLPlotCamera *camera, TGLPlotCoordinates *coord, Int_t context,
224  Bool_t xoySelectable, Bool_t xozSelectable, Bool_t yozSelectable);
225  TGLPlotPainter(TGLPlotCamera *camera, Int_t context);*/
226  TGLPlotPainter(TH1 *hist, TGLPlotCamera *camera, TGLPlotCoordinates *coord,
227  Bool_t xoySelectable, Bool_t xozSelectable, Bool_t yozSelectable);
229  TGLPlotPainter(TGLPlotCamera *camera);
230 
231  const TGLPlotBox& RefBackBox() const { return fBackBox; }
232  void SetPhysicalShapeColor(const Float_t *rgba)
233  {
234  fPhysicalShapeColor = rgba;
235  }
236 
237  virtual void InitGL()const = 0;
238  virtual void DeInitGL()const = 0;
239  virtual void DrawPlot()const = 0;
240  virtual void Paint();
241 
242  //Checks, if mouse cursor is above plot.
243  virtual Bool_t PlotSelected(Int_t px, Int_t py);
244  //Init geometry does plot's specific initialization.
245  virtual Bool_t InitGeometry() = 0;
246 
247  virtual void StartPan(Int_t px, Int_t py) = 0;
248  //Pan function is already declared in TVirtualGLPainter.
249 
250  //Add string option, it can be a digit in "lego" or "surf".
251  virtual void AddOption(const TString &stringOption) = 0;
252  //Function to process additional events (key presses, mouse clicks.)
253  virtual void ProcessEvent(Int_t event, Int_t px, Int_t py) = 0;
254  //Used by GLpad
255  void SetPadColor(const TColor *color);
256 
257  virtual void SetFrameColor(const TColor *frameColor);
258  //Camera is external to painter, if zoom was changed, or camera
259  //was rotated, selection must be invalidated.
260  void InvalidateSelection();
261 
262  enum ECutAxisID {
263  kXAxis = 7,
264  kYAxis = 8,
265  kZAxis = 9
266  };
267 
268  Bool_t CutAxisSelected()const{return !fHighColor && fSelectedPart <= kZAxis && fSelectedPart >= kXAxis;}
269 
272  void SetDrawAxes(Bool_t s) {fDrawAxes = s;}
274 
275 protected:
276  const TColor *GetPadColor()const;
277  //
278  void MoveSection(Int_t px, Int_t py);
279  void DrawSections()const;
280  virtual void DrawSectionXOZ()const = 0;
281  virtual void DrawSectionYOZ()const = 0;
282  virtual void DrawSectionXOY()const = 0;
283 
284  virtual void DrawPaletteAxis()const;
285 
286  virtual void ClearBuffers()const;
287 
288  void PrintPlot()const;
289 
290  //Attention! After one of this methods was called,
291  //the GL_MATRIX_MODE could become different from what
292  //you had before the call: for example, SaveModelviewMatrix will
293  //change it to GL_MODELVIEW.
294  void SaveModelviewMatrix()const;
295  void SaveProjectionMatrix()const;
296 
297  void RestoreModelviewMatrix()const;
298  void RestoreProjectionMatrix()const;
299 
300  ClassDef(TGLPlotPainter, 0) //Base for gl plots
301 };
302 
303 /*
304  Auxiliary class, which holds different
305  information about plot's current coordinate system
306 */
307 
308 class TH2Poly;
309 
311 private:
313 
317 
321 
325 
329 
333 
336 
337 public:
339  virtual ~TGLPlotCoordinates();
340 
342  EGLCoordType GetCoordType()const;
343 
344  void SetXLog(Bool_t xLog);
345  Bool_t GetXLog()const;
346 
347  void SetYLog(Bool_t yLog);
348  Bool_t GetYLog()const;
349 
350  void SetZLog(Bool_t zLog);
351  Bool_t GetZLog()const;
352 
353  void ResetModified();
354  Bool_t Modified()const;
355  //
356  Bool_t SetRanges(const TH1 *hist, Bool_t errors = kFALSE, Bool_t zBins = kFALSE);
357  //
358  Bool_t SetRanges(TH2Poly *hist);
359  //
360  Bool_t SetRanges(const TAxis *xAxis, const TAxis *yAxis, const TAxis *zAxis);
361 
362  Int_t GetNXBins()const;
363  Int_t GetNYBins()const;
364  Int_t GetNZBins()const;
365 
366  const Rgl::BinRange_t &GetXBins()const;
367  const Rgl::BinRange_t &GetYBins()const;
368  const Rgl::BinRange_t &GetZBins()const;
369 
370  const Rgl::Range_t &GetXRange()const;
371  Double_t GetXLength()const;
372  const Rgl::Range_t &GetYRange()const;
373  Double_t GetYLength()const;
374  const Rgl::Range_t &GetZRange()const;
375  Double_t GetZLength()const;
376 
377  const Rgl::Range_t &GetXRangeScaled()const;
378  const Rgl::Range_t &GetYRangeScaled()const;
379  const Rgl::Range_t &GetZRangeScaled()const;
380 
381  Double_t GetXScale()const{return fXScale;}
382  Double_t GetYScale()const{return fYScale;}
383  Double_t GetZScale()const{return fZScale;}
384 
385  Int_t GetFirstXBin()const{return fXBins.first;}
386  Int_t GetLastXBin()const{return fXBins.second;}
387  Int_t GetFirstYBin()const{return fYBins.first;}
388  Int_t GetLastYBin()const{return fYBins.second;}
389  Int_t GetFirstZBin()const{return fZBins.first;}
390  Int_t GetLastZBin()const{return fZBins.second;}
391 
392  Double_t GetFactor()const;
393 
394 private:
395  Bool_t SetRangesPolar(const TH1 *hist);
396  Bool_t SetRangesCylindrical(const TH1 *hist);
397  Bool_t SetRangesSpherical(const TH1 *hist);
398 
399  Bool_t SetRangesCartesian(const TH1 *hist, Bool_t errors = kFALSE, Bool_t zBins = kFALSE);
400 
403 
404  ClassDef(TGLPlotCoordinates, 0)//Auxilary class, holds plot dimensions.
405 };
406 
407 class TGLLevelPalette;
408 
409 namespace Rgl {
410 
411 void DrawPalette(const TGLPlotCamera *camera, const TGLLevelPalette &palette);
412 void DrawPalette(const TGLPlotCamera *camera, const TGLLevelPalette &palette,
413  const std::vector<Double_t> &levels);
414 void DrawPaletteAxis(const TGLPlotCamera *camera, const Range_t &minMax, Bool_t logZ);
415 
416 //Polygonal histogram (TH2Poly) is slightly stretched along x and y.
417 extern const Double_t gH2PolyScaleXY;
418 
419 }
420 
421 #endif
void ResetBoxGeometry()
Set geometry using plot&#39;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:1193
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:129
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
void TurnOnOff()
Turn the box cut on/off.
Rgl::Range_t fZRangeScaled
void AdjustBox()
Box cut is limited by plot&#39;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&#39;s back box color.
TGLBoxCut(const TGLPlotBox *plotBox)
Constructor.
TGL2DArray< Double_t > fTexCoords
void SaveProjectionMatrix() const
#define ClassDef(name, id)
Definition: Rtypes.h:297
virtual ~TGLBoxCut()
Destructor.
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
3 component (x/y/z) vertex class.
Definition: TGLUtil.h:82
void SetDrawBack(Bool_t d)
Definition: TGLPlotBox.h:82
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:79
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:26
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:31
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:31
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)
TGLPlotPainter&#39;s ctor.
Class to manage histogram axis.
Definition: TAxis.h:30
EGLCoordType
Definition: TGLUtil.h:41
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:28
Int_t GetLastZBin() const
std::pair< Int_t, Int_t > BinRange_t
Definition: TGLUtil.h:1192
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
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
const Bool_t kFALSE
Definition: RtypesCore.h:92
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:56
TGLPlotCoordinates()
Constructor.
virtual void DrawSectionXOZ() const =0
The color creation and management class.
Definition: TColor.h:19
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&#39;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
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
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)
Constructor.
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.
TGLPlotCoordinates * fCoord
virtual void Paint()
Draw lego/surf/whatever you can.
virtual void DrawPlot() const =0
virtual ~TGLPlotCoordinates()
Destructor.
const Bool_t kTRUE
Definition: RtypesCore.h:91
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:66
Rgl::Range_t fYRange