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 = //;
98 $subdir = "../Scenery/w120n030/w111n033";
99 print "WARNING: Hardcoding subdir = $subdir\n";
102 # 3. triangle -q file (Takes file.node and produces file.1.node and
105 print "Subdirectory for this dem file is $subdir\n";
107 if ( $do_triangle_1 ) {
108 @FILES = `ls $subdir`;
109 foreach $file ( @FILES ) {
112 if ( ($file =~ m/\.node$/) && ($file !~ m/\.\d\.node$/) ) {
113 $command = "./Triangle/triangle -q $subdir/$file";
114 print "Running '$command'\n";
115 open(OUT, "$command |");
121 # remove input file.node
122 unlink("$subdir/$file");
127 # 4. fixnode file.dem subdir
129 # Take the original .dem file (for interpolating Z values) and the
130 # subdirecotry containing all the file.1.node's and replace with
134 $command = "./FixNode/fixnode $dem_file $subdir";
135 print "Running '$command'\n";
136 open(OUT, "$command |");
144 # 4.1 splittris file (.1.node) (.1.ele)
146 # Extract the corner, edge, and body vertices (in original
147 # geodetic coordinates) and normals (in cartesian coordinates) and
148 # save them in something very close to the .obj format as file.se,
149 # file.sw, file.nw, file.ne, file.north, file.south, file.east,
150 # file.west, and file.body. This way we can reconstruct the
151 # region using consistant edges and corners.
153 # Arbitration rules: If an opposite edge file already exists,
154 # don't create our matching edge. If a corner already exists,
155 # don't create ours. Basically, the early bird gets the worm and
156 # gets to define the edge verticies and normals. All the other
157 # adjacent tiles must use these.
159 if ( $do_splittris ) {
160 @FILES = `ls $subdir`;
161 foreach $file ( @FILES ) {
163 if ( $file =~ m/\.1\.node$/ ) {
164 $file =~ s/\.node$//; # strip off the ".node"
166 $command = "./SplitTris/splittris $subdir/$file";
167 print "Running '$command'\n";
168 open(OUT, "$command |");
174 unlink("$subdir/$file.node");
175 unlink("$subdir/$file.node.orig");
176 unlink("$subdir/$file.ele");
182 # 4.2 read in the split of version of the tiles, reconstruct the tile
183 # using the proper shared corners and edges. Save as a node file
184 # so we can retriangulate.
186 if ( $do_assemtris ) {
187 @FILES = `ls $subdir`;
188 foreach $file ( @FILES ) {
190 if ( $file =~ m/\.1\.body$/ ) {
191 $file =~ s/\.body$//; # strip off the ".node"
193 $command = "./AssemTris/assemtris $subdir/$file";
194 print "Running '$command'\n";
195 open(OUT, "$command |");
205 # 4.3 Retriangulate fixed up files (without -q option)
208 # 5. tri2obj file (.1.node) (.1.ele)
210 # Take the file.1.node and file.1.ele and produce file.1.obj
213 @FILES = `ls $subdir`;
214 foreach $file ( @FILES ) {
216 if ( $file =~ m/\.1\.node$/ ) {
217 $file =~ s/\.node$//; # strip off the ".node"
219 $command = "./Tri2obj/tri2obj $subdir/$file";
220 print "Running '$command'\n";
221 open(OUT, "$command |");
227 unlink("$subdir/$file.node");
228 unlink("$subdir/$file.node.orig");
229 unlink("$subdir/$file.ele");
235 # 6. strip file.1.obj
237 # Strip the file.1.obj's
239 # 7. cp bands.d file.2.obj
241 # strips produces a file called "bands.d" ... copy this to file.2.obj
244 @FILES = `ls $subdir`;
245 foreach $file ( @FILES ) {
247 if ( $file =~ m/\.1\.obj$/ ) {
248 $command = "./Stripe_u/strips $subdir/$file";
249 print "Running '$command'\n";
250 open(OUT, "$command |");
256 # copy to destination file
258 $newfile =~ s/\.1\.obj$//;
259 print "Copying to $subdir/$newfile.2.obj\n";
260 open(IN, "<bands.d");
261 open(OUT, ">$subdir/$newfile.2.obj");
268 unlink("$subdir/$file");
276 # Sort file.2.obj by strip winding
279 @FILES = `ls $subdir`;
280 foreach $file ( @FILES ) {
282 if ( $file =~ m/\.2\.obj$/ ) {
284 $newfile =~ s/\.2\.obj$/.obj/;
286 $command = "./FixObj/fixobj $subdir/$file $subdir/$newfile";
287 print "Running '$command'\n";
288 open(OUT, "$command |");
294 unlink("$subdir/$file");
300 #---------------------------------------------------------------------------
302 # Revision 1.5 1998/01/15 02:50:08 curt
303 # Tweaked to add next stage.
305 # Revision 1.4 1998/01/14 15:55:34 curt
306 # Finished splittris, started assemtris.
308 # Revision 1.3 1998/01/14 02:15:52 curt
309 # Updated front end script to keep plugging away on tile fitting.
311 # Revision 1.2 1998/01/12 20:42:08 curt
312 # Working on fitting tiles together in a seamless manner.
314 # Revision 1.1 1998/01/09 23:06:46 curt