From 1fa96c4d579d5e462661fa44987060b78cbd3433 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 22 Sep 2017 20:56:59 +0100 Subject: [PATCH] 3.07 LIDAR edge cases --- CHANGELOG | 3 +++ inputs.cc | 75 +++++++++++++++++++++++++++++++++++++++++++++++-------- main.cc | 6 ++--- tiles.cc | 2 +- 4 files changed, 72 insertions(+), 14 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index bee5b60..1ae3d1f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,8 @@ SIGNAL SERVER CHANGELOG +3.07 - 2 Sep 2017 +Bugfixes for LIDAR edge cases with mismatched tiles, missing tiles etc. + 3.06 - 23 June 2017 Cropping edge cases with > 100km and LOS diff --git a/inputs.cc b/inputs.cc index aece4ac..0f19cd4 100644 --- a/inputs.cc +++ b/inputs.cc @@ -128,7 +128,7 @@ int loadClutter(char *filename, double radius, struct site tx) int loadLIDAR(char *filenames, int resample) { char *filename; - char *files[256]; // 20x20=400, 16x16=256 tiles + char *files[900]; // 20x20=400, 16x16=256 tiles int indx = 0, fc = 0, hoffset = 0, voffset = 0, pos, success; double xll, yll, xur, yur, cellsize, avgCellsize = 0, smCellsize = 0; char found, free_page = 0, jline[20], lid_file[255], @@ -148,7 +148,7 @@ int loadLIDAR(char *filenames, int resample) } /* Allocate the tile array */ - if( (tiles = (tile_t*) calloc(fc, sizeof(tile_t))) == NULL ) + if( (tiles = (tile_t*) calloc(fc+1, sizeof(tile_t))) == NULL ) return ENOMEM; /* Load each tile in turn */ @@ -233,6 +233,8 @@ int loadLIDAR(char *filenames, int resample) fprintf(stderr, "Warning: Unable to rescale to requested resolution\n"); for (size_t i = 0; i< fc; i++) { float rescale = tiles[i].resolution / (float)desired_resolution; + if(debug) + fprintf(stderr,"res %.2f desired_res %.2f\n",tiles[i].resolution,(float)desired_resolution); if (rescale != 1){ if( (success = tile_rescale(&tiles[i], rescale) != 0 ) ){ fprintf(stderr, "Error resampling tiles\n"); @@ -246,11 +248,28 @@ int loadLIDAR(char *filenames, int resample) double total_width = max_west - min_west >= 0 ? max_west - min_west : max_west + (360 - min_west); double total_height = max_north - min_north; if (debug) { - fprintf(stderr,"totalw: %.7f - %.7f = %.7f\n", max_west, min_west, total_width); + fprintf(stderr,"totalh: %.7f - %.7f = %.7f totalw: %.7f - %.7f = %.7f\n", max_north, min_north, total_height, max_west, min_west, total_width); fprintf(stderr,"mw:%lf Mnw:%lf\n", max_west, min_west); } + //detect problematic layouts eg. vertical rectangles + //create a synthetic empty tile on the fly with dimensions to make a square + /*if(total_height > total_width*1.5){ + tiles[fc].max_north=max_north; + tiles[fc].min_north=min_north; + westoffset=westoffset-total_width; // WGS84 for stdout only + max_west=max_west+total_width; // Positive westing + tiles[fc].max_west=max_west; // Positive westing + tiles[fc].min_west=max_west; + tiles[fc].ppdy=tiles[fc-1].ppdy; + tiles[fc].ppdy=tiles[fc-1].ppdx; + tiles[fc].width=tiles[fc-1].width; + tiles[fc].height=total_height; + tiles[fc].data=tiles[fc-1].data; + fc++; + }*/ + /* This is how we should _theoretically_ work this out, but due to - * the nature of floating point arithmetic and rounding errors, we need to + * the nature of floating point arithmetic and rounding errors, 499 usd to gbpwe need to * crunch the numbers the hard way */ // size_t new_width = total_width * pix_per_deg; // size_t new_height = total_height * pix_per_deg; @@ -267,7 +286,10 @@ int loadLIDAR(char *filenames, int resample) new_width = west_pixel_offset + tiles[i].width; if ( north_pixel_offset + tiles[i].height > new_height ) new_height = north_pixel_offset + tiles[i].height; + if (debug) + fprintf(stderr,"north_pixel_offset %d west_pixel_offset %d\n", north_pixel_offset, west_pixel_offset); } + size_t new_tile_alloc = new_width * new_height; short * new_tile = (short*) calloc( new_tile_alloc, sizeof(short) ); @@ -279,14 +301,22 @@ int loadLIDAR(char *filenames, int resample) fprintf(stderr,"Lidar tile dimensions w:%lf(%zu) h:%lf(%zu)\n", total_width, new_width, total_height, new_height); /* ...If we wanted a value other than sea level here, we would need to initialize the array... */ - + size_t prevPixelOffsetW=0; + size_t prevPixelOffsetN=0; /* Fill out the array one tile at a time */ for (size_t i = 0; i< fc; i++) { double north_offset = max_north - tiles[i].max_north; double west_offset = max_west - tiles[i].max_west >= 0 ? max_west - tiles[i].max_west : max_west + (360 - tiles[i].max_west); size_t north_pixel_offset = north_offset * tiles[i].ppdy; - size_t west_pixel_offset = west_offset * tiles[i].ppdx; - + size_t west_pixel_offset = west_offset * tiles[i].ppdx; + /*if(i>0){ + if(tiles[i].ppdx>tiles[i-1].ppdx+10 || tiles[i].ppdxtiles[i-1].ppdy+10 || tiles[i].ppdy 255) val[y] = 255; @@ -1269,7 +1307,8 @@ int LoadLossColors(struct site xmtr) region.levels = 16; - if ( xmtr.filename[0] == '\0' && (fd = fopen(filename, "r")) == NULL ) + if ( (fd = fopen(filename, "r")) == NULL && xmtr.filename[0] == '\0' ) + //if ( xmtr.filename[0] == '\0' && (fd = fopen(filename, "r")) == NULL ) /* Don't save if we don't have an output file */ return 0; @@ -1283,6 +1322,12 @@ int LoadLossColors(struct site xmtr) region.color[x][2]); fclose(fd); + + if (debug) { + fprintf(stderr, "loadLossColors: fopen fail: %s\n", filename); + fflush(stderr); + } + } else { @@ -1299,6 +1344,11 @@ int LoadLossColors(struct site xmtr) &val[2], &val[3]); if (ok == 4) { + if (debug) { + fprintf(stderr, "\nLoadLossColors() %d: %d, %d, %d\n", val[0],val[1],val[2],val[3]); + fflush(stderr); + } + for (y = 0; y < 4; y++) { if (val[y] > 255) val[y] = 255; @@ -1453,6 +1503,11 @@ int LoadDBMColors(struct site xmtr) &val[2], &val[3]); if (ok == 4) { + if (debug) { + fprintf(stderr, "\nLoadDBMColors() %d: %d, %d, %d\n", val[0],val[1],val[2],val[3]); + fflush(stderr); + } + if (val[0] < -200) val[0] = -200; diff --git a/main.cc b/main.cc index 325d9cc..6e2be69 100644 --- a/main.cc +++ b/main.cc @@ -1,4 +1,4 @@ -double version = 3.06; +double version = 3.07; /****************************************************************************\ * Signal Server: Radio propagation simulator by Alex Farrant QCVS, 2E0TDW * ****************************************************************************** @@ -1047,7 +1047,7 @@ int main(int argc, char *argv[]) unsigned char LRmap = 0, txsites = 0, topomap = 0, geo = 0, kml = 0, area_mode = 0, max_txsites, ngs = 0; - char mapfile[255], ano_filename[255], lidar_tiles[16384], clutter_file[255]; + char mapfile[255], ano_filename[255], lidar_tiles[27000], clutter_file[255]; char *az_filename, *el_filename, *udt_file = NULL; double altitude = 0.0, altitudeLR = 0.0, tx_range = 0.0, @@ -1287,7 +1287,7 @@ int main(int argc, char *argv[]) z = x + 1; lidar=1; if (z <= y && argv[z][0] && argv[z][0] != '-') - strncpy(lidar_tiles, argv[z], 16382); + strncpy(lidar_tiles, argv[z], 27000); // 900 tiles! } if (strcmp(argv[x], "-res") == 0) { diff --git a/tiles.cc b/tiles.cc index ccbaf07..d946a18 100644 --- a/tiles.cc +++ b/tiles.cc @@ -101,7 +101,7 @@ int tile_load_lidar(tile_t *tile, char *filename){ for (size_t w = 0; w < tile->width && pch != NULL; w++) { /* If the data is less than a *magic* minimum, normalize it to zero */ nextval = atoi(pch); - if (nextval <= -9999) + if (nextval <= 0) nextval = 0; tile->data[h*tile->width + w] = nextval; loaded++;