Re: Viewpoint in 3D

From: Rene Brun <Rene.Brun_at_cern.ch>
Date: Tue, 19 May 2009 11:16:47 +0200


see your script modified in attachment. Look for lines with //<=====

Rene Brun

Roger Mason wrote:
> Hi Rene,
>
> Rene Brun <Rene.Brun_at_cern.ch> writes:
>
>
>> I thought that I had already sent you the script writing the
>> labels. Here it is again.
>>
>
> You had, and it works. The problem is that _my_ code (below) does not
> work. The error message is:
>
> root [0] .x PlotHeights_6.C
> File contains 7 control points
> Error: illegal pointer to class object view 0x0 393 PlotHeights_6.C:44:
> *** Interpreter error recovered ***
>
> Many thanks,
> Roger
>
>
>>> // ================== PlotHeights_x.C
>>> #include <iostream>
>>>
>>> void PlotHeights_6 ()
>>> {
>>> // gROOT->Reset();
>>>
>>> // TString datdir = "../data/";
>>> // TString fname = TString(filename);
>>> // TString file = datdir+fname;
>>>
>>> TCanvas *c = new TCanvas("c","test",0,0,1024,768);
>>> c->Divide(2,1);
>>>
>>> TGraph2D *dt = new TGraph2D("graph.dat"); Int_t n = dt->GetN();
>>> cout << "File contains " << n << " control points" << endl;
>>>
>>> Double_t* x = dt->GetX();
>>> Double_t* y = dt->GetY();
>>> Double_t* z = dt->GetZ();
>>> Double_t xmax = dt->GetXmax();
>>> Double_t xmin = dt->GetXmin();
>>> Double_t ymax = dt->GetYmax();
>>> Double_t ymin = dt->GetYmin();
>>>
>>> // What the students get
>>> c->cd(1);
>>> gPad->SetPhi(-90); // Viewpoint
>>> gPad->SetTheta(-89.99);
>>> dt->SetMarkerStyle(8); // Marker for the control points
>>> dt->SetTitle("");
>>> dt->Draw("AP");
>>>
>>> Double_t xyz[3], uv[2];
>>> TView *view = gPad->GetView();
>>>
>>> TText t;
>>> t.SetTextSize(0.035);
>>> for (Int_t i=0;i<n;i++) {
>>> xyz[0] = dt->GetX()[i];
>>> xyz[1] = dt->GetY()[i];
>>> xyz[2] = dt->GetZ()[i];
>>> view->WCtoNDC(xyz,uv); // Line 44 <============================ error
>>> t->DrawText(uv[0]+0.01,uv[1],Form("%d",z[i]));
>>> }
>>>
>>> // TString imagefile = "../images/"+fname+".eps";
>>> // gPad->Print(imagefile); // Print the current pad (only)
>>>
>>> // The solution, in 3D viewed from above
>>> gStyle->SetPalette(1);
>>>
>>>
>>> Double_t contours[] = {20,40,60,80,100,120,140,160,180,200};
>>>
>>> c->cd(2);
>>> gPad->SetPhi(0); // Viewpoint
>>> gPad->SetTheta(90);
>>>
>>> TH2D* h = new TH2D();
>>> h = dt->GetHistogram(); // Get histo interpolated between
>>> // control points in dt.
>>> h->SetContour(10,contours); // Set 10 contour levels (default is 20)
>>> h->Draw("surf2"); // Draw interpolated points as surface
>>> h->Draw("cont1 same"); // Contour the surface
>>> dt->SetTitle("");
>>> dt->SetMarkerStyle(8); // Marker for the control points
>>> dt->Draw("p same"); // Superimpose the control points
>>>
>>>
>>> // TString imagefile = "../images/"+fname+"_solution.eps";
>>> // gPad->Print(imagefile); // Print the current pad (only)
>>>
>>> return c;
>>> }
>>>
>
>

Received on Tue May 19 2009 - 11:17:26 CEST

This archive was generated by hypermail 2.2.0 : Tue May 19 2009 - 23:50:01 CEST