Logo ROOT  
Reference Guide
glsurfaces.C File Reference

Detailed Description

Various surfaces rendered with GL. This example draws 6 surfaces using OpenGL in pad (one is remake of a classic surfaces.C, another contains 4 surfaces).

The commands used are exactly the same as with a normal pad. The only command to add is: gStyle->SetCanvasPreferGL(true);

void glsurfaces()
{
// after this command all legos surfaces (surf/surf1/surf2/surf4/tf3
// options) are automatically rendered with OpenGL.
TCanvas *c1 = new TCanvas("glc1","Surfaces Drawing Options",200,10,700,900);
c1->SetFillColor(42);
auto title = new TPaveText(0.2, 0.96, 0.8, 0.995);
title->SetFillColor(33);
title->AddText("Examples of Surface options");
title->Draw();
TPad *pad1 = new TPad("pad1","Gouraud shading", 0.03, 0.50, 0.98, 0.95, 21);
TPad *pad2 = new TPad("pad2","Color mesh", 0.03, 0.02, 0.98, 0.48, 21);
pad1->Draw();
pad2->Draw();
// We generate a 2-D function
TF2 *f2 = new TF2("f2","x**2 + y**2 - x**3 -8*x*y**4", -1., 1.2, -1.5, 1.5);
// Draw this function in pad1 with Gouraud shading option
pad1->cd();
pad1->SetLogz();
f2->SetFillColor(45);
f2->Draw("glsurf4");
TF2 *f2clone = new TF2("f2clone","x**2 + y**2 - x**3 -8*x*y**4",
-1., 1.2, -1.5, 1.5);
// Draw this function in pad2 with color mesh option
pad2->cd();
pad2->SetLogz();
f2clone->Draw("glsurf1");
//add axis titles. The titles are set on the intermediate
//histogram used for visualisation. We must force this histogram
//to be created, then force the redrawing of the two pads
pad2->Update();
f2->GetHistogram()->GetXaxis()->SetTitle("x title");
f2->GetHistogram()->GetYaxis()->SetTitle("y title");
f2clone->GetHistogram()->GetXaxis()->SetTitle("x title");
f2clone->GetHistogram()->GetYaxis()->SetTitle("y title");
f2clone->GetHistogram()->GetXaxis()->SetTitleOffset(1.4);
f2clone->GetHistogram()->GetYaxis()->SetTitleOffset(1.4);
pad1->Modified();
pad2->Modified();
TCanvas *c2 = new TCanvas("glc2","Surfaces Drawing Options with gl",
700,10,700,700);
c2->SetFillColor(42);
c2->Divide(2, 2);
c2->cd(1);
TF2 *fun1 = new TF2("fun1","1000*((sin(x)/x)*(sin(y)/y))+200",
-6., 6., -6., 6.);
fun1->SetNpx(30);
fun1->SetNpy(30);
fun1->SetFillColor(kGreen);
fun1->Draw("glsurf3");
c2->cd(2);
TF2 *fun2 = new TF2("fun2","cos(y)*sin(x)+cos(x)*sin(y)",
-6., 6., -6., 6.);
fun2->Draw("glsurf1cyl");
c2->cd(3);
TF2 *fun3 = new TF2("fun3","sin(x) / x * cos(y) * y", -6., 6., -6., 6.);
fun3->Draw("glsurfpol");
c2->cd(4);
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);
Int_t colInd = TColor::GetColor(1.f, 0.5f, 0.f);
fun4->SetFillColor(colInd);
fun4->Draw("gl");//tf3 option
}
Authors
Rene Brun, Timur Pocheptsov

Definition in file glsurfaces.C.

TStyle::SetCanvasPreferGL
void SetCanvasPreferGL(Bool_t prefer=kTRUE)
Definition: TStyle.h:325
TF1::GetHistogram
virtual TH1 * GetHistogram() const
Return a pointer to the histogram used to visualise the function.
Definition: TF1.cxx:1585
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
f
#define f(i)
Definition: RSha256.hxx:122
TPad
Definition: TPad.h:26
TF1::SetNpx
virtual void SetNpx(Int_t npx=100)
Set the number of points used to draw the function.
Definition: TF1.cxx:3453
kGreen
@ kGreen
Definition: Rtypes.h:66
TF2::SetNpy
virtual void SetNpy(Int_t npy=100)
Set the number of points used to draw the function.
Definition: TF2.cxx:932
Int_t
int Int_t
Definition: RtypesCore.h:45
TPaveLabel::Draw
virtual void Draw(Option_t *option="")
Draw this pavelabel with its current attributes.
Definition: TPaveLabel.cxx:77
TPad::SetLogz
virtual void SetLogz(Int_t value=1)
Set Lin/Log scale for Z.
Definition: TPad.cxx:5916
TPad::Modified
void Modified(Bool_t flag=1)
Definition: TPad.h:414
gStyle
R__EXTERN TStyle * gStyle
Definition: TStyle.h:412
TH1::GetYaxis
TAxis * GetYaxis()
Definition: TH1.h:318
TF3
Definition: TF3.h:28
TF2::Draw
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition: TF2.cxx:241
TColor::GetColor
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:1766
TNamed::SetTitle
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
fun3
Double_t fun3(Double_t *x, Double_t *par)
Definition: Functions.C:21
TPad::Update
virtual void Update()
Update pad.
Definition: TPad.cxx:2839
TF2
Definition: TF2.h:29
TStyle::SetPalette
void SetPalette(Int_t ncolors=kBird, Int_t *colors=0, Float_t alpha=1.)
See TColor::SetPalette.
Definition: TStyle.cxx:1785
TCanvas
Definition: TCanvas.h:23
TPad::cd
TVirtualPad * cd(Int_t subpadnumber=0)
Set Current pad.
Definition: TPad.cxx:594
c2
return c2
Definition: legend2.C:14
fun4
Double_t fun4(Double_t x)
Definition: Functions.C:26
TPaveText
Definition: TPaveText.h:21
TStyle::SetFrameFillColor
void SetFrameFillColor(Color_t color=1)
Definition: TStyle.h:355
TAttAxis::SetTitleOffset
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition: TAttAxis.cxx:293
TH1::GetXaxis
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:317
c1
return c1
Definition: legend1.C:41
TPad::Draw
virtual void Draw(Option_t *option="")
Draw Pad in Current pad (re-parent pad if necessary).
Definition: TPad.cxx:1285