Fanning Software Consulting

Speed Up Graphics Rendering

QUESTION: If I have a complicated scene with the new IDL 8 graphics, it takes a long time to render. For example, each time I change a property of an object, the entire scene is immediately rendered to the display. It is not only disconcerting to the user to see different parts of the scene shifting and popping about, but it slows things way down. Here is a simple example of what I mean.

    b = Barplot(/TEST)    FOR j=0, 20 DO BEGIN
      color = [Randomu(seed,1)*255, Randomu(seed,1)*255, Randomu(seed, 1)*255]
      !null = Barplot(/TEST, /OVERPLOT, TRANSPARENCY=50, COLOR=color, FILL_COLOR=color)
   ENDFOR    END 

Note the use of the undocumented keyword TEST. This simply produces some fake data for testing the Barplot command.

Is there any way to speed this up and perhaps get rid of the incessant updating?

ANSWER: Yes, you can do both by turning the bar plot updating off until you are finished creating the plot, then rendering the final result just once. This is done with the Refresh method of the BarPlot object, which enables/disables the drawing (refreshing) of the display when object properties change. The code to do so looks like this for your example.

    b = Barplot(/TEST)
   b.Refresh, /DISABLE   ; Turn barplot updating OFF.    FOR j=0, 20 DO BEGIN
      color = [Randomu(seed,1)*255, Randomu(seed,1)*255, Randomu(seed, 1)*255]
      !null = Barplot(/TEST, /OVERPLOT, TRANSPARENCY=50, COLOR=color, FILL_COLOR=color)
   ENDFOR    b.Refresh             ; Turn barplot updating ON.    END 

In this case, you still see the initial plot in the window. If you wanted to see nothing in the window until the bar plot was completely finished, you would suppress window updating by using code along these lines.

    win = Window()
   win.Refresh, /DISABLE  ; Turn window updating OFF.
   b = Barplot(/TEST, /CURRENT)    FOR j=0, 20 DO BEGIN
      color = [Randomu(seed,1)*255, Randomu(seed,1)*255, Randomu(seed, 1)*255]
      !null = Barplot(/TEST, /OVERPLOT, TRANSPARENCY=50, COLOR=color, FILL_COLOR=color)
   ENDFOR    win.Refresh            ; Turn window updating ON.    END  

This can result in a fairly long delay before something appears in the window. So another approach would be to display the initial axes in the window and wait for the bar plot to appear in its final incarnation. In this case, you hide the bar plot until you are ready to display it. The code looks like this.

   b = Barplot(/TEST, /HIDE) ; Hide barplot, but display axes.
   b.Refresh, /DISABLE       ; Turn barplot updating OFF.
   FOR j=0, 20 DO BEGIN
      color = [Randomu(seed,1)*255, Randomu(seed,1)*255, Randomu(seed, 1)*255]
      !null = Barplot(/TEST, /OVERPLOT, TRANSPARENCY=50, COLOR=color, FILL_COLOR=color)
   ENDFOR    b.Hide = 0                ; Turn bar plot hiding off to display.
   b.Refresh                 ; Display the finished bar plot    END 

Another Possible Reason for Slowness

Another reason this graphics output might be slow to render is that each time you add another plot to the graphic the ranges of all the axes need to be recalculated. This takes quite a bit of time, especially if you are just overplotting onto the same set of axes. To avoid the recalculating the axes range every time, set the axes range specifically on the first plot command. Then, subsequent overplots will not do the recalculation and will speed up.

   b = Barplot(/TEST, XRANGE=[-1,20], YRANGE=[0,1])    FOR j=0, 20 DO BEGIN
      color = [Randomu(seed,1)*255, Randomu(seed,1)*255, Randomu(seed, 1)*255]
      !null = Barplot(/TEST, /OVERPLOT, TRANSPARENCY=50, COLOR=color, FILL_COLOR=color)
   ENDFOR    END 

Version of IDL used to prepare this article: IDL 8.0

Google
 
Web Coyote's Guide to IDL Programming