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
42 # return the file name root (ending at last ".")
47 $pos = rindex($file, ".");
48 return substr($file, 0, $pos);
52 # set the FG_ROOT environment variable if it hasn't already been set.
53 if ( $ENV{FG_ROOT} eq "" ) {
54 # look for a file called fgtop as a place marker
57 } elsif ( -e "../fgtop" ) {
63 # 1. Start with file.dem
65 $dem_file = shift(@ARGV);
66 $error = shift(@ARGV);
69 print "Source file = $dem_file Error tolerance = $error\n";
72 die "I doubt you'll be happy with an error tolerance as low as $error.\n";
75 # 2. dem2node $FG_ROOT dem_file tolerance^2 (meters)
77 # - dem2node .. dem_file 160000
79 # splits dem file into 64 file.node's which contain the
80 # irregularly fitted vertices
83 $command = "./Dem2node/demfit $ENV{FG_ROOT} $dem_file $error";
85 print "Running '$command'\n";
87 open(OUT, "$command |");
92 $subdir =~ s/Dir = //;
97 $subdir = "../Scenery/w120n030/w111n033";
98 printf("WARNING: Hardcoding subdir = $subdir
101 # 3. triangle -q file (Takes file.node and produces file.1.node and
104 print "Subdirectory for this dem file is $subdir\n";
106 if ( $do_triangle_1 ) {
107 @FILES = `ls $subdir`;
108 foreach $file ( @FILES ) {
111 if ( ($file =~ m/\.node$/) && ($file !~ m/\.\d\.node$/) ) {
112 $command = "./Triangle/triangle -q $subdir/$file";
113 print "Running '$command'\n";
114 open(OUT, "$command |");
120 # remove input file.node
121 unlink("$subdir/$file");
126 # 4. fixnode file.dem subdir
128 # Take the original .dem file (for interpolating Z values) and the
129 # subdirecotry containing all the file.1.node's and replace with
133 $command = "./FixNode/fixnode $dem_file $subdir";
134 print "Running '$command'\n";
135 open(OUT, "$command |");
143 # 4.1 splittris file (.1.node) (.1.ele)
145 # Extract the corner, edge, and body vertices (in original
146 # geodetic coordinates) and normals (in cartesian coordinates) and
147 # save them in something very close to the .obj format as file.se,
148 # file.sw, file.nw, file.ne, file.north, file.south, file.east,
149 # file.west, and file.body. This way we can reconstruct the
150 # region using consistant edges and corners.
152 # Arbitration rules: If an opposite edge file already exists,
153 # don't create our matching edge. If a corner already exists,
154 # don't create ours. Basically, the early bird gets the worm and
155 # gets to define the edge verticies and normals. All the other
156 # adjacent tiles must use these.
158 if ( $do_splittris ) {
159 @FILES = `ls $subdir`;
160 foreach $file ( @FILES ) {
162 if ( $file =~ m/\.1\.node$/ ) {
163 $file =~ s/\.node$//; # strip off the ".node"
165 $command = "./SplitTris/splittris $subdir/$file";
166 print "Running '$command'\n";
167 open(OUT, "$command |");
177 # 4.2 read in tile sections/ele) skipping edges, read edges out of
178 # edge files, save including proper shared edges (as node/ele)
179 # files. If my edge and adjacent edge both exist, use other,
180 # delete mine. If only mine exists, use it.
183 # 4.3 Retriangulate fixed up files (without -q option)
186 # 5. tri2obj file (.1.node) (.1.ele)
188 # Take the file.1.node and file.1.ele and produce file.1.obj
191 @FILES = `ls $subdir`;
192 foreach $file ( @FILES ) {
194 if ( $file =~ m/\.1\.node$/ ) {
195 $file =~ s/\.node$//; # strip off the ".node"
197 $command = "./Tri2obj/tri2obj $subdir/$file";
198 print "Running '$command'\n";
199 open(OUT, "$command |");
205 unlink("$subdir/$file.node");
206 unlink("$subdir/$file.node.orig");
207 unlink("$subdir/$file.ele");
213 # 6. strip file.1.obj
215 # Strip the file.1.obj's
217 # 7. cp bands.d file.2.obj
219 # strips produces a file called "bands.d" ... copy this to file.2.obj
222 @FILES = `ls $subdir`;
223 foreach $file ( @FILES ) {
225 if ( $file =~ m/\.1\.obj$/ ) {
226 $command = "./Stripe_u/strips $subdir/$file";
227 print "Running '$command'\n";
228 open(OUT, "$command |");
234 # copy to destination file
236 $newfile =~ s/\.1\.obj$//;
237 print "Copying to $subdir/$newfile.2.obj\n";
238 open(IN, "<bands.d");
239 open(OUT, ">$subdir/$newfile.2.obj");
246 unlink("$subdir/$file");
254 # Sort file.2.obj by strip winding
257 @FILES = `ls $subdir`;
258 foreach $file ( @FILES ) {
260 if ( $file =~ m/\.2\.obj$/ ) {
262 $newfile =~ s/\.2\.obj$/.obj/;
264 $command = "./FixObj/fixobj $subdir/$file $subdir/$newfile";
265 print "Running '$command'\n";
266 open(OUT, "$command |");
272 unlink("$subdir/$file");
278 #---------------------------------------------------------------------------
280 # Revision 1.4 1998/01/14 15:55:34 curt
281 # Finished splittris, started assemtris.
283 # Revision 1.3 1998/01/14 02:15:52 curt
284 # Updated front end script to keep plugging away on tile fitting.
286 # Revision 1.2 1998/01/12 20:42:08 curt
287 # Working on fitting tiles together in a seamless manner.
289 # Revision 1.1 1998/01/09 23:06:46 curt