glsurfaces.C

Go to the documentation of this file.
00001 // Various surfaces rendered with GL.
00002 // This example draws 6 surfaces using OpenGL in pad (one is remake
00003 // of a classic surfaces.C, another contains 4 surfaces).
00004 //
00005 // The commands used are exactly the same as with a normal pad. 
00006 // The only command to add is: gStyle->SetCanvasPreferGL(true);
00007 // Authors: Rene Brun, Timur Pocheptsov
00008 
00009 void glsurfaces()
00010 {
00011    gStyle->SetPalette(0);
00012    
00013    // after this command all legos surfaces (surf/srf1/surf2/surf4/tf3
00014    // options) are automatically rendered with OpenGL.
00015    gStyle->SetCanvasPreferGL(kTRUE);
00016 
00017    TCanvas *c1 = new TCanvas("glc1","Surfaces Drawing Options",200,10,700,900);
00018    c1->SetFillColor(42);
00019    gStyle->SetFrameFillColor(42);
00020    title = new TPaveText(0.2, 0.96, 0.8, 0.995);
00021    title->SetFillColor(33);
00022    title->AddText("Examples of Surface options");
00023    title->Draw();
00024 
00025    TPad *pad1 = new TPad("pad1","Gouraud shading", 0.03, 0.50, 0.98, 0.95, 21);
00026    TPad *pad2 = new TPad("pad2","Color mesh", 0.03, 0.02, 0.98, 0.48, 21);
00027    pad1->Draw();
00028    pad2->Draw();
00029    // We generate a 2-D function
00030    TF2 *f2 = new TF2("f2","x**2 + y**2 - x**3 -8*x*y**4", -1., 1.2, -1.5, 1.5);
00031    // Draw this function in pad1 with Gouraud shading option
00032    pad1->cd();
00033    pad1->SetLogz();
00034    f2->SetFillColor(45);
00035    f2->Draw("glsurf4");
00036 
00037    TF2 *f2clone = new TF2("f2clone","x**2 + y**2 - x**3 -8*x*y**4",
00038                           -1., 1.2, -1.5, 1.5);
00039    // Draw this function in pad2 with color mesh option
00040    pad2->cd();
00041    pad2->SetLogz();
00042    f2clone->Draw("glsurf1");
00043    
00044    //add axis titles. The titles are set on the intermediate
00045    //histogram used for visualisation. We must force this histogram
00046    //to be created, then force the redrawing of the two pads
00047    pad2->Update();
00048    f2->GetHistogram()->GetXaxis()->SetTitle("x title");
00049    f2->GetHistogram()->GetYaxis()->SetTitle("y title");
00050    f2->GetHistogram()->GetXaxis()->SetTitleOffset(1.4);
00051    f2->GetHistogram()->GetYaxis()->SetTitleOffset(1.4);
00052    f2clone->GetHistogram()->GetXaxis()->SetTitle("x title");
00053    f2clone->GetHistogram()->GetYaxis()->SetTitle("y title");
00054    f2clone->GetHistogram()->GetXaxis()->SetTitleOffset(1.4);
00055    f2clone->GetHistogram()->GetYaxis()->SetTitleOffset(1.4);
00056    pad1->Modified();
00057    pad2->Modified();
00058 
00059    TCanvas *c2 = new TCanvas("glc2","Surfaces Drawing Options with gl",
00060                              700,10,700,700);
00061    c2->SetFillColor(42);
00062    gStyle->SetFrameFillColor(42);
00063 
00064    c2->Divide(2, 2);
00065 
00066    c2->cd(1);
00067    TF2 *fun1 = new TF2("fun1","1000*((sin(x)/x)*(sin(y)/y))+200",
00068                        -6., 6., -6., 6.);
00069    fun1->SetNpx(30);
00070    fun1->SetNpy(30);
00071    fun1->SetFillColor(kGreen);
00072    fun1->Draw("glsurf3");
00073 
00074    c2->cd(2);
00075    TF2 *fun2 = new TF2("fun2","cos(y)*sin(x)+cos(x)*sin(y)",
00076                        -6., 6., -6., 6.);
00077    fun2->Draw("glsurf1cyl");
00078 
00079    c2->cd(3);
00080    TF2 *fun3 = new TF2("fun3","sin(x) / x * cos(y) * y", -6., 6., -6., 6.);
00081    fun3->Draw("glsurfpol");
00082 
00083    c2->cd(4);
00084    TF3 *fun4 = new TF3("fun4","sin(x * x + y * y + z * z - 4)",
00085                        -2.5, 2.5, -2.5, 2.5, -2.5, 2.5);
00086    Int_t colInd = TColor::GetColor(1.f, 0.5f, 0.f);
00087    fun4->SetFillColor(colInd);
00088    fun4->Draw("gl");//tf3 option
00089 }

Generated on Tue Jul 5 15:44:17 2011 for ROOT_528-00b_version by  doxygen 1.5.1