From 07e284098013425baf1455e24c8cb2c1bdb5596e Mon Sep 17 00:00:00 2001
From: curt <curt>
Date: Sat, 6 May 2000 19:55:30 +0000
Subject: [PATCH] Clip all land use data to GSHHS land mask so that lower res
 data won't mess up our coast lines. Changed some default names of Work
 directories ... Add in support for GSHHS lakes, islands, and ponds. Updated
 stats for parallel scenery build server.

---
 src/BuildTiles/Clipper/clipper.cxx      | 26 +++++++++++++-----
 src/BuildTiles/Main/main.cxx            | 36 ++++++++++++++++++-------
 src/BuildTiles/Parallel/Makefile.am     |  2 +-
 src/BuildTiles/Parallel/server.cxx      |  7 ++++-
 src/BuildTiles/Triangulate/triangle.cxx |  1 -
 5 files changed, 54 insertions(+), 18 deletions(-)

diff --git a/src/BuildTiles/Clipper/clipper.cxx b/src/BuildTiles/Clipper/clipper.cxx
index cbd1ea03..5bfb72af 100644
--- a/src/BuildTiles/Clipper/clipper.cxx
+++ b/src/BuildTiles/Clipper/clipper.cxx
@@ -33,6 +33,9 @@
 #include "clipper.hxx"
 
 
+#define MASK_CLIP 1
+
+
 // Constructor
 FGClipper::FGClipper( void ) {
 }
