From c6873f8dead0d03b606134f6d52549004968a77a Mon Sep 17 00:00:00 2001 From: Gareth Evans Date: Tue, 6 Jun 2017 21:47:05 +0100 Subject: [PATCH] Move tile post processing --- inputs.cc | 89 ++++++++++++++++++++++++++----------------------------- tiles.hh | 20 ++++++++++--- 2 files changed, 58 insertions(+), 51 deletions(-) diff --git a/inputs.cc b/inputs.cc index 1d8652b..1d94c19 100644 --- a/inputs.cc +++ b/inputs.cc @@ -254,7 +254,7 @@ int loadLIDAR(char *filenames) } /* Allocate the tile array */ - tiles = (tile_t*)calloc(fc,sizeof(tile_t)); + tiles = (tile_t*) calloc(fc, sizeof(tile_t)); /* Load each tile in turn */ for (indx = 0; indx < fc; indx++) { @@ -279,6 +279,47 @@ int loadLIDAR(char *filenames) smCellsize = tiles[indx].cellsize; } + // Update a bunch of globals + if (tiles[indx].max_el > max_elevation) + max_elevation = tiles[indx].max_el; + if (tiles[indx].min_el < min_elevation) + min_elevation = tiles[indx].min_el; + + if (max_north == -90 || tiles[indx].max_north > max_north) + max_north = tiles[indx].max_north; + + if (min_north == 90 || tiles[indx].min_north < min_north) + min_north = tiles[indx].min_north; + + if (tiles[indx].max_west > max_west) + max_west = tiles[indx].max_west; + if (tiles[indx].min_west < min_west) + min_west = tiles[indx].min_west; + + if (max_west == -1) { + max_west = tiles[indx].max_west; + } else { + if (abs(tiles[indx].max_west - max_west) < 180) { + if (tiles[indx].max_west > max_west) + max_west = tiles[indx].max_west; + } else { + if (tiles[indx].max_west < max_west) + max_west = tiles[indx].max_west; + } + } + + if (min_west == 360) { + min_west = tiles[indx].min_west; + } else { + if (fabs(tiles[indx].min_west - min_west) < 180.0) { + if (tiles[indx].min_west < min_west) + min_west = tiles[indx].min_west; + } else { + if (tiles[indx].min_west > min_west) + min_west = tiles[indx].min_west; + } + } + } /* Iterate through all tiles to find the largest x/y dimension @@ -314,52 +355,6 @@ int loadLIDAR(char *filenames) dem[indx].max_el = tiles[indx].max_el; dem[indx].min_el = tiles[indx].min_el; - if (tiles[indx].max_el > max_elevation) - max_elevation = tiles[indx].max_el; - if (tiles[indx].min_el < min_elevation) - min_elevation = tiles[indx].min_el; - - if (max_north == -90) - max_north = dem[indx].max_north; - - else if (dem[indx].max_north > max_north) - max_north = dem[indx].max_north; - - if (min_north == 90) - min_north = dem[indx].min_north; - - else if (dem[indx].min_north < min_north) - min_north = dem[indx].min_north; - - if (dem[indx].max_west > max_west) - max_west = dem[indx].max_west; - if (dem[indx].min_west < min_west) - min_west = dem[indx].min_west; - - if (max_west == -1) { - max_west = dem[indx].max_west; - } else { - if (abs(dem[indx].max_west - max_west) < 180) { - if (dem[indx].max_west > max_west) - max_west = dem[indx].max_west; - } else { - if (dem[indx].max_west < max_west) - max_west = dem[indx].max_west; - } - } - - if (min_west == 360) { - min_west = dem[indx].min_west; - } else { - if (fabs(dem[indx].min_west - min_west) < 180.0) { - if (dem[indx].min_west < min_west) - min_west = dem[indx].min_west; - } else { - if (dem[indx].min_west > min_west) - min_west = dem[indx].min_west; - } - } - /* * Copy the lidar tile data into the dem array. The dem array is rotated * 90 degrees (christ knows why...) diff --git a/tiles.hh b/tiles.hh index 2341faa..e76756f 100644 --- a/tiles.hh +++ b/tiles.hh @@ -11,10 +11,22 @@ typedef struct _tile_t{ int rows; int height; }; - double xll; - double yll; - double xur; - double yur; + union{ + double xll; + double max_west; + }; + union{ + double yll; + double min_north; + }; + union{ + double xur; + double min_west; + }; + union{ + double yur; + double max_north; + }; double cellsize; long long datastart; int nodata;