Re: Draw histograms in Canvas

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri Mar 26 1999 - 23:42:21 MET


Hi Anton,
You should call hist->Draw() only once. Draw simply appends the histogram
into the list of primitives in the pad. The real drawing is performed
only when the pad needs to be updated. When this happens, hist->Paint is
called.
In your case, you should only call 
  gPad->Modified();
  gPad->Update();
every time you want to force a redraw of the canvas.
If you call
  hist->Draw()
in a loop, this will add a new reference to the same histogram to the pad
list. This means that every time you will update the canvas, you will
Paint more and more histograms and the process will  become slower and
slower.

Rene Brun

On Fri, 26 Mar 1999, Anton Fokin wrote:

> Hi Rene and rooters,
> 
> Although I sent my question directly to Valery Fine, I think that your
> comment may be interesting for rooters in general because I know people who
> already asked me near the same question. I.e. what is the best way to
> update your histograms on screen in on-line applications.
> 
> ---------
> 
> Hi Valery,
> 
> thanks for the answer. It makes things clear, but still I have some more
> specific question. Let's imagine I have an on-line application where an
> user can define a set of canvas with histograms. There is also an
> asin.timer set to update all the histograms once a second or so. Then I
> have a loop inside UpdateTimer.Notify() which basically goes through all
> the canvas and calls Hist[i]->Draw(); for each histogram. First at all it
> may be a very time consuming, especially if I draw histograms with "fancy"
> options like "cont" for 2D, etc. On the other hand a user can only view a
> certain number of canvas/histograms at once. Moreover canvas can be
> overlapped so that only a few histograms in canvas need to be actually
> redrawn. What can you suggest in this case? Having in mind my experience
> working with other winlibs starting from Borland TurboVision I know that
> Object->Draw() checks if the Object is not hidden by other objects on the
> screen. Then it goes through the actual drawing. Moreover it checks if its
> children is not hidden before calling Children->Draw() for its Z buffer. In
> root it seems that Hist->Draw() does much more than just drawing, while
> Hist->Show() does similar things. The problem is that I have to use Draw()
> to update histogram because its content is changing dynamically.
> 
> 
> Dr. Anton Fokin
> 
> Division of Cosmic and Subatomic Physics
> Lund University
> Sweden
> 
> ----------
> > From: Rene Brun <brun@pcbrun.cern.ch>
> > To: Anton Fokin <kosu_fokin@garbo.lucas.lu.se>
> > Cc: roottalk@hpsalo.cern.ch
> > Subject: Re: Draw histograms in Canvas
> > Date:  den 26 March 1999 15:27
> > 
> > Hi Anton,
> > Iconizing a canvas and back will not force  a call to the TH1 drawing
> > functions.
> > The TCanvas::Update function is only called when the canvas content has
> > been modified, or the scale of the canvas modified by growing/shrinking
> > its dimensions with the mouse.
> > 
> > Rene Brun
> > 
> > On Fri, 26 Mar 1999, Anton Fokin wrote:
> > 
> > > Hi rooters,
> > > 
> > > I wonder if a histogram will be actually drawn (i.e. histogram->Draw()
> will
> > > consume the same amount of processor time and go through the the same
> code)
> > > if a Canvas is iconized/hidden/etc. Or it's my duty to check if a
> histogram
> > > is hidden and doesn't need to be redrawn. Also, if I go from an
> iconized to
> > > normal Canvas, will it force automatic redraw update for all histograms
> > > belonging to the Canvas?
> > > 
> > > Best regards,
> > > 
> > > Dr. Anton Fokin
> > > 
> > > Division of Cosmic and Subatomic Physics
> > > Lund University
> > > Sweden
> > > 
> > > 
> 



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:30 MET