#!/usr/bin/perl # filename: makesurf.pl # author: Marvin Simkin # date: 2002-11-17 # purpose: read Garmin Mapsource output make road lines # syntax: makesurf.pl < bed.surf > bed.draw # bed.surf: some surface data produced e.g. by GMT "surface" command # bed.draw: object drawing instructions for makeiv.pl # NOTE: # Input data format: # 463114{t}896228{t}860.646 # 463200{t}896228{t}862.11 # 463285{t}896228{t}863.574 # 463371{t}896228{t}865.038 # 463456{t}896228{t}866.501 # 463542{t}896228{t}867.962 # 463627{t}896228{t}869.422 # 463713{t}896228{t}870.879 # 463798{t}896228{t}872.333 # 463884{t}896228{t}873.782 # # Data should be ordered with X varying fastest and repeatedly, # with one sequential pass through Y. # # Gridded data varies by X while Y remains constant, # for the first pass through the grid. # Then X starts over with the next Y. # This program makes triangles connecting the grid points # to create a solid VRML 1.0 surface (after conversion with makeiv.pl). # # This assumes the X values are the same for every pass # though it could probably be modified to handle other cases. # Output data format # triangle:X1,Y1,Z1,X2,Y2,Z2,X3,Y3,Z3 # INITIALIZE: my @Column; my $LastX; $LastX = ''; my $LastY; $LastY = ''; my $ThisY; $ThisY = ''; my %LastZ; my $SaveZ; # SUBROUTINES: use strict; # ARGUMENTS: # MAINLINE: my $Line; while ($Line = <>) { chomp $Line; @Column = split (' ', $Line); # don't bother with too-short lines if ($#Column > 1) { my $X; my $Y; my $Z; $X = $Column[0]; $Y = $Column[1]; $Z = $Column[2]; if ($Y eq $ThisY) { # continue with same row # if this is the first row we can't draw triangles yet if ($LastY ne '') { # draw a pair of triangles on one line since they go together #ENH# could set color (or delete entirely) depending on surface grid accuracy #ENH# or possibly even pick up a pixel from a same-gridded image? print "triangle:$LastX,$LastY,$SaveZ,$LastX,$ThisY,$LastZ{$LastX},$X,$Y,$Z;"; print "triangle:$LastX,$LastY,$SaveZ,$X,$LastY,$LastZ{$X},$X,$Y,$Z\n"; } } else { # starting a new row $LastY = $ThisY; $ThisY = $Y; # since this is the first point on this row we can't draw triangles } # save remembered point before we overwrite it $SaveZ = $LastZ{$X}; # save incoming point for next pass $LastZ{$X} = $Z; $LastX = $X; } else { print STDERR "Skipped line without 3 columns of data: '$Line'\n"; } }