1
0
Fork 0

In the process of trying to track down bugs in the construct process I

redid slightly how the land cover squares are calculated.
This commit is contained in:
curt 2000-11-20 16:43:30 +00:00
parent 97a83fb03c
commit f90cffd10d

View file

@ -174,99 +174,92 @@ static int actual_load_polys( const string& dir,
// Merge a polygon with an existing one if possible, append a new // Merge a polygon with an existing one if possible, append a new
// one otherwise; this function is used by actual_load_landcover, below, // one otherwise; this function is used by actual_load_landcover, below,
// to reduce the number of separate polygons. // to reduce the number of separate polygons.
static void inline add_to_polys (vector<FGPolygon> &list, static void inline add_to_polys ( FGPolygon &accum, const FGPolygon &poly) {
const FGPolygon &poly) if ( accum.contours() > 0 ) {
{ accum = polygon_union( accum, poly );
int len = list.size(); } else {
FGPolygon temp; accum = poly;
// Look for an adjacent polygon
if (len > 0) {
for (int i = 0; i < len; i++) {
temp = polygon_union(list[i], poly);
if (temp.contours() == 1) { // no new contours: they are adjacent
cout << "Merging with existing land-cover polygon" << endl;
list[i] = temp;
return;
}
} }
}
// No adjacent polygons available; append
// this one to the list.
cout << "Adding new land-cover polygon" << endl;
list.push_back(poly);
} }
// Generate polygons from land-cover raster. Horizontally- or vertically- // Generate polygons from land-cover raster. Horizontally- or
// adjacent polygons will be merged automatically. // vertically- adjacent polygons will be merged automatically.
static int actual_load_landcover ( LandCover &cover, FGConstruct & c, static int actual_load_landcover ( LandCover &cover, FGConstruct & c,
FGClipper &clipper ) { FGClipper &clipper ) {
int count = 0; int count = 0;
double lon, lat; FGPolygon polys[FG_MAX_AREA_TYPES];
vector<FGPolygon> poly_list[FG_MAX_AREA_TYPES];
FGPolygon poly; // working polygon FGPolygon poly; // working polygon
// Get the top corner of the tile // Get the top corner of the tile
lon = double base_lon = c.get_bucket().get_center_lon() -
c.get_bucket().get_center_lon() - (0.5 * c.get_bucket().get_width()); (0.5 * c.get_bucket().get_width());
lat = double base_lat = c.get_bucket().get_center_lat() -
c.get_bucket().get_center_lat() - (0.5 * c.get_bucket().get_height()); (0.5 * c.get_bucket().get_height());
cout << "DPM: tile at " << lon << ',' << lat << endl; cout << "DPM: tile at " << base_lon << ',' << base_lat << endl;
double max_lon = c.get_bucket().get_center_lon() +
(0.5 * c.get_bucket().get_width());
double max_lat = c.get_bucket().get_center_lat() +
(0.5 * c.get_bucket().get_height());
// Figure out how many units wide and double dx = 1.0 / 120.0;
// high this tile is; each unit is double dy = dx;
// 30 arc seconds.
int x_span = int(120 * bucket_span(lat)); // arcsecs of longitude // Figure out how many units wide and high this tile is; each unit
int y_span = int(120 * FG_BUCKET_SPAN); // arcsecs of latitude // is 30 arc seconds.
for (int x = 0; x < x_span; x++) { // int x_span = int(120 * bucket_span(base_lat)); // arcsecs of longitude
for (int y = 0; y < y_span; y++) { // int y_span = int(120 * FG_BUCKET_SPAN); // arcsecs of latitude
// Figure out the boundaries of the
// 30 arcsec square. double x1 = base_lon;
double x1 = lon + (x * (1.0/120.0)); double y1 = base_lat;
double y1 = lat + (y * (1.0/120.0)); double x2 = x1 + dx;
double x2 = x1 + (1.0/120.0); double y2 = y1 + dy;
double y2 = y1 + (1.0/120.0);
// Look up the land cover for the square while ( x1 < max_lon ) {
int cover_value = cover.getValue(x1 + (1.0/240.0), y1 + (1.0/240.0)); while ( y1 < max_lat ) {
cout << " position: " << x1 << ',' << y1 << ',' // Look up the land cover for the square
<< cover.getDescUSGS(cover_value) << endl; int cover_value = cover.getValue(x1 + (1.0/240.0),
AreaType area = translateUSGSCover(cover_value); y1 + (1.0/240.0));
if (area != DefaultArea) { cout << " position: " << x1 << ',' << y1 << ','
// Create a square polygon and merge << cover.getDescUSGS(cover_value) << endl;
// it into the list. AreaType area = translateUSGSCover(cover_value);
poly.erase(); if (area != DefaultArea) {
poly.add_node(0, Point3D(x1, y1, 0.0)); // Create a square polygon and merge it into the list.
poly.add_node(0, Point3D(x1, y2, 0.0)); poly.erase();
poly.add_node(0, Point3D(x2, y2, 0.0)); poly.add_node(0, Point3D(x1, y1, 0.0));
poly.add_node(0, Point3D(x2, y1, 0.0)); poly.add_node(0, Point3D(x1, y2, 0.0));
add_to_polys(poly_list[area], poly); poly.add_node(0, Point3D(x2, y2, 0.0));
poly.add_node(0, Point3D(x2, y1, 0.0));
add_to_polys(polys[area], poly);
}
y1 = y2;
y2 += dy;
} }
} x1 = x2;
x2 += dx;
y1 = base_lat;
y2 = y1 + dy;
} }
// Now that we're finished looking up // Now that we're finished looking up land cover, we have a list
// land cover, we have a list of lists // of lists of polygons, one (possibly-empty) list for each area
// of polygons, one (possibly-empty) // type. Add the remaining polygons to the clipper.
// list for each area type. Add the for ( int i = 0; i < FG_MAX_AREA_TYPES; i++ ) {
// remaining polygons to the clipper. if ( polys[i].contours() ) {
for (int i = 0; i < FG_MAX_AREA_TYPES; i++) { clipper.add_poly( i, polys[i] );
int len = poly_list[i].size(); count++;
for (int j = 0; j < len; j++) { }
clipper.add_poly(i, poly_list[i][j]);
count++;
}
} }
// Return the number of polygons // Return the number of polygons actually read.
// actually read.
return count; return count;
} }
// load all 2d polygons matching the specified base path and clip // load all 2d polygons matching the specified base path and clip
// against each other to resolve any overlaps // against each other to resolve any overlaps
static int load_polys( FGConstruct& c ) { static int load_polys( FGConstruct& c ) {
@ -280,20 +273,18 @@ static int load_polys( FGConstruct& c ) {
clipper.init(); clipper.init();
// load 2D polygons from all directories provided // load 2D polygons from all directories provided
for (int i = 0; i < load_dirs.size(); i++) { for ( int i = 0; i < (int)load_dirs.size(); ++i ) {
poly_path = load_dirs[i] + '/' + base; poly_path = load_dirs[i] + '/' + base;
cout << "poly_path = " << poly_path << endl; cout << "poly_path = " << poly_path << endl;
count += actual_load_polys( poly_path, c, clipper ); count += actual_load_polys( poly_path, c, clipper );
cout << " loaded " << count << " total polys" << endl; cout << " loaded " << count << " total polys" << endl;
} }
#if 0
// Load the land use polygons // Load the land use polygons
string glc = c.get_work_base(); string glc = c.get_work_base();
glc += "/LC-Global/gusgs2_0ll.img"; glc += "/LC-Global/gusgs2_0ll.img";
LandCover cover( glc ); LandCover cover( glc );
count += actual_load_landcover ( cover, c, clipper ); count += actual_load_landcover ( cover, c, clipper );
#endif
point2d min, max; point2d min, max;
min.x = c.get_bucket().get_center_lon() - 0.5 * c.get_bucket().get_width(); min.x = c.get_bucket().get_center_lon() - 0.5 * c.get_bucket().get_width();
@ -318,7 +309,7 @@ static int load_dem( FGConstruct& c, FGArray& array) {
point_list result; point_list result;
string base = c.get_bucket().gen_base_path(); string base = c.get_bucket().gen_base_path();
for (int i = 0; i < load_dirs.size(); i++) { for ( int i = 0; i < (int)load_dirs.size(); ++i ) {
string dem_path = load_dirs[i] + "/" + base string dem_path = load_dirs[i] + "/" + base
+ "/" + c.get_bucket().gen_index_str() + ".dem"; + "/" + c.get_bucket().gen_index_str() + ".dem";
cout << "dem_path = " << dem_path << endl; cout << "dem_path = " << dem_path << endl;
@ -643,7 +634,7 @@ static void do_output( FGConstruct& c, FGGenOutput& output ) {
static void do_custom_objects( const FGConstruct& c ) { static void do_custom_objects( const FGConstruct& c ) {
FGBucket b = c.get_bucket(); FGBucket b = c.get_bucket();
for (int i = 0; i < load_dirs.size(); i++) { for ( int i = 0; i < (int)load_dirs.size(); ++i ) {
string base_dir = load_dirs[i] + "/" + b.gen_base_path(); string base_dir = load_dirs[i] + "/" + b.gen_base_path();
string index_file = base_dir + "/" + b.gen_index_str() + ".ind"; string index_file = base_dir + "/" + b.gen_index_str() + ".ind";
cout << "collecting custom objects from " << index_file << endl; cout << "collecting custom objects from " << index_file << endl;