RE: Changing canvas size

From: Fine, Valeri <fine_at_bnl.gov>
Date: Thu, 2 Apr 2009 11:21:06 -0400


Hello Olivier,

I think the nested event loop invocation is a good temporary solution. However, such nested "event loop" makes the application a pseudo-multi-threaded with the danger of the various "side effect".

I think what one really needs is the TCanvas-less TPad object to allow user

{

    Double_t w = 600;
    Double_t h = 600;
    TPad* pad = new TPad("pad", "pad", w, h);     pad->SaveAs("pad.png");

// with the option:
//    pad->SaveAs("pad.png",UInt h=0,Uint w=0);
//  where the default h=0; w=0 means to preserve 
//  the original object size

}

 Such solution has several advantages:

  1. It does not require "event loop".
  2. It creates the internal pixmap object off-screen. As such, it has no extra window decoration elements. The picture size will always match the object attributes for sure with no delay.
  3. It is orders of the magnitude faster then the regular ROOT batch TPad image processing via libAfterimage, because it does use the graphic hardware accelerator to render the hidden image.
  4. It is much faster then the regular ROOT interactive TCanvas rendering as well, because it does not require the redundant screen update via the complex event communication loop and double buffering mechanism.
  5. One still can invoke pad->Draw() to add the TPad to the current TCanvas and this way make it interactive.
  6. One can add an extra method for TCanvas

       TPad *TCanvas::TakePad(TPad *pad);

      // TakePad removes the "pad" from the TCanvas list of the primitives making "pad" TCanvas-less.

Such TCanvas-less TPad class is a part of QtRoot framework. http://root.bnl.gov/QtRoot/htmldoc/TEmbeddedPad.html However, it has no Qt -dependency. It is "pure" TPad subclass and can be moved from QtRoot to root/gpad.
On the other hand, I do not think there is any strong reason to add this class to ROOT mainstream "as is".
It would be sufficient to add and extra option to the existing TPad ctor instead.

Just my 2 cents.

Best Regards

                         Valeri Fine


Brookhaven National Laboratory
Upton, NY 11973, USA
Phone: +1 631 344 7806
Fax: +1 631 344 4206
E-mail: fine_at_bnl.gov

> -----Original Message-----

> From: Olivier Couet [mailto:Olivier.Couet_at_cern.ch]
> Sent: Thursday, April 02, 2009 4:49 AM
> To: OKUMURA, Akira
> Cc: Rene Brun; Fine, Valeri
> Subject: RE: [ROOT] Changing canvas size
> 
> Yes, the code in TASImage (which worked for you) is in fact:
> 
>    gSystem->ProcessEvents();
>    gSystem->Sleep(10);
>    gSystem->ProcessEvents();
> 
> I am planning to use the same.
> 

> -----Original Message-----
> From: OKUMURA, Akira [mailto:oxon_at_ceres.phys.s.u-tokyo.ac.jp]
> Sent: Thursday, April 02, 2009 10:45 AM
> To: Olivier Couet
> Cc: Rene Brun; Valeri Fayn
> Subject: Re: [ROOT] Changing canvas size
> 
> Hello Olivier,
> 
> > As I said in my previous email I will not modify the TCanvas. I'll
> > rather fix SetWindowSize.
> 
> Sorry, I didn't read it carefully.
> 
> FYI. I had to add three lines in my environment;
>    c->Modified();
>    c->Update();
>    gSystem->Sleep(50);
> in addition to
>    gSystem->ProcessEvents();
> 
> Final macro (at least for my Mac) is as below.
> 
> {
>    Double_t w = 600;
>    Double_t h = 600;
>    TCanvas* c = new TCanvas("c", "c", w, h);
>    c->Modified();
>    c->Update();
>    c->SetWindowSize(w + (w - c->GetWw()), h + (h - c->GetWh()));
>    gSystem->Sleep(50);
>    gSystem->ProcessEvents();
> 
>    c->SaveAs("c1.png");
>    c->SaveAs("c2.png");
>    gSystem->Exec("file c1.png c2.png");
> }
> 
> 
> Regards,
> 
> OKUMURA, Akira oxon_at_ceres.phys.s.u-tokyo.ac.jp
> Department of Physics, The University of Tokyo
> 7-3-1 Hongo, Bunkyo-ku, Tokyo 113-0033
> TEL/FAX +81 3-5841-4173/4059
> Skype : okumura.akira
> 
> On 2009/04/02, at 17:17, Olivier Couet wrote:
> 
> > Hi Akira,
> >
> > As I said in my previous email I will not modify the TCanvas. I'll
> > rather fix SetWindowSize.
> >
> > Regards.
> >
> > -----Original Message-----
> > From: OKUMURA, Akira [mailto:oxon_at_ceres.phys.s.u-tokyo.ac.jp]
> > Sent: Thursday, April 02, 2009 10:16 AM
> > To: Olivier Couet
> > Cc: Rene Brun; Valeri Fayn
> > Subject: Re: [ROOT] Changing canvas size
> >
> > Hello all,
> >
> > Thank you so much. It's working now!
> >
> > It is good idea to add the line
> >   gSystem->ProcessEvents();
> > in the HTML document.
> > http://root.cern.ch/root/html/TCanvas.html
> >
> > Regards,
> >
> > OKUMURA, Akira oxon_at_ceres.phys.s.u-tokyo.ac.jp
> > Department of Physics, The University of Tokyo
> > 7-3-1 Hongo, Bunkyo-ku, Tokyo 113-0033
> > TEL/FAX +81 3-5841-4173/4059
> > Skype : okumura.akira
> >
> > On 2009/04/02, at 17:03, Olivier Couet wrote:
> >
> >> Hi Akira,
> >>
> >> SetWindowSize changes the window size but the action is kept in a
> >> queue
> >> and not performed immediately. To flush the queue it is enough to
do
> >> gSystem->ProcessEvents(); . That's what SaveAs is doing and that's
> >> why
> >> your 2nd png file has the correct size. So to make your macro
> >> working it
> >> is enough to modify it as shown in the following example. On my
> >> side I
> >> will add a gSystem->ProcessEvents(); in SetWindowSize (like in
> >> SaveAs),
> >> so it will not be necessary to add it in users' macros, and the
> >> example
> >> given in the help of TPad will be correct.
> >>
> >> {
> >>  Double_t w = 600;
> >>  Double_t h = 600;
> >>  TCanvas * c1 = new TCanvas("c", "c", w, h);
> >>  c->SetWindowSize(w + (w - c->GetWw()), h + (h - c->GetWh()));
> >>  gSystem->ProcessEvents();
> >>  c->SaveAs("c1.png");
> >>  c->SaveAs("c2.png");
> >> }
> >>
> >> Cheers,        Olivier
> >>
> >> --
> >> Org:    CERN - European Laboratory for Particle Physics.
> >> Mail:   1211 Geneve 23 - Switzerland                     Mailbox:
> >> J25910
> >>
> >> E-Mail: Olivier.Couet_at_cern.ch                            Phone:
> >> +41 22
> >> 7676522
> >> WWW:    http://cern.ch/Olivier.Couet/                    Fax:
> >> +41 22
> >> 7670300
> >
Received on Thu Apr 02 2009 - 17:21:27 CEST

This archive was generated by hypermail 2.2.0 : Fri Apr 03 2009 - 17:50:02 CEST