#---------------------------------------------------------------------------
+$max_area = 10000; # maximum triangle area
+
$| = 1; # flush buffers after every write
-$do_demfit = 1;
+$do_dem2node = 1;
$do_triangle_1 = 1;
$do_fixnode = 1;
$do_splittris = 1;
$do_tri2obj = 1;
$do_strips = 1;
$do_fixobj = 1;
+
+$do_install = 1;
-# return the file name root (ending at last ".")
-sub file_root {
- my($file) = @_;
- my($pos);
-
- $pos = rindex($file, ".");
- return substr($file, 0, $pos);
+if ( $#ARGV < 3 ) {
+ die "Usage: $0 <fg-root-dir> <work-dir> <error^2> dem-file(s)\n";
}
+# Start with file.dem
+
+$fg_root = shift(@ARGV);
+$work_dir = shift(@ARGV);
+$error = shift(@ARGV);
+$error += 0.0;
+
+while ( $dem_file = shift(@ARGV) ) {
+ print "Source file = $dem_file Error tolerance = $error\n";
-# set the FG_ROOT environment variable if it hasn't already been set.
-if ( $ENV{FG_ROOT} eq "" ) {
- # look for a file called fgtop as a place marker
- if ( -e "fgtop" ) {
- $ENV{FG_ROOT} = ".";
- } elsif ( -e "../fgtop" ) {
- $ENV{FG_ROOT} = "..";
+ if ( $error < 0.5 ) {
+ die "I doubt you'll be happy with an error tolerance as " .
+ "low as $error.\n";
}
+
+
+ if ( $do_dem2node ) {
+ dem2node() ;
+ } else {
+ $subdir = "./work/Scenery/w100n040/w093n045/";
+ print "WARNING: Hardcoding subdir = $subdir\n";
+ }
+
+ triangle_1() if ( $do_triangle_1 );
+ fixnode() if ( $do_fixnode );
+ splittris() if ( $do_splittris );
+ assemtris() if ( $do_assemtris );
+ triangle_2() if ( $do_triangle_2);
+ tri2obj() if ( $do_tri2obj );
+ strips() if ( $do_strips );
+ fixobj() if ( $do_fixobj );
+ install() if ( $do_install );
}
-# 1. Start with file.dem
+# exit normally
+exit(0);
-$dem_file = shift(@ARGV);
-$error = shift(@ARGV);
-$error += 0.0;
-print "Source file = $dem_file Error tolerance = $error\n";
+# fix command to work with windoze, replaces first "/" with "\\"
+sub fix_command {
+ my($in) = @_;
-if ( $error < 0.5 ) {
- die "I doubt you'll be happy with an error tolerance as low as $error.\n";
+ $system = `uname -s`;
+ chop($system);
+
+ if ( $system =~ m/CYGWIN32/ ) {
+ $in =~ s/\//\\\\/;
+ }
+
+ return($in);
}
-# 2. dem2node $FG_ROOT dem_file tolerance^2 (meters)
+
+# return the file name root (ending at last ".")
+sub file_root {
+ my($file) = @_;
+ my($pos);
+
+ $pos = rindex($file, ".");
+ return substr($file, 0, $pos);
+}
+
+
+# 1. dem2node work_dir dem_file tolerance^2 (meters)
#
# - dem2node .. dem_file 160000
#
# splits dem file into 64 file.node's which contain the
# irregularly fitted vertices
-if ( $do_demfit ) {
- $command = "./Dem2node/demfit $ENV{FG_ROOT} $dem_file $error";
-
+sub dem2node {
+ $command = "Dem2node/dem2node $work_dir $dem_file $error";
+ $command = fix_command($command);
print "Running '$command'\n";
open(OUT, "$command |");
}
}
close(OUT);
-} else {
- $subdir = "../Scenery/w100n040/w093n045";
- print "WARNING: Hardcoding subdir = $subdir\n";
-}
+}
+
-# 3. triangle -q file (Takes file.node and produces file.1.node and
+# 2. triangle -q file (Takes file.node and produces file.1.node and
# file.1.ele)
print "Subdirectory for this dem file is $subdir\n";
-if ( $do_triangle_1 ) {
+sub triangle_1 {
@FILES = `ls $subdir`;
foreach $file ( @FILES ) {
print $file;
chop($file);
if ( ($file =~ m/\.node$/) && ($file !~ m/\.\d\.node$/) ) {
- $command = "./Triangle/triangle -q $subdir/$file";
+ $command = "Triangle/triangle -a$max_area -q $subdir/$file";
+ $command = fix_command($command);
print "Running '$command'\n";
open(OUT, "$command |");
while ( <OUT> ) {
}
}
-# 4. fixnode file.dem subdir
+
+# 3. fixnode file.dem subdir
#
# Take the original .dem file (for interpolating Z values) and the
# subdirecotry containing all the file.1.node's and replace with
# fixed file.1.node
-if ( $do_fixnode ) {
- $command = "./FixNode/fixnode $dem_file $subdir";
+sub fixnode {
+ $command = "FixNode/fixnode $dem_file $subdir";
+ $command = fix_command($command);
print "Running '$command'\n";
open(OUT, "$command |");
while ( <OUT> ) {
# gets to define the edge verticies and normals. All the other
# adjacent tiles must use these.
-if ( $do_splittris ) {
+sub splittris {
@FILES = `ls $subdir`;
foreach $file ( @FILES ) {
chop($file);
if ( $file =~ m/\.1\.node$/ ) {
$file =~ s/\.node$//; # strip off the ".node"
- $command = "./SplitTris/splittris $subdir/$file";
+ $command = "SplitTris/splittris $subdir/$file";
+ $command = fix_command($command);
print "Running '$command'\n";
open(OUT, "$command |");
while ( <OUT> ) {
# using the proper shared corners and edges. Save as a node file
# so we can retriangulate.
-if ( $do_assemtris ) {
+sub assemtris {
@FILES = `ls $subdir`;
foreach $file ( @FILES ) {
chop($file);
if ( $file =~ m/\.1\.body$/ ) {
$file =~ s/\.body$//; # strip off the ".body"
- $command = "./AssemTris/assemtris $subdir/$file";
+ $command = "AssemTris/assemtris $subdir/$file";
+ $command = fix_command($command);
print "Running '$command'\n";
open(OUT, "$command |");
while ( <OUT> ) {
# 4.3 Retriangulate reassembled files (without -q option) so no new
# nodes are generated.
-if ( $do_triangle_2 ) {
+sub triangle_2 {
@FILES = `ls $subdir`;
foreach $file ( @FILES ) {
print $file;
chop($file);
if ( ($file =~ m/\.node$/) && ($file !~ m/\.\d\.node$/) ) {
- $command = "./Triangle/triangle $subdir/$file";
+ $base = $file;
+ $base =~ s/\.node$//;
+ print("Test for $subdir/$base.q\n");
+ if ( -r "$subdir/$base.q" ) {
+
+ # if triangle hangs, we can create a filebase.q for
+ # the file it hung on. Then, we test for that file
+ # here which causes the incremental algorithm to run
+ # (which shouldn't ever hang.)
+
+ $command = "Triangle/triangle -i $subdir/$file";
+ } else {
+ $command = "Triangle/triangle $subdir/$file";
+ }
+ $command = fix_command($command);
print "Running '$command'\n";
open(OUT, "$command |");
while ( <OUT> ) {
# the gaps between tiles eliminated, but the colors and lighting
# transition smoothly across tile boundaries.
-if ( $do_tri2obj ) {
+sub tri2obj {
@FILES = `ls $subdir`;
foreach $file ( @FILES ) {
chop($file);
if ( $file =~ m/\.1\.node$/ ) {
$file =~ s/\.node$//; # strip off the ".node"
- $command = "./Tri2obj/tri2obj $subdir/$file";
+ $command = "Tri2obj/tri2obj $subdir/$file";
+ $command = fix_command($command);
print "Running '$command'\n";
open(OUT, "$command |");
while ( <OUT> ) {
#
# strips produces a file called "bands.d" ... copy this to file.2.obj
-if ( $do_strips ) {
+sub strips {
@FILES = `ls $subdir`;
foreach $file ( @FILES ) {
chop($file);
if ( $file =~ m/\.1\.obj$/ ) {
- $command = "./Stripe_u/strips $subdir/$file";
+ $command = "Stripe_w/strips $subdir/$file";
+ $command = fix_command($command);
print "Running '$command'\n";
+ # $input = <STDIN>;
open(OUT, "$command |");
while ( <OUT> ) {
print $_;
$newfile = $file;
$newfile =~ s/\.1\.obj$//;
print "Copying to $subdir/$newfile.2.obj\n";
- open(IN, "<bands.d");
+ # open(IN, "<bands.d");
+ open(IN, "<stripe.objf");
open(OUT, ">$subdir/$newfile.2.obj");
while ( <IN> ) {
print OUT $_;
#
# Sort file.2.obj by strip winding
-if ( $do_fixobj ) {
+sub fixobj {
@FILES = `ls $subdir`;
foreach $file ( @FILES ) {
chop($file);
$newfile = $file;
$newfile =~ s/\.2\.obj$/.obj/;
- $command = "./FixObj/fixobj $subdir/$file $subdir/$newfile";
+ $command = "FixObj/fixobj $subdir/$file $subdir/$newfile";
+ $command = fix_command($command);
+ print "Running '$command'\n";
+ open(OUT, "$command |");
+ while ( <OUT> ) {
+ print $_;
+ }
+ close(OUT);
+
+ unlink("$subdir/$file");
+ }
+ }
+}
+
+
+# 9. install
+#
+# rename, compress, and install scenery files
+
+sub install {
+ $tmp = $subdir;
+ $tmp =~ s/$work_dir//;
+ # print "Temp dir = $tmp\n";
+ $install_dir = "$fg_root/$tmp";
+ print "Install dir = $install_dir\n";
+ system("mkdir -p $install_dir");
+
+ @FILES = `ls $subdir`;
+ foreach $file ( @FILES ) {
+ chop($file);
+ if ( $file =~ m/\d\d.obj$/ ) {
+ $new_file = file_root($file);
+
+ $command = "gzip -v --best < $subdir/$file > $install_dir/$new_file.gz";
+ # $command = fix_command($command);
print "Running '$command'\n";
open(OUT, "$command |");
while ( <OUT> ) {
#---------------------------------------------------------------------------
# $Log$
+# Revision 1.22 1998/07/08 14:49:13 curt
+# tweaks.
+#
+# Revision 1.21 1998/06/08 17:18:37 curt
+# Mods to test new Stripe fixes from Wilbur Streett.
+#
+# Revision 1.20 1998/06/05 18:20:24 curt
+# Added DemInfo to dump out "A" record DEM info.
+# Modified process-dem.pl to work in a temp directory and compress/copy the
+# result to the final destination.
+#
+# Revision 1.19 1998/05/27 02:25:26 curt
+# Added a flag to the first run of "triangle" to impose a maximum triangle
+# size. This forces really flat areas to be subdivided a certain amount
+# anyways. This makes for slightly more interesting scenery.
+#
+# Revision 1.18 1998/05/20 20:55:40 curt
+# Makefile tweaks
+#
+# Revision 1.17 1998/04/28 01:23:25 curt
+# Added a work around so that we can get past the "triangle" program
+# hanging, by aborting and rerunning with that tile marked to use the "-i"
+# option.
+#
+# Revision 1.16 1998/04/18 03:57:53 curt
+# Added zlib library support.
+#
+# Revision 1.15 1998/04/08 23:24:07 curt
+# Adopted Gnu automake/autoconf system.
+#
+# Revision 1.14 1998/04/06 21:09:38 curt
+# Additional win32 support.
+# Fixed a bad bug in dem file parsing that was causing the output to be
+# flipped about x = y.
+#
+# Revision 1.13 1998/03/19 02:52:52 curt
+# Updated to reflect some minor tool reorganization and the creation of class
+# to handle DEM processing needs.
+#
+# Revision 1.12 1998/03/19 01:48:35 curt
+# Added gpc-2.01 (generic polygon clipping library)
+#
+# Revision 1.11 1998/03/03 03:36:57 curt
+# Cumulative tweaks.
+#
+# Revision 1.10 1998/02/01 03:42:26 curt
+# Modifications to handle compressed dem files.
+#
# Revision 1.9 1998/01/27 18:36:54 curt
# Lots of updates to get back in sync with changes made over in .../Src/
#