From e08b755290ca7dcb0dd0dd0382c8b8bf45bc10a7 Mon Sep 17 00:00:00 2001 From: curt Date: Wed, 22 Nov 2000 22:19:44 +0000 Subject: [PATCH] Contributions from David Megginson. - increased maximum areas to 128 (for future growth), and added Road and Railroad areas - changed the method of calculating the triangle centre in poly_support.hxx - added a has_holes() method to polygon.hxx - added a new library, e00, for reading ArcInfo e00 files (i.e. the free online ones from DCW and GeoGratis); it needs more work - added a new prep utility, e00lines, for creating textured polygons out of e00 line data (with user-specified width and area type); this is useful for roads, railroads, rivers, and utility lines --- configure.in | 2 ++ src/BuildTiles/Clipper/clipper.cxx | 45 ++++++++++-------------------- src/BuildTiles/Clipper/clipper.hxx | 34 ++++++++++------------ src/BuildTiles/Main/main.cxx | 24 ++++++++-------- src/Lib/Makefile.am | 1 + src/Lib/Polygon/names.cxx | 2 ++ src/Lib/Polygon/names.hxx | 2 ++ src/Lib/Polygon/polygon.cxx | 17 +++++++++++ src/Lib/Polygon/polygon.hxx | 12 ++++++++ src/Lib/TriangleJRS/triangle.c | 3 +- src/Prep/Makefile.am | 1 + src/Prep/MergerClipper/merger.hxx | 2 +- 12 files changed, 80 insertions(+), 65 deletions(-) diff --git a/configure.in b/configure.in index 74deeddb..6af531a3 100644 --- a/configure.in +++ b/configure.in @@ -302,6 +302,7 @@ AC_OUTPUT( \ src/Lib/Makefile \ src/Lib/Array/Makefile \ src/Lib/DEM/Makefile \ + src/Lib/e00/Makefile \ src/Lib/Geometry/Makefile \ src/Lib/landcover/Makefile \ src/Lib/Optimize/Makefile \ @@ -313,6 +314,7 @@ AC_OUTPUT( \ src/Prep/DemChop/Makefile \ src/Prep/DemInfo/Makefile \ src/Prep/DemRaw2ascii/Makefile \ + src/Prep/E00Lines/Makefile \ src/Prep/GenAirports/Makefile \ src/Prep/GSHHS/Makefile \ src/Prep/MergerClipper/Makefile \ diff --git a/src/BuildTiles/Clipper/clipper.cxx b/src/BuildTiles/Clipper/clipper.cxx index 3d198e89..009fe698 100644 --- a/src/BuildTiles/Clipper/clipper.cxx +++ b/src/BuildTiles/Clipper/clipper.cxx @@ -38,21 +38,18 @@ FG_USING_STD(cout); #define MASK_CLIP 1 -// Constructor -FGClipper::FGClipper( void ) { +// Constructor. +FGClipper::FGClipper() { } -// Destructor -FGClipper::~FGClipper( void ) { +// Destructor. +FGClipper::~FGClipper() { } -// Initialize Clipper (allocate and/or connect structures) +// Initialize the clipper (empty all the polygon buckets.) bool FGClipper::init() { - // v_list.num_vertices = 0; - // v_list.vertex = new gpc_vertex[FG_MAX_VERTICES];; - for ( int i = 0; i < FG_MAX_AREA_TYPES; ++i ) { polys_in.polys[i].clear(); } @@ -61,7 +58,7 @@ bool FGClipper::init() { } -// Load a polygon definition file +// Load a polygon definition file. bool FGClipper::load_polys(const string& path) { string poly_name; AreaType poly_type = DefaultArea; @@ -78,9 +75,6 @@ bool FGClipper::load_polys(const string& path) { exit(-1); } - // gpc_polygon *poly = new gpc_polygon; - // poly->num_contours = 0; - // poly->contour = NULL; FGPolygon poly; Point3D p; @@ -133,8 +127,6 @@ bool FGClipper::load_polys(const string& path) { // cout << "poly pt = " << p << endl; poly.add_node( i, p ); } - - // gpc_add_contour( poly, &v_list, hole_flag ); } in >> skipcomment; @@ -142,10 +134,6 @@ bool FGClipper::load_polys(const string& path) { int area = (int)poly_type; - // if ( area == OceanArea ) { - // TEST - Ignore - // } else - add_poly(area, poly); // FILE *ofp= fopen("outfile", "w"); @@ -154,8 +142,8 @@ bool FGClipper::load_polys(const string& path) { return true; } - -void FGClipper::add_poly (int area, const FGPolygon &poly) +// Add a polygon to the clipper. +void FGClipper::add_poly( int area, const FGPolygon &poly ) { if ( area < FG_MAX_AREA_TYPES ) { polys_in.polys[area].push_back(poly); @@ -167,7 +155,7 @@ void FGClipper::add_poly (int area, const FGPolygon &poly) } -// remove any slivers from in polygon and move them to out polygon. +// Move slivers from in polygon to out polygon. void FGClipper::move_slivers( FGPolygon& in, FGPolygon& out ) { // traverse each contour of the polygon and attempt to identify // likely slivers @@ -221,7 +209,9 @@ void FGClipper::move_slivers( FGPolygon& in, FGPolygon& out ) { } -// for each sliver contour, see if a union with another polygon yields +// Attempt to merge slivers into a list of polygons. +// +// For each sliver contour, see if a union with another polygon yields // a polygon with no increased contours (i.e. the sliver is adjacent // and can be merged.) If so, replace the clipped polygon with the // new polygon that has the sliver merged in. @@ -289,7 +279,8 @@ void FGClipper::merge_slivers( FGPolyList& clipped, FGPolygon& slivers ) { } -// Do actually clipping work +// Clip all the polygons against each other in a priority scheme based +// on order of the polygon type in the polygon type enum. bool FGClipper::clip_all(const point2d& min, const point2d& max) { FGPolygon accum, tmp; FGPolygon slivers, remains; @@ -339,7 +330,6 @@ bool FGClipper::clip_all(const point2d& min, const point2d& max) { } #endif - // int count = 0; // process polygons in priority order for ( int i = 0; i < FG_MAX_AREA_TYPES; ++i ) { cout << "num polys of type (" << i << ") = " @@ -377,13 +367,6 @@ bool FGClipper::clip_all(const point2d& min, const point2d& max) { } #endif - // clip current polygon against previous higher priority - // stuff - - // result_diff = new gpc_polygon; - // result_diff->num_contours = 0; - // result_diff->contour = NULL; - FGPolygon result_union, result_diff; if ( accum.contours() == 0 ) { diff --git a/src/BuildTiles/Clipper/clipper.hxx b/src/BuildTiles/Clipper/clipper.hxx index e07d0065..b80909a2 100644 --- a/src/BuildTiles/Clipper/clipper.hxx +++ b/src/BuildTiles/Clipper/clipper.hxx @@ -45,41 +45,35 @@ FG_USING_STD(string); FG_USING_STD(vector); -// typedef vector < gpc_polygon * > gpcpoly_container; -// typedef gpcpoly_container::iterator gpcpoly_iterator; -// typedef gpcpoly_container::const_iterator const_gpcpoly_iterator; - - -#define FG_MAX_AREA_TYPES 40 // FIXME also defined in +#define FG_MAX_AREA_TYPES 128 // FIXME also defined in // MergerClipper/clipper.hxx #define EXTRA_SAFETY_CLIP -// #define FG_MAX_VERTICES 100000 -class FGPolyList { +class FGPolyList +{ public: poly_list polys[FG_MAX_AREA_TYPES]; FGPolygon safety_base; }; -class FGClipper { +class FGClipper +{ private: - // gpc_vertex_list v_list; - // static gpc_polygon poly; FGPolyList polys_in, polys_clipped; public: - // Constructor - FGClipper( void ); + // Constructor. + FGClipper (void); - // Destructor - ~FGClipper( void ); + // Destructor. + ~FGClipper (void); - // Initialize Clipper (allocate and/or connect structures) + // Initialize Clipper (allocate and/or connect structures.) bool init(); // Load a polygon definition file @@ -88,20 +82,20 @@ public: // Add a polygon. void add_poly(int area, const FGPolygon &poly); - // remove any slivers from in polygon and move them to out + // Remove any slivers from in polygon and move them to out // polygon. void move_slivers( FGPolygon& in, FGPolygon& out ); - // for each sliver contour, see if a union with another polygon + // For each sliver contour, see if a union with another polygon // yields a polygon with no increased contours (i.e. the sliver is // adjacent and can be merged.) If so, replace the clipped // polygon with the new polygon that has the sliver merged in. void merge_slivers( FGPolyList& clipped, FGPolygon& slivers ); - // Do actually clipping work + // Do actual clipping work. bool clip_all(const point2d& min, const point2d& max); - // return output poly list + // Return output poly list inline FGPolyList get_polys_clipped() const { return polys_clipped; } }; diff --git a/src/BuildTiles/Main/main.cxx b/src/BuildTiles/Main/main.cxx index 6b990248..93224417 100644 --- a/src/BuildTiles/Main/main.cxx +++ b/src/BuildTiles/Main/main.cxx @@ -64,9 +64,7 @@ FG_USING_STD(vector); vector load_dirs; -/** - * Translate USGS land cover into TerraGear. - */ +// Translate USGS land cover values into TerraGear area types. static AreaType translateUSGSCover (int usgs_value) { switch (usgs_value) { @@ -127,7 +125,7 @@ static AreaType translateUSGSCover (int usgs_value) } -// do actual scan of directory and loading of files +// Scan a directory and load polygon files. static int actual_load_polys( const string& dir, FGConstruct& c, FGClipper& clipper ) { @@ -172,8 +170,10 @@ static int actual_load_polys( const string& dir, } -// Merge a polygon with an existing one if possible, append a new -// one otherwise; this function is used by actual_load_landcover, below, +// Add a polygon to a list, merging if possible. +// +// Merge a polygon with an existing one if possible, append a new one +// otherwise; this function is used by actual_load_landcover, below, // to reduce the number of separate polygons. static void inline add_to_polys ( FGPolygon &accum, const FGPolygon &poly) { if ( accum.contours() > 0 ) { @@ -184,8 +184,8 @@ static void inline add_to_polys ( FGPolygon &accum, const FGPolygon &poly) { } -// Generate polygons from land-cover raster. Horizontally- or -// vertically- adjacent polygons will be merged automatically. +// Generate polygons from la and-cover raster. Horizontally- or +// vertically-adjacent polygons will be merged automatically. static int actual_load_landcover ( LandCover &cover, FGConstruct & c, FGClipper &clipper ) { @@ -261,8 +261,8 @@ static int actual_load_landcover ( LandCover &cover, FGConstruct & c, } -// load all 2d polygons matching the specified base path and clip -// against each other to resolve any overlaps +// load all 2d polygons from the specified load disk directories and +// clip against each other to resolve any overlaps static int load_polys( FGConstruct& c ) { FGClipper clipper; @@ -304,8 +304,8 @@ static int load_polys( FGConstruct& c ) { } -// load regular grid of elevation data (dem based), return list of -// fitted nodes +// Load elevation data from a DEM file, a regular grid of elevation +// data--dem based) and return list of fitted nodes. static int load_dem( FGConstruct& c, FGArray& array) { point_list result; string base = c.get_bucket().gen_base_path(); diff --git a/src/Lib/Makefile.am b/src/Lib/Makefile.am index f953db1a..14793089 100644 --- a/src/Lib/Makefile.am +++ b/src/Lib/Makefile.am @@ -1,6 +1,7 @@ SUBDIRS = \ Array \ DEM \ + e00 \ Geometry \ landcover \ Optimize \ diff --git a/src/Lib/Polygon/names.cxx b/src/Lib/Polygon/names.cxx index ca26da3d..41f8eb97 100644 --- a/src/Lib/Polygon/names.cxx +++ b/src/Lib/Polygon/names.cxx @@ -70,6 +70,8 @@ inline static void init () set_area("Reservoir", ReservoirArea); set_area("Reservoir Intermittent", IntReservoirArea); set_area("IntermittentReservoir", IntReservoirArea); + set_area("Road", RoadArea); + set_area("Railroad", RailroadArea); set_area("Stream", StreamArea); set_area("Canal", CanalArea); set_area("Glacier", GlacierArea); diff --git a/src/Lib/Polygon/names.hxx b/src/Lib/Polygon/names.hxx index c89aafdb..d623fc98 100644 --- a/src/Lib/Polygon/names.hxx +++ b/src/Lib/Polygon/names.hxx @@ -44,6 +44,8 @@ enum AreaType { IntLakeArea, ReservoirArea, IntReservoirArea, + RoadArea, + RailroadArea, StreamArea, CanalArea, GlacierArea, diff --git a/src/Lib/Polygon/polygon.cxx b/src/Lib/Polygon/polygon.cxx index 86a61e22..2a4e7902 100644 --- a/src/Lib/Polygon/polygon.cxx +++ b/src/Lib/Polygon/polygon.cxx @@ -533,3 +533,20 @@ FGPolygon polygon_to_tristrip_old( const FGPolygon& in_poly ) { return result; } #endif + + +// Send a polygon to standard output. +ostream & +operator<< (ostream &output, const FGPolygon &poly) +{ + int nContours = poly.contours(); + output << nContours << endl; + for (int i = 0; i < nContours; i++) { + int nPoints = poly.contour_size(i); + output << nPoints << endl; + output << poly.get_hole_flag(i) << endl; + for (int j = 0; j < nPoints; j++) { + output << poly.get_pt(i, j) << endl; + } + } +} diff --git a/src/Lib/Polygon/polygon.hxx b/src/Lib/Polygon/polygon.hxx index 270d4d1f..81c337ce 100644 --- a/src/Lib/Polygon/polygon.hxx +++ b/src/Lib/Polygon/polygon.hxx @@ -33,9 +33,11 @@ #include #include +#include #include #include +FG_USING_STD(ostream); FG_USING_STD(string); FG_USING_STD(vector); @@ -139,6 +141,13 @@ public: inline void set_hole_flag( const int contour, const int flag ) { hole_list[contour] = flag; } + inline bool has_holes () const { + for (int i = 0; i < contours(); i++) { + if (get_hole_flag(i)) + return true; + } + return false; + } // shift every point in the polygon by lon, lat void shift( double lon, double lat ); @@ -200,6 +209,9 @@ FGPolygon polygon_xor( const FGPolygon& subject, const FGPolygon& clip ); // Union FGPolygon polygon_union( const FGPolygon& subject, const FGPolygon& clip ); +// Output +ostream &operator<< (ostream &output, const FGPolygon &poly); + #endif // _POLYGON_HXX diff --git a/src/Lib/TriangleJRS/triangle.c b/src/Lib/TriangleJRS/triangle.c index a9ca9ad0..5a3a1d64 100644 --- a/src/Lib/TriangleJRS/triangle.c +++ b/src/Lib/TriangleJRS/triangle.c @@ -303,6 +303,7 @@ #define ONETHIRD 0.333333333333333333333333333333333333333333333333333333333333 #include +#include #include #include #ifndef NO_TIMER @@ -2728,7 +2729,7 @@ char **argv; k++; } workstring[k] = '\0'; - minangle = (REAL) strtod(workstring, (char **) NULL); + minangle = (REAL) atof(workstring); } else { minangle = 20.0; } diff --git a/src/Prep/Makefile.am b/src/Prep/Makefile.am index cc420d91..41bfd8e5 100644 --- a/src/Prep/Makefile.am +++ b/src/Prep/Makefile.am @@ -2,6 +2,7 @@ SUBDIRS = \ DemChop \ DemInfo \ DemRaw2ascii \ + E00Lines \ GenAirports \ GSHHS \ MergerClipper \ diff --git a/src/Prep/MergerClipper/merger.hxx b/src/Prep/MergerClipper/merger.hxx index 20e1da47..b86d2b16 100644 --- a/src/Prep/MergerClipper/merger.hxx +++ b/src/Prep/MergerClipper/merger.hxx @@ -43,7 +43,7 @@ FG_USING_STD(string); FG_USING_STD(vector); -#define FG_MAX_AREA_TYPES 40 // FIXME: also defined in clipper.hxx +#define FG_MAX_AREA_TYPES 128 // FIXME: also defined in clipper.hxx class FGPolyList { public: