Re: [ROOT] Displaying contours on a surface plot

From: Olivier Couet (Olivier.Couet@cern.ch)
Date: Thu Mar 18 2004 - 17:27:45 MET


Yes it is a bit challenging ...

 One simple thing would be to do:

    h2->Draw("SURF4");
    h2->Draw("SURF SAME");

 the 2nd Draw uses an hidden line removal algorithm and you can see the 
levels as dotted lines on the surface... BUT you have also many other 
lines which very likely you do not want ! 

 May be one way to implement it would be something like:

    h2->Draw("SURF4");
    h2->Draw("CONT1 SAME");

 for the time being these 2 commands produce a weird useless plot. We can 
imagine that if the option "CONT1 SAME" is used on a plot containing a 
3D view (surface, lego) the contours are plotted in 3D using an hidden 
line removal algorithm. Would that be fine ?

 Cheers,             Olivier 

On Thu, 18 Mar 2004, Andreas Zoglauer wrote:

> 
> Hello Rooters!
> 
> I have the following probably challenging problem:
> 
> I want to draw a 2D surface plot (SURF2 or SURF4) and add (black) 
> contour lines on the surface NOT above like in SURF3.
> 
> Here is an example with shows what I want to do:
> 
> Contour()
> {
>    gROOT->Reset();
> 
>    int NBins = 50;
>    double d = 2;
> 
>    TH2F* h2 = new TH2F("h2", "h2", NBins, -d, d, NBins, -d, d);
>    for (int bx = 1;  bx <= NBins; ++bx) {
>      for (int by = 1;  by <= NBins; ++by) {
>        double x = h2->GetXaxis()->GetBinCenter(bx);
>        double y = h2->GetYaxis()->GetBinCenter(by);
>        h2->SetBinContent(bx, by, exp(-x*x)*exp(-y*y));
>      }
>    }
> 
>    TCanvas *c1=new TCanvas("c1","c1",600,600);
>    h2->Draw("SURF4");
> 
>    int LineBins = 100;
>    TPolyLine3D *l = 0;
>    for (double h = 0; h < 0.9*d; h+= d/20.0) {
>      l = new TPolyLine3D(LineBins);
>      for (int e = 0; e < LineBins; ++e) {
>        Double_t Angle = e*2*TMath::Pi()/LineBins;
>        l->SetPoint(e, h*cos(Angle), h*sin(Angle), exp(-h*h));
>      }
>      l->Draw("SAME");
>    }
> 
>    c1->Update();
> }
> 
> So my questions are:
> 1. Is there an easy way to do this in ROOT avoiding the calculation of 
> the PolyLines?
> 2. If not, how can I hide/not draw the unvisible/hidden part of the 
> polyline??
> 
> 
> Thanks,
> Andreas
> 
> 

-- 
Org:    CERN - European Laboratory for Particle Physics.
Mail:   1211 Geneve 23 - Switzerland                     Mailbox: J25910      
E-Mail: Olivier.Couet@cern.ch                            Phone:   +41 22 7676522
WWW:    http://cern.ch/Olivier.Couet/                    Fax:     +41 22 7677155



This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:06 MET