Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
15void glsurfaces()
16{
18
19 // after this command all legos surfaces (surf/surf1/surf2/surf4/tf3
20 // options) are automatically rendered with OpenGL.
22
23 TCanvas *c1 = new TCanvas("glc1", "Surfaces Drawing Options", 200, 10, 700, 900);
24 c1->SetFillColor(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", -1., 1.2, -1.5, 1.5);
44 // Draw this function in pad2 with color mesh option
45 pad2->cd();
46 pad2->SetLogz();
47 f2clone->Draw("glsurf1");
48
49 // add axis titles. The titles are set on the intermediate
50 // histogram used for visualisation. We must force this histogram
51 // to be created, then force the redrawing of the two pads
52 pad2->Update();
53 f2->GetHistogram()->GetXaxis()->SetTitle("x title");
54 f2->GetHistogram()->GetYaxis()->SetTitle("y title");
57 f2clone->GetHistogram()->GetXaxis()->SetTitle("x title");
58 f2clone->GetHistogram()->GetYaxis()->SetTitle("y title");
59 f2clone->GetHistogram()->GetXaxis()->SetTitleOffset(1.4);
60 f2clone->GetHistogram()->GetYaxis()->SetTitleOffset(1.4);
61 pad1->Modified();
62 pad2->Modified();
63
64 TCanvas *c2 = new TCanvas("glc2", "Surfaces Drawing Options with gl", 700, 10, 700, 700);
65 c2->SetFillColor(42);
67
68 c2->Divide(2, 2);
69
70 c2->cd(1);
71 TF2 *fun1 = new TF2("fun1", "1000*((sin(x)/x)*(sin(y)/y))+200", -6., 6., -6., 6.);
72 fun1->SetNpx(30);
73 fun1->SetNpy(30);
74 fun1->SetFillColor(kGreen);
75 fun1->Draw("glsurf3");
76
77 c2->cd(2);
78 TF2 *fun2 = new TF2("fun2", "cos(y)*sin(x)+cos(x)*sin(y)", -6., 6., -6., 6.);
79 fun2->Draw("glsurf1cyl");
80
81 c2->cd(3);
82 TF2 *fun3 = new TF2("fun3", "sin(x) / x * cos(y) * y", -6., 6., -6., 6.);
83 fun3->Draw("glsurfpol");
84
85 c2->cd(4);
86 TF3 *fun4 = new TF3("fun4", "sin(x * x + y * y + z * z - 4)", -2.5, 2.5, -2.5, 2.5, -2.5, 2.5);
87 Int_t colInd = TColor::GetColor(1.f, 0.5f, 0.f);
88 fun4->SetFillColor(colInd);
89 fun4->Draw("gl"); // tf3 option
90}
Double_t fun3(Double_t *x, Double_t *par)
Definition Functions.C:21
Double_t fun4(Double_t x)
Definition Functions.C:26
int Int_t
Definition RtypesCore.h:45
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
@ kGreen
Definition Rtypes.h:66
R__EXTERN TStyle * gStyle
Definition TStyle.h:436
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition TAttAxis.cxx:298
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:37
The Canvas class.
Definition TCanvas.h:23
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:1921
virtual TH1 * GetHistogram() const
Return a pointer to the histogram used to visualise the function Note that this histogram is managed ...
Definition TF1.cxx:1584
virtual void SetNpx(Int_t npx=100)
Set the number of points used to draw the function.
Definition TF1.cxx:3433
A 2-Dim function with parameters.
Definition TF2.h:29
virtual void SetNpy(Int_t npy=100)
Set the number of points used to draw the function.
Definition TF2.cxx:927
void Draw(Option_t *option="") override
Draw this function with its current attributes.
Definition TF2.cxx:259
A 3-Dim function with parameters.
Definition TF3.h:28
TAxis * GetXaxis()
Definition TH1.h:325
TAxis * GetYaxis()
Definition TH1.h:326
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:164
The most important graphics class in the ROOT system.
Definition TPad.h:28
void SetLogz(Int_t value=1) override
Set Lin/Log scale for Z.
Definition TPad.cxx:6111
void Update() override
Update pad.
Definition TPad.cxx:2935
void Modified(Bool_t flag=true) override
Mark pad modified Will be repainted when TCanvas::Update() will be called next time.
Definition TPad.cxx:7388
TVirtualPad * cd(Int_t subpadnumber=0) override
Set Current pad.
Definition TPad.cxx:693
void Draw(Option_t *option="") override
Draw Pad in Current pad (re-parent pad if necessary).
Definition TPad.cxx:1364
A Pave (see TPave) with text, lines or/and boxes inside.
Definition TPaveText.h:21
void SetFrameFillColor(Color_t color=1)
Definition TStyle.h:372
void SetPalette(Int_t ncolors=kBird, Int_t *colors=nullptr, Float_t alpha=1.)
See TColor::SetPalette.
Definition TStyle.cxx:1888
void SetCanvasPreferGL(Bool_t prefer=kTRUE)
Definition TStyle.h:341
return c1
Definition legend1.C:41
return c2
Definition legend2.C:14