[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: POLYFILL erases my tick values - solution?



Craig Markwardt wrote:

> You could re-render the entire thing in an off-screen pixmap, and then
> dump the pixmap to the screen (or at least the relevant portion).  I
> believe this would be a classic example of so-called double buffering
> in computer graphics.

Double Buffering was definitely a good idea, Craig.  It was very simple
to implement and is much faster than I would have expected.  In fact, it
worked well enough that I think David should add it to his book as a
technique to avoid flashing displays in the case that you can't simply
save and device,COPY the relevant part of your graphics output.  It
seems to work especially well in the context of plotting.  If you want
to rapidly redisplay a plot with moving/changing parts and multiple
display commands being invoked, this technique is definitely for you! 
Flicker free performance.

Here's the synopsis:

;; Standard widget_draw/pixwin setup, in an Init function maybe
widget_control,base,/REALIZE
widget_control,self.wDraw,GET_VALUE=win  ; Put *after* realizing
self.win=win
window,/FREE,/PIXMAP,XSIZE=xsize,YSIZE=ysize
self.pixwin=!D.WINDOW

;; When plotting
wset,self.pixwin ; instead of wset,self.win
erase
polyfill,blah,blah
plot,blah,blah,/NOERASE
oplot,blah,blah 
polyfill, blah, blah  ; and etc.
;; Two additional commands complete the double buffer
wset,self.win
device,COPY=[0,0,!D.X_SIZE,!D.Y_SIZE,0,0,self.pixwin]

This is really just the same idea (though easier!) as the normal image
buffering techniques typified by the "rubber band" example we all know
and love, but with the seemingly costly step of re-displaying each and
every time through, rather than saving a fixed image for copying.  It
does make a *big* difference in the smoothness of moving plots, and
really takes only 2 additional lines surrounding your plot code (plus
getting the pixwin in the first place).

Also, don't forget to free those pixwins in your cleanup
routines/methods!

JD

-- 
 J.D. Smith                  |   WORK: (607) 255-6263
 Cornell Dept. of Astronomy  |         (607) 255-5842
 304 Space Sciences Bldg.    |    FAX: (607) 255-5875  
 Ithaca, NY 14853            |