Re: Viewpoint in 3D

From: Rene Brun <Rene.Brun_at_cern.ch>
Date: Sun, 17 May 2009 18:24:52 +0200


Hi Roger,

Try this

{

   TCanvas *c = new TCanvas("c","Graph2D example",0,0,600,400);

   TGraph2D *dt = new TGraph2D("graph.dat");

   gStyle->SetPalette(1);

   Double_t contours[] = {20,40,60,80,100,120,140,160,180,200};

   // Set the canvas range a bit bigger than the x,y data ranges

   c->Range(0,0,160,160); // does not work
   c->SetTheta(84);
   c->SetPhi(45);
   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->SetMarkerStyle(8);       // Marker for the control points
   dt->Draw("p same");             // Superimpose the control points
   dt->GetZaxis()->SetNdivisions(2);
   //draw text at each point
   Double_t xyz[3], uv[2];
   Int_t np = dt->GetN();
   c->Update();
   TView *view = c->GetView();
   TText t;
   t->SetTextSize(0.035);
   for (Int_t i=0;i<np;i++) {
      xyz[0] = dt->GetX()[i];
      xyz[1] = dt->GetY()[i];
      xyz[2] = dt->GetZ()[i];
      view->WCtoNDC(xyz,uv);
      t->DrawText(uv[0]+0.01,uv[1],Form("point %d",i));
   }
     

   return c;
}

Rene Brun

Roger Mason wrote:
> Hello Rene,
>
> Firstly, thank you for your help.
>
> I now have a macro that does most of what I want:
>
> // PlotHeights.C
> {
> TCanvas *c = new TCanvas("c","Graph2D example",0,0,600,400);
>
> TGraph2D *dt = new TGraph2D("graph.dat");
>
> gStyle->SetPalette(1);
>
> Double_t contours[] = {20,40,60,80,100,120,140,160,180,200};
>
> // Set the canvas range a bit bigger than the x,y data ranges
> c->Range(0,0,160,160); // does not work
>
> 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->SetMarkerStyle(8); // Marker for the control points
> dt->Draw("p same"); // Superimpose the control points
>
> return c;
> }
> // ROOT 5.20/00 (trunk_at_24524, Sep 30 2008, 15:32:00 on linux)
>
> I would like to set the viewpoint in 3D so that I can make a birds eye
> view of the contours (like a topographic map). I could not find mention
> of this in the documentation, but perhaps I'm looking in the wrong
> place. I would also like to be able to label the points plotted from
> dt.
>
> Thanks again,
> Roger
>
>
Received on Sun May 17 2009 - 18:25:12 CEST

This archive was generated by hypermail 2.2.0 : Tue May 19 2009 - 11:50:03 CEST