3 #---------------------------------------------------------------------------
4 # Toplevel script to automate DEM file processing and conversion
6 # Written by Curtis Olson, started January 1998.
8 # Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 # (Log is kept at end of this file)
26 #---------------------------------------------------------------------------
29 $| = 1; # flush buffers after every write
32 # return the file name root (ending at last ".")
37 $pos = rindex($file, ".");
38 return substr($file, 0, $pos);
42 # set the FG_ROOT environment variable if it hasn't already been set.
43 if ( $ENV{FG_ROOT} eq "" ) {
44 # look for a file called fgtop as a place marker
47 } elsif ( -e "../fgtop" ) {
53 # 1. Start with file.dem
55 $dem_file = shift(@ARGV);
56 $error = shift(@ARGV);
59 print "Source file = $dem_file Error tolerance = $error\n";
62 die "I doubt you'll be happy with an error tolerance as low as $error.\n";
65 # 2. dem2node $FG_ROOT dem_file tolerance^2 (meters)
67 # - dem2node .. dem_file 160000
69 # splits dem file into 64 file.node's which contain the
70 # irregularly fitted vertices
72 $command = "./Dem2node/demfit $ENV{FG_ROOT} $dem_file $error";
74 print "Running '$command'\n";
76 open(OUT, "$command |");
81 $subdir =~ s/Dir = //;
87 # 3. triangle -q file (Takes file.node and produces file.1.node and
90 $subdir = "../Scenery/w120n030/w111n033";
91 print "Subdirectory for this dem file is $subdir\n";
93 @FILES = `ls $subdir`;
94 foreach $file ( @FILES ) {
97 if ( ($file =~ m/\.node$/) && ($file !~ m/\.\d\.node$/) ) {
98 $command = "./Triangle/triangle -q $subdir/$file";
99 print "Running '$command'\n";
100 open(OUT, "$command |");
106 # remove input file.node
107 unlink("$subdir/$file");
112 # 4. fixnode file.dem subdir
114 # Take the original .dem file (for interpolating Z values) and the
115 # subdirecotry containing all the file.1.node's and replace with
118 $command = "./FixNode/fixnode $dem_file $subdir";
119 print "Running '$command'\n";
120 open(OUT, "$command |");
127 # 5. tri2obj file (.1.node)
129 # Take the file.1.node and file.1.ele and produce file.1.obj
131 @FILES = `ls $subdir`;
132 foreach $file ( @FILES ) {
134 if ( $file =~ m/\.1\.node$/ ) {
135 $file =~ s/\.node$//; # strip off the ".node"
137 $command = "./Tri2obj/tri2obj $subdir/$file";
138 print "Running '$command'\n";
139 open(OUT, "$command |");
145 unlink("$subdir/$file.node");
146 unlink("$subdir/$file.node.orig");
147 unlink("$subdir/$file.ele");
153 # 6. strip file.1.obj
155 # Strip the file.1.obj's
157 # 7. cp bands.d file.2.obj
159 # strips produces a file called "bands.d" ... copy this to file.2.obj
161 @FILES = `ls $subdir`;
162 foreach $file ( @FILES ) {
164 if ( $file =~ m/\.1\.obj$/ ) {
165 $command = "./Stripe_u/strips $subdir/$file";
166 print "Running '$command'\n";
167 open(OUT, "$command |");
173 # copy to destination file
175 $newfile =~ s/\.1\.obj$//;
176 print "Copying to $subdir/$newfile.2.obj\n";
177 open(IN, "<bands.d");
178 open(OUT, ">$subdir/$newfile.2.obj");
185 unlink("$subdir/$file");
192 # Sort file.2.obj by strip winding
194 @FILES = `ls $subdir`;
195 foreach $file ( @FILES ) {
197 if ( $file =~ m/\.2\.obj$/ ) {
199 $newfile =~ s/\.2\.obj$/.obj/;
201 $command = "./FixObj/fixobj $subdir/$file $subdir/$newfile";
202 print "Running '$command'\n";
203 open(OUT, "$command |");
209 unlink("$subdir/$file");
214 #---------------------------------------------------------------------------
216 # Revision 1.1 1998/01/09 23:06:46 curt