@@ -291,6 +294,17 @@ bool FGClipper::clip_all(const point2d& min, const point2d& max) {
     polys_in.safety_base.add_node( 0, Point3D(max.x, max.y, 0.0) );
     polys_in.safety_base.add_node( 0, Point3D(min.x, max.y, 0.0) );
 
+    // set up land mask, we clip most things to this since it is our
+    // best representation of land vs. ocean.  If we have other less
+    // accurate data that spills out into the ocean, we want to just
+    // clip it.
+    FGPolygon mask;
+    mask.erase();
+    for ( int i = 0; i < (int)polys_in.polys[DefaultArea].size(); ++i ) {
+	result_union = polygon_union( mask, polys_in.polys[DefaultArea][i] );
+	mask = result_union;
+    }
+
     // int count = 0;
     // process polygons in priority order
     for ( int i = 0; i < FG_MAX_AREA_TYPES; ++i ) {
@@ -304,12 +318,12 @@ bool FGClipper::clip_all(const point2d& min, const point2d& max) {
 	    FG_LOG( FG_CLIPPER, FG_DEBUG, get_area_name( (AreaType)i ) 
 		    << " = " << current.contours() );
 
-#ifdef EXTRA_SAFETY_CLIP
-	    // clip to base tile
-	    tmp = polygon_int( current, polys_in.safety_base );
-#else
-	    tmp = current;
-#endif
+	    if ( i > HoleArea ) {
+		// clip to land mask
+		tmp = polygon_int( current, mask );
+	    } else {
+		tmp = current;
+	    }
 
 	    // clip current polygon against previous higher priority
 	    // stuff
diff --git a/src/BuildTiles/Main/main.cxx b/src/BuildTiles/Main/main.cxx
index 183b602d..dc33be92 100644
--- a/src/BuildTiles/Main/main.cxx
+++ b/src/BuildTiles/Main/main.cxx
@@ -104,19 +104,37 @@ int load_polys( FGConstruct& c ) {
     count += actual_load_polys( poly_path, c, clipper );
     cout << "  loaded " << count << " total polys" << endl;
 
-    // load hydro
+    // load GSHHS land masses
+    poly_path = c.get_work_base() + "/GSHHS-LandMass/" + base;
+    cout << "poly_path = " << poly_path << endl;
+    count += actual_load_polys( poly_path, c, clipper );
+    cout << "  loaded " << count << " total polys" << endl;
+
+    // load GSHHS lakes
+    poly_path = c.get_work_base() + "/GSHHS-Lakes/" + base;
+    cout << "poly_path = " << poly_path << endl;
+    count += actual_load_polys( poly_path, c, clipper );
+    cout << "  loaded " << count << " total polys" << endl;
+
+    // load GSHHS islands
+    poly_path = c.get_work_base() + "/GSHHS-Islands/" + base;
+    cout << "poly_path = " << poly_path << endl;
+    count += actual_load_polys( poly_path, c, clipper );
+    cout << "  loaded " << count << " total polys" << endl;
+
+    // load GSHHS ponds
+    poly_path = c.get_work_base() + "/GSHHS-Ponds/" + base;
+    cout << "poly_path = " << poly_path << endl;
+    count += actual_load_polys( poly_path, c, clipper );
+    cout << "  loaded " << count << " total polys" << endl;
+
+    // load USA hydro data
     poly_path = c.get_work_base() + "/USA-Hydro/" + base;
     cout << "poly_path = " << poly_path << endl;
     count += actual_load_polys( poly_path, c, clipper );
     cout << "  loaded " << count << " total polys" << endl;
 
-    // load land masses
-    poly_path = c.get_work_base() + "/Global-LandMass/" + base;
-    cout << "poly_path = " << poly_path << endl;
-    count += actual_load_polys( poly_path, c, clipper );
-    cout << "  loaded " << count << " total polys" << endl;
-
-    // load urban areas
+     // load USA urban areas
     poly_path = c.get_work_base() + "/USA-Urban/" + base;
     cout << "poly_path = " << poly_path << endl;
     count += actual_load_polys( poly_path, c, clipper );
@@ -692,7 +710,7 @@ int main(int argc, char **argv) {
     cout << "result of setting mem limit = " << result << endl;
 
     // cpu time limit since occassionally the triangulator can go into
-    // and infinite loop.
+    // an infinite loop.
     limit.rlim_cur = 120;
     limit.rlim_max = 120;
     result = setrlimit( RLIMIT_CPU, &limit );
diff --git a/src/BuildTiles/Parallel/Makefile.am b/src/BuildTiles/Parallel/Makefile.am
index 00798be1..825ae543 100644
--- a/src/BuildTiles/Parallel/Makefile.am
+++ b/src/BuildTiles/Parallel/Makefile.am
@@ -1,4 +1,4 @@
-EXTRA_DIST fgfs-launch-clients fgfs-launch-server genworklist.sh
+EXTRA_DIST=fgfs-launch-clients fgfs-launch-server genworklist.sh
 
 bin_PROGRAMS = fgfs-tools-server fgfs-tools-client
 
diff --git a/src/BuildTiles/Parallel/server.cxx b/src/BuildTiles/Parallel/server.cxx
index cad079e5..6f138e30 100644
--- a/src/BuildTiles/Parallel/server.cxx
+++ b/src/BuildTiles/Parallel/server.cxx
@@ -220,7 +220,12 @@ long int get_next_tile() {
 	seconds = tmp_time;
 	cout << "Current tile per second rate = " << counter << endl;
 	cout << "Overall tile per second rate = "
-	     <<  global_counter / ( seconds - start_seconds ) << endl;	    
+	     << (double)global_counter / (double)(seconds - start_seconds)
+	     << endl;
+	cout << "Overall tile per hour rate = "
+	     <<  (double)global_counter * 3600.0 / 
+	           (double)(seconds - start_seconds)
+	     << endl;
 	counter = 0;
     }
 
diff --git a/src/BuildTiles/Triangulate/triangle.cxx b/src/BuildTiles/Triangulate/triangle.cxx
index bd6cf566..b071929b 100644
--- a/src/BuildTiles/Triangulate/triangle.cxx
+++ b/src/BuildTiles/Triangulate/triangle.cxx
@@ -526,4 +526,3 @@ int FGTriangle::run_triangulate( const string& angle, const int pass ) {
     return 0;
 }
 
-