ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
glsurfaces.C
Go to the documentation of this file.
1 // Various surfaces rendered with GL.
2 // This example draws 6 surfaces using OpenGL in pad (one is remake
3 // of a classic surfaces.C, another contains 4 surfaces).
4 //
5 // The commands used are exactly the same as with a normal pad.
6 // The only command to add is: gStyle->SetCanvasPreferGL(true);
7 // Authors: Rene Brun, Timur Pocheptsov
8 
9 void glsurfaces()
10 {
11  gStyle->SetPalette(0);
12 
13  // after this command all legos surfaces (surf/srf1/surf2/surf4/tf3
14  // options) are automatically rendered with OpenGL.
16 
17  TCanvas *c1 = new TCanvas("glc1","Surfaces Drawing Options",200,10,700,900);
18  c1->SetFillColor(42);
20  title = new TPaveText(0.2, 0.96, 0.8, 0.995);
21  title->SetFillColor(33);
22  title->AddText("Examples of Surface options");
23  title->Draw();
24 
25  TPad *pad1 = new TPad("pad1","Gouraud shading", 0.03, 0.50, 0.98, 0.95, 21);
26  TPad *pad2 = new TPad("pad2","Color mesh", 0.03, 0.02, 0.98, 0.48, 21);
27  pad1->Draw();
28  pad2->Draw();
29  // We generate a 2-D function
30  TF2 *f2 = new TF2("f2","x**2 + y**2 - x**3 -8*x*y**4", -1., 1.2, -1.5, 1.5);
31  // Draw this function in pad1 with Gouraud shading option
32  pad1->cd();
33  pad1->SetLogz();
34  f2->SetFillColor(45);
35  f2->Draw("glsurf4");
36 
37  TF2 *f2clone = new TF2("f2clone","x**2 + y**2 - x**3 -8*x*y**4",
38  -1., 1.2, -1.5, 1.5);
39  // Draw this function in pad2 with color mesh option
40  pad2->cd();
41  pad2->SetLogz();
42  f2clone->Draw("glsurf1");
43 
44  //add axis titles. The titles are set on the intermediate
45  //histogram used for visualisation. We must force this histogram
46  //to be created, then force the redrawing of the two pads
47  pad2->Update();
48  f2->GetHistogram()->GetXaxis()->SetTitle("x title");
49  f2->GetHistogram()->GetYaxis()->SetTitle("y title");
50  f2->GetHistogram()->GetXaxis()->SetTitleOffset(1.4);
51  f2->GetHistogram()->GetYaxis()->SetTitleOffset(1.4);
52  f2clone->GetHistogram()->GetXaxis()->SetTitle("x title");
53  f2clone->GetHistogram()->GetYaxis()->SetTitle("y title");
54  f2clone->GetHistogram()->GetXaxis()->SetTitleOffset(1.4);
55  f2clone->GetHistogram()->GetYaxis()->SetTitleOffset(1.4);
56  pad1->Modified();
57  pad2->Modified();
58 
59  TCanvas *c2 = new TCanvas("glc2","Surfaces Drawing Options with gl",
60  700,10,700,700);
61  c2->SetFillColor(42);
63 
64  c2->Divide(2, 2);
65 
66  c2->cd(1);
67  TF2 *fun1 = new TF2("fun1","1000*((sin(x)/x)*(sin(y)/y))+200",
68  -6., 6., -6., 6.);
69  fun1->SetNpx(30);
70  fun1->SetNpy(30);
71  fun1->SetFillColor(kGreen);
72  fun1->Draw("glsurf3");
73 
74  c2->cd(2);
75  TF2 *fun2 = new TF2("fun2","cos(y)*sin(x)+cos(x)*sin(y)",
76  -6., 6., -6., 6.);
77  fun2->Draw("glsurf1cyl");
78 
79  c2->cd(3);
80  TF2 *fun3 = new TF2("fun3","sin(x) / x * cos(y) * y", -6., 6., -6., 6.);
81  fun3->Draw("glsurfpol");
82 
83  c2->cd(4);
84  TF3 *fun4 = new TF3("fun4","sin(x * x + y * y + z * z - 4)",
85  -2.5, 2.5, -2.5, 2.5, -2.5, 2.5);
86  Int_t colInd = TColor::GetColor(1.f, 0.5f, 0.f);
87  fun4->SetFillColor(colInd);
88  fun4->Draw("gl");//tf3 option
89 }
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title Offset is a correction factor with respect to the "s...
Definition: TAttAxis.cxx:245
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition: TF2.cxx:216
virtual void SetNpx(Int_t npx=100)
Set the number of points used to draw the function.
Definition: TF1.cxx:3116
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition: TF3.cxx:174
Double_t fun2(Double_t *x, Double_t *par)
Definition: fit2.C:22
TCanvas * c1
Definition: legend1.C:2
R__EXTERN TStyle * gStyle
Definition: TStyle.h:423
tuple f2
Definition: surfaces.py:24
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:659
TPad * pad1
Definition: hcons.C:13
virtual void Update()
Update pad.
Definition: TPad.cxx:2721
int Int_t
Definition: RtypesCore.h:41
Definition: Rtypes.h:61
TFile * f
virtual TH1 * GetHistogram() const
Return a pointer to the histogram used to vusualize the function.
Definition: TF1.cxx:1274
TVirtualPad * cd(Int_t subpadnumber=0)
Set Current pad.
Definition: TPad.cxx:514
void SetFrameFillColor(Color_t color=1)
Definition: TStyle.h:367
Double_t fun3(Double_t *x, Double_t *par)
Definition: Functions.C:21
virtual void Draw(Option_t *option="")
Draw Pad in Current pad (re-parent pad if necessary).
Definition: TPad.cxx:1192
void SetCanvasPreferGL(Bool_t prefer=kTRUE)
Definition: TStyle.h:337
TPaveLabel title(3, 27.1, 15, 28.7,"ROOT Environment and Tools")
virtual void SetFillColor(Color_t fcolor)
Definition: TAttFill.h:50
Double_t fun4(Double_t x)
Definition: Functions.C:26
A 3-Dim function with parameters.
Definition: TF3.h:30
The most important graphics class in the ROOT system.
Definition: TPad.h:46
virtual void SetNpy(Int_t npy=100)
Set the number of points used to draw the function.
Definition: TF2.cxx:907
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb"...
Definition: TColor.cxx:1023
TAxis * GetYaxis()
Definition: TH1.h:320
A 2-Dim function with parameters.
Definition: TF2.h:33
void glsurfaces()
Definition: glsurfaces.C:9
The Canvas class.
Definition: TCanvas.h:48
return c2
Definition: legend2.C:14
A Pave (see TPave) with text, lines or/and boxes inside.
Definition: TPaveText.h:35
virtual void Draw(Option_t *option="")
Draw this pavelabel with its current attributes.
Definition: TPaveLabel.cxx:77
TPad * pad2
Definition: hcons.C:13
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Definition: TPad.cxx:1073
tuple fun1
Definition: formula1.py:18
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual void SetLogz(Int_t value=1)
Set Lin/Log scale for Z.
Definition: TPad.cxx:5324
virtual void SetTitle(const char *title="")
Change (i.e. set) the title of the TNamed.
Definition: TNamed.cxx:152
void SetPalette(Int_t ncolors=kBird, Int_t *colors=0, Float_t alpha=1.)
See TColor::SetPalette.
Definition: TStyle.cxx:1445
void Modified(Bool_t flag=1)
Definition: TPad.h:407
TAxis * GetXaxis()
Definition: TH1.h:319