MathGroup Archive 1997

[Date Index] [Thread Index] [Author Index]

Search the Archive

special ColorFunction

  • To: mathgroup at smc.vnet.net
  • Subject: [mg5984] special ColorFunction
  • From: rustybel at foothill.net (Russell Towle)
  • Date: Sat, 8 Feb 1997 22:37:58 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

Hi all,

A couple of weeks ago I posed a question to the group about a special
ColorFunction.  Mr. Jeffrey Adams was kind enough to reply and he managed
to contrive exactly the function which I needed.  The function sends the
scaled values used internally in a function such as ListDensityPlot, values
which run from 0 to 1, into an RGBColor specification, such that of the
three bytes which make 24-bit RGB color, the red byte expresses the nearest
multiple of 1/255 times the scaled value, rounded down, and the green byte,
how shall I say it, expresses the difference between one red level and the
next.  The effect is that the two bytes taken together express a 16-bit
number.  The blue byte is set to zero.  The purpose of all this is to
prepare USGS landscape elevation data in Mathematica for rendering as a
height field in POV-Ray.

Mr. Adams also suggested use of Raster as an alternative to
ListDensityPlot.  Here is his function and an example of its use:

HeightFieldColorFunction[ x_ /; x < 0] := RGBColor[0, 0, 0]
HeightFieldColorFunction[ x_ /; x > 1] := RGBColor[1, 1, 0]
HeightFieldColorFunction[ x_ ] := With[ {scaledValue = Floor[x 65535]},
RGBColor[ Quotient[scaledValue, 256]/255. , Mod[scaledValue, 256]/255., 0] ]

An example of its use, as applied to a table of values:

data = Table[Sin[x y], {x,0,4,.1},{y,0,4,.1}];
Show[ Graphics[
Raster[data, {{0,0}, Dimensions[data]}, {Min[data],Max[data]},
ColorFunction -> HeightFieldColorFunction ] ], AspectRatio->1]

Although I am using this to render landscapes in POV-Ray, with Mr. Adam's
special ColorFunction a variety of "mathematical" surfaces could be
exported to POV-Ray, without ever creating an explicit list of polygons, as
would otherwise be the case.  In order to do this, Adam's function must be
applied, as above; the resulting strangely speckled image must then be
converted to 24-bit Targa format, for use in POV-Ray.  On my Macintosh I do
this by first converting the graphic to the object PICT format, then
copying it to the clipboard and, using the Convert Clipboard command,
exporting it to an external PICT file.  Then I use PhotoShop to crop the
white boundary away and save it as a Targa.  Other programs might be used
to do this, such as Graphic Converter, which is shareware, but I am not
familiar with these.

Mr. Adams also contrived a way to export the images to Targa files directly
from within Mathematica, using the FastBinaryFiles MathLink program, and a
notebook he wrote.  But it does not handle the large arrays of elevations
very well, and the kernel runs out of memory.  This was a problem even when
the array of elevations was of dimensions {371, 472}.

I find POV-Ray useful for rendering scenes with many polygons, using the
heightfield function; I have rendered landscapes containing over 17 million
triangles, which in Mathematica would have been impossible.

Russell Towle
Giant Gap Press:  books on California history, digital topographic maps
P.O. Box 141
Dutch Flat, California 95714
------------------------------
Voice:  (916) 389-2872
e-mail:  rustybel at foothill.net
------------------------------




  • Prev by Date: Plot has HoldAll, Why?
  • Next by Date: Re: Integration
  • Previous by thread: Plot has HoldAll, Why?
  • Next by thread: Fwd: Why doesn't this simplify further?