HoloDraw Program Documentation: surfdraw

Documentation | Download | Examples | Frequently Asked Questions (FAQ)

Program Summary

Filename surfdraw.pl
Author Marvin Simkin
Program Created 2003-04-08
Last Updated Jan 28 13:06
Purpose read GMT surface grid or similar data and draw a solid surface
syntax surfdraw.pl < topo.surf > topo.draw
topo.surf some surface data produced e.g. by GMT "surface" command
topo.draw object drawing instructions for drawiv.pl or drawwrl.pl

Discussion

This reads gridded data, such as a digital elevation map.
Gridded data has a series of regularly spaced measurements
which when combined define a surface, such as a topography.
The X and Y points are assumed to be laid out in a
rectangular grid pattern, for example every 5 meters,
with the Z measurement representing the height at that X-Y point.

For example, here is a 3 by 3 grid in which the elevation is 0
around the outside but 5 in the center:
0 0 0
0 5 0
0 0 0
(This is a diagram of the grid with all of the numbers being Z values.)

The data for this grid would be input to surfdraw.pl by giving the X and Y
coordinates of each point along with its Z value:
X Y Z
= = =
0 0 0
1 0 0
2 0 0
0 1 0
1 1 5
2 1 0
0 2 0
1 2 0
2 2 0

This program is intended to accept 3 input formats.
(Currently only 2 are working...)

THREE COLUMN INPUT
The data is a grid of X Y Z values
463114{tab}896228{tab}860.646
463200{tab}896228{tab}862.11
463285{tab}896228{tab}863.574
463371{tab}896228{tab}865.038
463456{tab}896228{tab}866.501
463542{tab}896228{tab}867.962
463627{tab}896228{tab}869.422
463713{tab}896228{tab}870.879
463798{tab}896228{tab}872.333
463884{tab}896228{tab}873.782

Spaces can be used in place of the tab characters if you prefer.

Data should be ordered with X varying fastest and repeatedly,
with one sequential pass through Y, as illustrated in the file
fragment above. Notice that X is incrementing by 85.5 (the source
data was rounded after generation) but Y remains the same.
Eventually the first iteration through all X values would end,
Y would be incremented (probably by 85.5) and we would start over
with the same X values again.
This assumes the X values are the same for every pass
though it could probably be modified to handle other cases.

This program makes triangles connecting the grid points
to create a solid VRML surface (using drawiv.pl or drawwrl.pl).

This outputs triangles instead of rectangles
because no matter how convoluted the topography,
3 points will always be coplanar
while a rectangle could be warped such that one of the corners
is not on the same plane as the other 3

FOUR COLUMN INPUT
## NOT WORKING YET
## Same as three column input except the 4th column is an attribute
## which is looked up in a Color Palette Table to color the polygons.
## The data is a grid of X Y Z values followed by some Attribute
## 463114{tab}896228{tab}860.646{tab}1.2
## 463200{tab}896228{tab}862.11{tab}3.4
## 463285{tab}896228{tab}863.574{tab}5.6

SIX COLUMN INPUT
Same as three column input with the addition of Red Green and Blue
values to color each input point
The data is a grid of X Y Z values followed by R G B
463114{tab}896228{tab}860.646{tab}1{tab}0{tab}0
463200{tab}896228{tab}862.11{tab}1{tab}1{tab}0
463285{tab}896228{tab}863.574{tab}0.5{tab}0{tab}1

COLOR NOTE
Unfortunately, colors have to be applied to polygons, not to points.
But in the input, colors are associated with points.
It takes 4 points to define the boundaries of one pair of polygons.
What this means is that some colors have to be ignored,
because there aren't enough polygons to go around.
For now I have decided to solve this problem the same way I solved
a similar problem in xyzadraw.pl, namely, the first colors in the
data will be used and the last ones will be dropped.
This means that the color of the last X point in each row will
be ignored, along with all the colors of the entire last Y column.

Consider:
*----*----*
|~~~/|~~~/|
|~~/~|~~/~|
|~/~~|~/~~|
|/~~~|/~~~|
*----*----*
|~~~/|~~~/|
|~~/~|~~/~|
|~/~~|~/~~|
|/~~~|/~~~|
*----*----*
There are 9 points (*) but only 4 shaded squares
(each rendered as 2 triangles.)
The colors are associated with the shaded areas, not the points.
So only 4 point colors can be used, the rest are discarded.

There might be some way to generate a LOT more polygons
and dither the colors, but I am going to leave that for later
if at all.

Output data format
color=R G B    # if 4 or 6 column input
polygon:X1 Y1 Z1,X2 Y2 Z2,X3 Y3 Z3;polygon:X1 Y1 Z1,X2 Y2 Z2,X3 Y3 Z3


Written by Marvin Simkin
Filename surfdraw.html
Last updated April 5, 2005
Arizona State University Valid HTML 4.01!
Freedom to Choose ANY Browser