Re: ERASING a line [message #7159 is a reply to message #7152] |
Wed, 09 October 1996 00:00   |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Mario Noyon <mnoyon@jmc-luni.u-bordeaux2.fr> writes:
> I would like to draw a vertical line on a drawing widget and erase it
> afterwards. Just like idl does it with the BOX_CURSOR.
> I watched this routine to see how they did, but my procedure refuses to
> redraw the line erased.
> Does someone have an idea?
You should count your blessings. I have just the opposite problem.
My procedures do *exactly* what I tell them to do, but half the
time they produce nonsense. The technical term for this is
"recalcitrant procedures".
Andy Loughe suggests one solution. Draw the line over again in
the background color.
PLOTS, line, color=!P.BACKGROUND
This is often an excellent solution, but it is not really "erasing" the
box, which you will soon discover if your line crosses anything other
than background.
The technique used in the BOX_CURSOR program is to use the
exclusive OR graphics function.
DEVICE, SET_GRAPHICS_FUNCTION=6 ; XOR mode
PLOTS, line ; Draw the line
PLOTS, line ; Erase the line
DEVICE, SET_GRAPHICS_FUNCTION=3 ; Normal mode
This works by "flipping" the bits of the underlying pixel
values to their "opposite" color. When you draw the second
time, the pixels are flipped back to their original values,
thereby erasing the line.
Unfortunately, this does not always give satisfactory results either
because you can't exactly draw a "green" box, unless you have
a private color table in IDL (and who does?). Since I often want
to draw lines in green or yellow, or some other pleasant color,
I prefer to use a technique called "device copy" in conjunction
with pixmap windows.
In this technique, you create a copy of your graphics window
as a pixmap window (a window in memory). This has everything
your graphics window has in it, except for the line that you
drew in the graphics window. When you want to erase the
line, you "copy" the contents of the pixmap window into the
graphics window. (Sometimes you copy only the portion of
the pixmap window necessary to repair the damage in the
graphics window, but most of the time this technique is
fast enough that I just slam the whole pixmap window
over.) This has the effect of erasing the line. It will
look something like this:
WINDOW, 0, TITLE='Graphics Window', XS=300, YS=300
PLOT, data
OPLOT, moredata
WINDOW, 1, /PIXMAP, XS=300, YS=300
PLOT, data
OPLOT, moredata
; Now draw the line in the graphics window.
WSET, 0
PLOTS, line, COLOR=green
; Now erase the line.
DEVICE, COPY=[0, 0, 300, 300, 0, 0, 1]
Device copy is extremely fast (*much* faster than just re-doing
the graphics). It is the technique I would recommend.
Yours,
David
--
David Fanning, Ph.D.
Phone: 970-221-0438
Fax: 970-221-4728
E-Mail: davidf@fortnet.org
|
|
|