Re: Viewpoint in 3D

From: Roger Mason <rmason_at_esd.mun.ca>
Date: Mon, 18 May 2009 11:46:50 -0230


Hi Rene,

Rene Brun <Rene.Brun_at_cern.ch> writes:

> Try the script in the attachment. Use TPad::SetTheta, Phi to set the
> viewing angle.
> Yes, we have some incoherent behavior between settings via TPad and TView.

When I run the version printed below I>
get the following:

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 ***

Is that what you mean by incoherent?

Is it possible to have the view from gPad->SetPhi(-90), gPad->SetTheta(-89.99) and have the points labelled?

Thanks very much,

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 Mon May 18 2009 - 16:29:03 CEST

This archive was generated by hypermail 2.2.0 : Mon May 18 2009 - 17:50:01 CEST