Logo ROOT   6.14/05
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 #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 
64  void SetFactor(Double_t f){fFactor = f;}
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:
101  enum ESliceAxis {kXOZ, kYOZ, kXOY};
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);
173  ~PlotTranslation();
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 
214  kHighColorSelectionBase = 7,
215  kTrueColorSelectionBase = 10
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 
270  void SetDrawFrontBox(Bool_t b) {fBackBox.SetDrawFront(b);}
271  void SetDrawBackBox(Bool_t b) {fBackBox.SetDrawBack(b);}
272  void SetDrawAxes(Bool_t s) {fDrawAxes = s;}
273  Bool_t GetDrawAxes() {return fDrawAxes;}
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 
341  void SetCoordType(EGLCoordType type);
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.
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:1193
image html pict1_TGaxis_012 png width
Define new text attributes for the label number "labNum".
Definition: TGaxis.cxx:2551
const TF3 * fF3
Double_t fYOZSectionPos
Rgl::Range_t fXRange
Basic string class.
Definition: TString.h:131
Bool_t GetDrawAxes()
#define f(i)
Definition: RSha256.hxx:104
Rgl::Range_t GetZRange() const
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
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:320
virtual ~TGLBoxCut()
Destructor.
Rgl::Range_t GetXRange() const
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
Double_t fXOZSectionPos
Bool_t IsActive() const
void SetDrawFront(Bool_t d)
Definition: TGLPlotBox.h:79
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:26
The 3-D histogram classes derived from the 1-D histogram classes.
Definition: TH3.h:31
Rgl::BinRange_t fZBins
Definition: TPoint.h:31
Double_t fPadTheta
void SetDrawBackBox(Bool_t b)
TGLPlotCamera * fCamera
Int_t GetLastYBin() const
Class to manage histogram axis.
Definition: TAxis.h:30
EGLCoordType
Definition: TGLUtil.h:41
SVector< double, 2 > v
Definition: Dict.h:5
Rgl::Range_t GetYRange() const
auto * a
Definition: textangle.C:12
A 3-Dim function with parameters.
Definition: TF3.h:28
std::pair< Int_t, Int_t > BinRange_t
Definition: TGLUtil.h:1192
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
const Bool_t kFALSE
Definition: RtypesCore.h:88
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 Double_t
Definition: RtypesCore.h:55
int type
Definition: TGX11.cxx:120
Rgl::Range_t fZRange
The TH1 histogram class.
Definition: TH1.h:56
static constexpr double s
The color creation and management class.
Definition: TColor.h:19
Int_t GetFirstZBin() const
Int_t GetLastXBin() const
Binding & operator=(OUT(*fun)(void))
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
TGLPlotCoordinates * fCoord
const Bool_t kTRUE
Definition: RtypesCore.h:87
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:66
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