Logo ROOT  
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
24class TGLPlotCamera;
25class TGL5DDataSet;
26class TString;
27class TColor;
28class TAxis;
29class TH1;
30class TH3;
31class 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
38class TGLBoxCut {
39private:
47
48 const TGLPlotBox * const fPlotBox;
51
53
54public:
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
88
89private:
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
99class TGLTH3Slice : public TNamed {
100public:
102
103private:
105 const TAxis *fAxis;
107
111
112 const TH3 *fHist;
113 const TF3 *fF3;
114
116
118
119public:
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
145private:
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
160class TGLPlotPainter;
161
162/*
163Object of this class, created on stack in DrawPlot member-functions,
164saves modelview matrix, moves plot to (0; 0; 0), and
165restores modelview matrix in dtor.
166*/
167
168namespace Rgl {
169
171public:
172 PlotTranslation(const TGLPlotPainter *painter);
174
175private:
177};
178
179}
180
183private:
185
186protected:
188
195
199
209
210 std::vector<Double_t> fZLevels;
212
216 };
217
221
222public:
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);
230
231 const TGLPlotBox& RefBackBox() const { return fBackBox; }
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
265 kZAxis = 9
266 };
267
268 Bool_t CutAxisSelected()const{return !fHighColor && fSelectedPart <= kZAxis && fSelectedPart >= kXAxis;}
269
274
275protected:
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
308class TH2Poly;
309
311private:
313
317
321
325
329
333
336
337public:
339 virtual ~TGLPlotCoordinates();
340
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
394private:
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
407class TGLLevelPalette;
408
409namespace Rgl {
410
411void DrawPalette(const TGLPlotCamera *camera, const TGLLevelPalette &palette);
412void DrawPalette(const TGLPlotCamera *camera, const TGLLevelPalette &palette,
413 const std::vector<Double_t> &levels);
414void DrawPaletteAxis(const TGLPlotCamera *camera, const Range_t &minMax, Bool_t logZ);
415
416//Polygonal histogram (TH2Poly) is slightly stretched along x and y.
417extern const Double_t gH2PolyScaleXY;
418
419}
420
421#endif
#define b(i)
Definition: RSha256.hxx:100
#define f(i)
Definition: RSha256.hxx:104
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
float Float_t
Definition: RtypesCore.h:53
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassDef(name, id)
Definition: Rtypes.h:326
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
EGLCoordType
Definition: TGLUtil.h:42
int type
Definition: TGX11.cxx:120
const TGLPlotPainter * fPainter
PlotTranslation(const TGLPlotPainter *painter)
Class to manage histogram axis.
Definition: TAxis.h:30
The color creation and management class.
Definition: TColor.h:19
A 3-Dim function with parameters.
Definition: TF3.h:28
Used by plot-painters to determine the area of the plot that is cut away.
Rgl::Range_t GetZRange() const
void MoveBox(Int_t px, Int_t py, Int_t axisID)
Move box cut along selected direction.
void AdjustBox()
Box cut is limited by plot's sizes.
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.
Double_t fYLength
Rgl::Range_t fYRange
void DrawBox(Bool_t selectionPass, Int_t selected) const
Draw cut as a semi-transparent box.
void TurnOnOff()
Turn the box cut on/off.
Double_t fXLength
void SetFactor(Double_t f)
TPoint fMousePos
Bool_t fActive
Bool_t IsInCut(const V *v) const
const TGLPlotBox *const fPlotBox
void StartMovement(Int_t px, Int_t py)
Start cut's movement.
TGLVertex3 fCenter
Bool_t IsActive() const
Double_t fFactor
Double_t fZLength
Rgl::Range_t fZRange
virtual ~TGLBoxCut()
Destructor.
void SetActive(Bool_t a)
Turn the box cut on/off.
void ResetBoxGeometry()
Set geometry using plot's back box.
TGLBoxCut(const TGLPlotBox *plotBox)
Constructor.
Rgl::Range_t GetXRange() const
Rgl::Range_t GetYRange() const
Rgl::Range_t fXRange
Implementation of a box around a histogram/function for plot-painters.
Definition: TGLPlotBox.h:26
void SetDrawFront(Bool_t d)
Definition: TGLPlotBox.h:79
void SetDrawBack(Bool_t d)
Definition: TGLPlotBox.h:82
Camera for TGLPlotPainter and sub-classes.
Definition: TGLPlotCamera.h:22
Helper class for plot-painters holding information about axis ranges, numbers of bins and flags if ce...
Double_t GetZLength() const
Z length.
void SetXLog(Bool_t xLog)
If log changed, sections must be reset, set fModified.
Bool_t SetRanges(const TH1 *hist, Bool_t errors=kFALSE, Bool_t zBins=kFALSE)
Set bin ranges, ranges.
Double_t GetYScale() const
const Rgl::Range_t & GetXRangeScaled() const
Scaled range.
Rgl::BinRange_t fZBins
const Rgl::BinRange_t & GetZBins() const
Z bins range.
Rgl::Range_t fZRangeScaled
Bool_t GetXLog() const
Get X log.
Int_t GetFirstXBin() const
const Rgl::BinRange_t & GetXBins() const
X bins range.
Int_t GetFirstYBin() const
const Rgl::Range_t & GetZRange() const
Z range.
TGLPlotCoordinates(const TGLPlotCoordinates &)
virtual ~TGLPlotCoordinates()
Destructor.
Rgl::Range_t fYRange
EGLCoordType fCoordType
Bool_t SetRangesPolar(const TH1 *hist)
Set bin ranges, ranges, etc.
const Rgl::Range_t & GetYRangeScaled() const
Scaled range.
Bool_t SetRangesCartesian(const TH1 *hist, Bool_t errors=kFALSE, Bool_t zBins=kFALSE)
Set bin ranges, ranges, etc.
void SetCoordType(EGLCoordType type)
If coord type was changed, plot must reset sections (if any), set fModified.
void ResetModified()
Reset modified.
TGLPlotCoordinates()
Constructor.
Bool_t SetRangesCylindrical(const TH1 *hist)
Set ranges cylindrical.
Bool_t GetYLog() const
Get Y log.
Bool_t GetZLog() const
Get Z log.
Bool_t Modified() const
Modified.
Rgl::Range_t fZRange
Double_t GetXScale() const
Double_t GetZScale() const
Int_t GetLastZBin() const
Int_t GetNXBins() const
Number of X bins.
Int_t GetFirstZBin() const
const Rgl::Range_t & GetZRangeScaled() const
Scaled range.
const Rgl::Range_t & GetYRange() const
Y range.
Rgl::BinRange_t fXBins
Double_t GetXLength() const
X length.
void SetZLog(Bool_t zLog)
If log changed, sections must be reset, set fModified.
void SetYLog(Bool_t yLog)
If log changed, sections must be reset, set fModified.
TGLPlotCoordinates & operator=(const TGLPlotCoordinates &)
Bool_t SetRangesSpherical(const TH1 *hist)
Set ranges spherical.
Rgl::BinRange_t fYBins
Int_t GetLastYBin() const
const Rgl::Range_t & GetXRange() const
X range.
Int_t GetNYBins() const
Number of Y bins.
Int_t GetLastXBin() const
Rgl::Range_t fYRangeScaled
EGLCoordType GetCoordType() const
Get coordinates type.
Rgl::Range_t fXRangeScaled
const Rgl::BinRange_t & GetYBins() const
Y bins range.
Int_t GetNZBins() const
Number of Z bins.
Double_t GetYLength() const
Y length.
Rgl::Range_t fXRange
Double_t GetFactor() const
Get factor.
Base class for plot-painters that provide GL rendering of various 2D and 3D histograms,...
Bool_t CutAxisSelected() const
void InvalidateSelection()
Selection must be updated.
void DrawSections() const
Draw sections (if any).
Double_t fPadTheta
const Float_t * fPhysicalShapeColor
TGLPlotPainter(TH1 *hist, TGLPlotCamera *camera, TGLPlotCoordinates *coord, Bool_t xoySelectable, Bool_t xozSelectable, Bool_t yozSelectable)
TGLPlotPainter's ctor.
std::vector< Double_t > fZLevels
virtual void SetFrameColor(const TColor *frameColor)
Set plot's back box color.
const TGLPlotBox & RefBackBox() const
TGLSelectionBuffer fSelection
Double_t fXOYSectionPos
virtual Bool_t PlotSelected(Int_t px, Int_t py)
Read color buffer content to find selected object.
void RestoreModelviewMatrix() const
virtual void DrawPaletteAxis() const
Draw. Palette. Axis.
virtual void ProcessEvent(Int_t event, Int_t px, Int_t py)=0
const TColor * fPadColor
void SetPadColor(const TColor *color)
Used in a pad.
const TColor * GetPadColor() const
Get pad color.
Double_t fXOZSectionPos
void SetDrawAxes(Bool_t s)
virtual void DrawPlot() const =0
virtual Bool_t InitGeometry()=0
void PrintPlot() const
Generate PS using gl2ps.
void SetDrawBackBox(Bool_t b)
TGLBoxCut fBoxCut
virtual void Paint()
Draw lego/surf/whatever you can.
void SetDrawFrontBox(Bool_t b)
virtual void InitGL() const =0
TGLPlotCoordinates * fCoord
virtual void DrawSectionXOY() const =0
TGLPlotBox fBackBox
void SaveProjectionMatrix() const
virtual void StartPan(Int_t px, Int_t py)=0
virtual void DrawSectionYOZ() const =0
Bool_t GetDrawAxes()
void SaveModelviewMatrix() const
void MoveSection(Int_t px, Int_t py)
Create dynamic profile using selected plane.
Bool_t fUpdateSelection
TGLPlotCamera * fCamera
virtual void DeInitGL() const =0
void SetPhysicalShapeColor(const Float_t *rgba)
void RestoreProjectionMatrix() const
virtual void ClearBuffers() const
Double_t fYOZSectionPos
virtual void AddOption(const TString &stringOption)=0
virtual void DrawSectionXOZ() const =0
A slice of a TH3.
const TGLLevelPalette & GetPalette() const
void SetMinMax(const Rgl::Range_t &newRange)
void FindMinMax(Int_t sliceBegin, Int_t sliceEnd) const
Find minimum and maximum for slice.
Rgl::Range_t fMinMax
void DrawSliceFrame(Int_t low, Int_t up) const
Draw slice frame.
const TH3 * fHist
Bool_t PreparePalette() const
Initialize color palette.
const TAxis * fAxis
ESliceAxis fAxisType
const TGLPlotCoordinates * fCoord
void PrepareTexCoords(Double_t pos, Int_t sliceBegin, Int_t sliceEnd) const
Prepare TexCoords.
void DrawSlice(Double_t pos) const
Draw slice.
TGLLevelPalette fPalette
TGLTH3Slice(const TString &sliceName, const TH3 *hist, const TGLPlotCoordinates *coord, const TGLPlotBox *box, ESliceAxis axis)
Constructor.
void SetSliceWidth(Int_t width=1)
Set Slice width.
const TGLPlotBox * fBox
void DrawSliceTextured(Double_t pos) const
Draw slice textured.
const TF3 * fF3
TGL2DArray< Double_t > fTexCoords
3 component (x/y/z) vertex class.
Definition: TGLUtil.h:83
The TH1 histogram class.
Definition: TH1.h:56
2D Histogram with Polygonal Bins
Definition: TH2Poly.h:66
The 3-D histogram classes derived from the 1-D histogram classes.
Definition: TH3.h:31
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
Definition: TPoint.h:31
Basic string class.
Definition: TString.h:131
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
void DrawPalette(const TGLPlotCamera *camera, const TGLLevelPalette &palette)
Draw. Palette.
void DrawPaletteAxis(const TGLPlotCamera *camera, const Range_t &minMax, Bool_t logZ)
std::pair< Int_t, Int_t > BinRange_t
Definition: TGLUtil.h:1193
std::pair< Double_t, Double_t > Range_t
Definition: TGLUtil.h:1194
const Double_t gH2PolyScaleXY
static constexpr double s
auto * a
Definition: textangle.C:12