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

Another fun question about color in IDL



Well, I was just getting the hang of all this, then I
started going to object graphics and now I'm confused
again. I have some 2D data that I was surface'ing and
shade_surf'ing with the z axis intensity colored by
data value, blue's low, red's high. e.g., say I have
the data:

x = [10,20,30]
y = [0,-1,-2,-3]
z = [[0.0,0.4,0.1],[1.0,0.6,0.2],[2.0,0.8,0.3],[3.0,1.0,0.4]]

then I can show it with a little (direct graphics) routine I have:
result = tbSurfPlot(z, x, y, CHARSIZE=1.5, SHADED=1, COLORDATA=zData)

;////////////////////////////
function tbSurfPlot, zData, xData, yData, $
 NODATA=noData, COLORDATA=colorData,SHADED=shaded, $
 Ax=AX, Az=AZ, XTitle=XTITLE, YTitle=YTITLE, ZTitle=ZTITLE, $
 charSize=CHARSIZE

 ;//Function to display surfaces like I usually like 'em.
 ;NODATA - pass value to set as missing data.
 ;COLORDATA - pass a data set to set color shading by.
 ;  Defaults to zData, color to itself
 ;SHADED - If set, plots a shade_surf w/ overlaid grid surface
 ;  to give depth, else just a surface
 ;AX,AZ,XTITLE,YTITLE,ZTITLE,CHARSIZE - passed to surface
 ;  and/or shade_surf routines

 ;//Keyword processing/set defaults
 if keyword_set(NODATA) then zData[where(zData EQ noData)] = !Values.F_NaN
 if keyword_set(COLORDATA) EQ 0 then colorData = zData
 if keyword_set(AX) EQ 0 then Ax = 30
 if keyword_set(AZ) EQ 0 then Az = 30
 if keyword_set(XTITLE) EQ 0 then XTitle = "X"
 if keyword_set(YTITLE) EQ 0 then YTitle = "Y"
 if keyword_set(ZTITLE) EQ 0 then ZTitle = "Z"
 if keyword_set(CHARSIZE) EQ 0 then charSize = 1

 ;///////////////////////////////////////////////////////////////////////
 ;//Set up display: from D. Fanning Book/////////////////////////////////
 ;///////////////////////////////////////////////////////////////////////
 if !version.release GE 5.2 then $
  device, get_visual_depth=visualDepth $
 else if !D.N_Colors GT 256 then $
  visualDepth = 16 $
 else $
  visualDepth = 8
 if visualDepth GT 8 then $
  ;//Use 24-bit display color tables
  device, decomposed = 0
 ;///////////////////////////////////////////////////////////////////////

 ;///////////////////////////////////////////////////////////////////////
 ;//Save original color table
 tvlct, old_r,old_g,old_b, /get

 ;//Load rainbow color table for colored shading
 loadct, 13

 ;//Set background and foreground colors
 tvlct, 190,190,190, 253 ;grey
 tvlct, 000,000,000, 254 ;black
 ;tvlct, 255,255,255, 255 ;white
 tvlct, 250,250,210, 255 ;ecru'ish?
 !p.color = 254
 !p.background = 255
 ;///////////////////////////////////////////////////////////////////////

 ;///////////////////////////////////////////////////////////////////////
 ;//plot it up
 if keyword_set(SHADED) then begin
  shade_surf, zData, xData, yData, $
   Ax=AX, Az=AZ, $
   shades=bytscl(colorData, top=!D.N_Colors-4, NaN=1), $
   XTitle=XTitle, YTitle=YTitle, ZTitle=ZTitle, charsize=charSize
  surface, zData, xData, yData, $
   Ax=AX, Az=AZ, $
   /noerase, thick=0.25, linestyle=1, $
   XTitle=XTitle, YTitle=YTitle, ZTitle=ZTitle, charsize=charSize
 endif else begin
  surface, zData, xData, yData, $
   Ax=AX, Az=AZ, $
   shades=bytscl(colorData, top=!D.N_Colors-4, NaN=1), $
   XTitle=XTitle, YTitle=YTitle, ZTitle=ZTitle, charsize=charSize
 endelse
 ;///////////////////////////////////////////////////////////////////////

 ;//Restore original color table
 tvlct, old_r,old_g,old_b

 return, 1
end ;//end tbSurfPlot
;////////////////////////////

Dandy.
Then I decided to get cute when David Fanning pointed me to his
xsurface object graphics procedure at
http://www.dfanning.com/programs/xsurface.pro
I thought, hmmmm, I'll just make his solid surface option which
uses yellow by default and switch it to use my color shading
instead, the equivalent of:

colorData = zData
shade_surf, zData, xData, yData, Ax=AX, Az=AZ, $
shades=bytscl(colorData, top=!D.N_Colors-4, NaN=1), $
XTitle=XTitle, YTitle=YTitle, ZTitle=ZTitle, charsize=charSize

in my direct graphics code.

Well, you can probably guess the rest. I can't get the RGB model
it defaults to to handle colors the way I've been using them. It
seemed simple enough, scan his code for the surface creation call:

thisSurface = OBJ_NEW('IDLgrSurface', data, x, y, $
   Color=[255,255,0], _Extra=extra)

and tweak it with the SHADE_RANGE keyword which I thought would be
analagous to the SHADES keyword in shade_surf. No luck. It's only
a 2 element vector. I'm trying to do something with a palette, but
I think I'm not grasping the concepts of the obj. graphics model or
RGB.

Can anyone give me a nudge (or preferably a hard shove) in the
right direction??

Thanks, as always.
TB