Re: cgcolor, cgplot, and /WINDOW [message #75517 is a reply to message #75516] |
Tue, 22 March 2011 22:02   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Kwill writes:
> I was excited to learn today of David's Coyote Graphics packages, and
> downloaded them on both my laptop and desktop. I'm getting very
> puzzling results on one machine (but not the other). When I set the /
> WINDOW keyword in cgplot, cgcolor will not work for overplotting in
> color, displaying all subsequent points in a dark grey.
>
> My example:
>
> IDL> cgplot, indgen(10),color=cgcolor("Dodger Blue"), /window
> IDL> cgplot, indgen(10)+1, color=cgcolor("Hot Pink"), /window, /over
>
> This results in one blue and one grey line plotted on the screen. I do
> not have any color problems when the /WINDOW keyword is not set.
>
> I tried an identical series of commands on my laptop: it runs
> perfectly, producing both a blue and pink line. Both of my machines
> run IDL Version 7.1.1, Mac OS X (darwin x86_64 m64) on Snow Leopard
> 10.6.4.
>
> I'm baffled as to why this would be different between my two machines,
> but hopeful that I'm doing something wrong and that CGCOLOR plays
> nicely with the resizeable window in CGPLOT. Any ideas?
OK, this explanation is complicated. :-)
First of all. This is the wrong way to pass a color to
cgPlot. The color does NOT have to go through cgColor,
since it will go through cgColor internally in cgPlot.
By calling the command the way Kwill has here, a string
is turned into a number, then the number is passed to
cgPlot.
In itself, this is not a problem. In fact, had Kwill just
issued these two commands and had them display in a normal
IDL graphics window, there would have been no problem. He
would have gotten the result he expected. And, of course,
as he reports, he has no problem if he uses the software
correctly.
He would also have gotten the result he expected in cgWindow
had he been in decomposed color mode. I suspect the reason
one machine worked and the other didn't is that one machine
was in decomposed color mode and the other wasn't. One of
my goals (probably not possible in my life time) is to convince
everyone to run IDL in decomposed color mode. In fact, I would
strongly support IDL eliminating indexed color mode entirely.
It would make me a rich man. :-)
BUT, he was in indexed color mode and he wanted to display
the commands in cgWindow. So, as I say, things are complicated. :-)
In indexed color mode, cgColor loads a color in the color table
and returns an index to the loaded color. So it is this number,
say, 138 that is passed into cgPlot. cgPlot does ALL its
graphics in decomposed color, so it has to convert that index
number to a 24-bit value. As you can see, it did this
correctly with the first command, and incorrectly with the
second command. How come? This is the mystery.
It turns out that to make cgWindow work properly in an
unknown IDL color environment, I have to exercise pretty
tight control over the color space. Basically, what I do
is save the current color table when I enter a program, and
restore it after I leave. What I do between entering and
leaving is no business of yours.
This works pretty well, until there are two commands to
execute in a resizeable graphics window. What happens
when the program was called the way Kwill called it was
that between the first and second commands, the color
table was "restored" to the way it was when the program
was first called. This had the effect of "erasing" the
hot pink color, so that the color at 138 was a gray color,
not hot pink. In other words, the sequencing of the loading
and restoring the color tables went awry.
So, the take home message is this. (1) Call the programs
they way they were meant to be called, or (2) Swear off
indexed color forever. I can assure you if you choose (2)
life will be very, very pleasant for you. You may even
come to understand how color works in IDL. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|