
[The following article appeared in the April 1994 issue of Gimme 
Arrays!, the newsletter of the Toronto ACM APL Special Interest Group.
You can reach the SIG at P.O. Box 384, Adelaide Street Post Office,
Toronto, Ontario, Canada, M5C 2J5. This article may be reproduced 
provided that the Toronto ACM SIGAPL chapter and author are acknowledged.
No warranty is given or implied by these scripts which are provided 'as is'.]


From Pentagons and Plasma Clouds to Cliff Dwellers (Part II)
Cameron Linton <crl@ipsalab.tor.soliton.com>


This is the second installment of the review of the February 28, 1994 
presentation by Clifford Reiter to the Toronto ACM SIGAPL. 

Cliffords mathematics visualization class did not stop with the 
two-dimensional Sierpinski Triangle images discussed in the first part of 
this article. For three-dimensional interpretations Clifford integrated 
the results from his J scripts with the freeware package Persistence of 
Vision Ray Tracer (POV-Ray) v2.01. 

POV-Ray is a copyrighted freeware program that allows users to create 
three-dimensional, photo-realistic images easily using a rendering
technique called ray tracing. POV-Ray reads an ASCII text file containing 
information describing the objects and lighting in a scene from the 
viewpoint of a camera which is also described in the text file. POV-Ray 
mathematically simulates the rays of light moving through the scene to 
produce a photo-realistic image with shading, perspective, reflections, and
lighting. 

Clifford initialized his scenes by describing boxes in an ASCII file using
POV-Rays scene description language. He then used J to generate the 
coordinate data of the boxes which he appended to the file. POV-Ray parses 
this input file and renders an image in Targa (.TGA) graphics format. A 
graphics image viewing product such as Paint Shop Pro2 can then display 
the result and convert it to a bit map (.BMP) file if desired.

Installation

Install POV-Ray in, for example, directory c:\shware\povray on the C drive 
of your PC from a diskette1 in your B drive. Starting from the root 
directory of your C drive, create the necessary subdirectories and change 
the current directory.  Copy the files povdoc.zip, povscn.zip, and 
povibm.exe. 

c:
cd \
mkdir shware
cd shware
mkdir povray
cd povray
copy b:pov*.*

Then, unzip povdoc.zip, preserving the directory structure, and run the 
self-extracting file povibm.exe; its OK to overwrite duplicate files. Do 
a little house-keeping. 

pkunzip povdoc.zip -d
povibm.exe
del pov*.zip
del povibm.exe
Information on POV-Ray is located in the files
..\ibmdocs\povinf.doc
..\ibmdocs\povlegal.doc
..\docs\povray.doc

Demonstration

Prepare to run the demonstration by adding c:\shware\povray to your current 
search path. Ensuring that c:\shware\povray is still the current directory, 
create a designs subdirectory and copy the file s3head.pov from the floppy 
disk.

mkdir designs
cd designs
copy b:s3head.pov

The file s3head.pov contains Cliffords scene initialization information.
(You can view 's3head.pov' using an ASCII text editor.)

Next, switch to J 7.0. It is convenient to keep a DOS Window open so that 
you can toggle between J, DOS, and Paint Shop Pro. In J, execute the script 
sierpin3.js3 by typing:

NB. substitute your directory
0!:2 <c:\crl\cliff\sierpin3.js

This creates the file sierpin3.pov (see below). The first three lines 
represent three boxes, one on top of each other. In this example, 343 lines 
are generated. sierpin3.pov is an ASCII file which contains the scene 
initialization information of sierpin3.pov plus the box coordinates 
generated from J. This will be your input file to POV-Ray.

===sierpin.pov - start ===
object{box{<0,0,0><0.125,0.125,0.125>} pigment{rgb<1,0,0>}}       
object{box{<0,0,0.125><0.125,0.125,0.25>} pigment{rgb<1,0,0>}} 
object{box{<0,0,0.25><0.125,0.125,0.375>} pigment{rgb<1,0,0>}} 
. . .
object{box{<0.875,0.75,0><1,0.875,0.125>} pigment{rgb<1,0,0>}} 
object{box{<0.875,0.75,0.125><1,0.875,0.25>} pigment{rgb<1,0,0>}}
object{box{<0.875,0.875,0><1,1,0.125>} pigment{rgb<1,0,0>}} 
===sierpin.pov - end ===


In the sierpin3.js code, b is an 8 by 8 by 8 array of 1s and 0s, and reminds
us of the Raster arrays described in the previous article. si is an enclosed
array of tuples representing the boxes to be rendered. There is one for each
position of a 0 in the original b array. fmtbox calculates near lower left 
and far upper right corners of the box and formats the coordinates for the 
POV-Ray parser to understand. 

You are now ready to render this file to create your graphics (.TGA) file. 
Switch to the DOS Window and execute from the c:\shware\povray\designs 
directory.

povray -isierpin3.pov -osierpin3.tga +linclude +ft -h200 -w200 +v

This will create a 200 by 200 colour pixel graphics file called 
sierpin3.tga. On a 50 MHz 486 with 16 Megs of RAM this took thirty-nine 
seconds to render. Wait for POV-Ray to render each line of the output file.

The last step is to view the file in a graphics viewer such as Paint Shop 
Pro. Switch to this program and File Menu, Open, TGA Format, 
c:\shware\povray\designs\sierpin3.tga, OK to see the result (Figure 1).

By changing n to 4 you get a finer pattern (Figure 2). On the 50 MHZ 486 PC
it took about thirty seconds to generate the 2400+ lines from J, and two 
minutes for POV-Ray to render the TGA file with 250 by 250 pixels.

This is a very simple demonstration of the elaborate three-dimensional 
Cliff Dweller graphic images that Clifford presented to the Toronto group.

Once again, on behalf of the Toronto ACM SIGAPL, I would like to thank 
Clifford for an entertaining evening, for introducing us to new concepts, 
and for showing an application of APL and J integrated into other software 
systems.



Footnotes
1.	The POV-Ray files are available over Internet by anonymous FTP from 
        alfred.ccs.carleton.ca (134.117.1.1) in /pub/pov-ray. POV-Ray 
        headquarters are on CompuServe GRAPHDEV forum Raytracing sections.
        To run POV-Ray on a personal computer you need the files 
        POVDOC.ZIP and POVIBM.EXE. As a user you are legally required 
        to possess the file POVSCN.ZIP containing sample scenes too. For 
        those without Internet or CompuServe access, the POV-Ray files will 
        also be available at the April 25, 1994 Toronto SIGAPL meeting. 
        Bring a 3.5" HD floppy.

2.	Paint Shop Pro v1.02a is a copyright Windows shareware program 
        available from JASC, Inc., +1 612-930-9171.

3.	These scripts (plus others used by Clifford) will be available at 
        the April 25, 1994 meeting for those members who bring a 3.5" HD 
        floppy. They are also available over Internet by anonymous FTP from
        Waterloo at archive.UWaterloo.CA (129.97.129.140 or 129.97.128.10) 
        in /languages/apl/j/workspaces/reiter.zip.



