Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
glsurfaces.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_gl
3 /// Various surfaces rendered with GL.
4 /// This example draws 6 surfaces using OpenGL in pad (one is remake
5 /// of a classic surfaces.C, another contains 4 surfaces).
6 ///
7 /// The commands used are exactly the same as with a normal pad.
8 /// The only command to add is: `gStyle->SetCanvasPreferGL(true);`
9 ///
10 /// \macro_image(nobatch)
11 /// \macro_code
12 ///
13 /// \authors Rene Brun, Timur Pocheptsov
14 
15 void glsurfaces()
16 {
17  gStyle->SetPalette(0);
18 
19  // after this command all legos surfaces (surf/surf1/surf2/surf4/tf3
20  // options) are automatically rendered with OpenGL.
21  gStyle->SetCanvasPreferGL(kTRUE);
22 
23  TCanvas *c1 = new TCanvas("glc1","Surfaces Drawing Options",200,10,700,900);
24  c1->SetFillColor(42);
25  gStyle->SetFrameFillColor(42);
26  auto title = new TPaveText(0.2, 0.96, 0.8, 0.995);
27  title->SetFillColor(33);
28  title->AddText("Examples of Surface options");
29  title->Draw();
30 
31  TPad *pad1 = new TPad("pad1","Gouraud shading", 0.03, 0.50, 0.98, 0.95, 21);
32  TPad *pad2 = new TPad("pad2","Color mesh", 0.03, 0.02, 0.98, 0.48, 21);
33  pad1->Draw();
34  pad2->Draw();
35  // We generate a 2-D function
36  TF2 *f2 = new TF2("f2","x**2 + y**2 - x**3 -8*x*y**4", -1., 1.2, -1.5, 1.5);
37  // Draw this function in pad1 with Gouraud shading option
38  pad1->cd();
39  pad1->SetLogz();
40  f2->SetFillColor(45);
41  f2->Draw("glsurf4");
42 
43  TF2 *f2clone = new TF2("f2clone","x**2 + y**2 - x**3 -8*x*y**4",
44  -1., 1.2, -1.5, 1.5);
45  // Draw this function in pad2 with color mesh option
46  pad2->cd();
47  pad2->SetLogz();
48  f2clone->Draw("glsurf1");
49 
50  //add axis titles. The titles are set on the intermediate
51  //histogram used for visualisation. We must force this histogram
52  //to be created, then force the redrawing of the two pads
53  pad2->Update();
54  f2->GetHistogram()->GetXaxis()->SetTitle("x title");
55  f2->GetHistogram()->GetYaxis()->SetTitle("y title");
56  f2->GetHistogram()->GetXaxis()->SetTitleOffset(1.4);
57  f2->GetHistogram()->GetYaxis()->SetTitleOffset(1.4);
58  f2clone->GetHistogram()->GetXaxis()->SetTitle("x title");
59  f2clone->GetHistogram()->GetYaxis()->SetTitle("y title");
60  f2clone->GetHistogram()->GetXaxis()->SetTitleOffset(1.4);
61  f2clone->GetHistogram()->GetYaxis()->SetTitleOffset(1.4);
62  pad1->Modified();
63  pad2->Modified();
64 
65  TCanvas *c2 = new TCanvas("glc2","Surfaces Drawing Options with gl",
66  700,10,700,700);
67  c2->SetFillColor(42);
68  gStyle->SetFrameFillColor(42);
69 
70  c2->Divide(2, 2);
71 
72  c2->cd(1);
73  TF2 *fun1 = new TF2("fun1","1000*((sin(x)/x)*(sin(y)/y))+200",
74  -6., 6., -6., 6.);
75  fun1->SetNpx(30);
76  fun1->SetNpy(30);
77  fun1->SetFillColor(kGreen);
78  fun1->Draw("glsurf3");
79 
80  c2->cd(2);
81  TF2 *fun2 = new TF2("fun2","cos(y)*sin(x)+cos(x)*sin(y)",
82  -6., 6., -6., 6.);
83  fun2->Draw("glsurf1cyl");
84 
85  c2->cd(3);
86  TF2 *fun3 = new TF2("fun3","sin(x) / x * cos(y) * y", -6., 6., -6., 6.);
87  fun3->Draw("glsurfpol");
88 
89  c2->cd(4);
90  TF3 *fun4 = new TF3("fun4","sin(x * x + y * y + z * z - 4)",
91  -2.5, 2.5, -2.5, 2.5, -2.5, 2.5);
92  Int_t colInd = TColor::GetColor(1.f, 0.5f, 0.f);
93  fun4->SetFillColor(colInd);
94  fun4->Draw("gl");//tf3 option
95 }