From 02bd67f11bbd2c2d2a77b6f5d888d778bd5e4fb8 Mon Sep 17 00:00:00 2001 From: Gareth Evans Date: Wed, 14 Jun 2017 20:33:32 +0100 Subject: [PATCH] Change data to short to restrain memory usage --- inputs.cc | 10 +++++----- main.cc | 2 +- tiles.cc | 10 +++++----- tiles.hh | 8 ++++---- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/inputs.cc b/inputs.cc index 395f0e5..995e3c4 100644 --- a/inputs.cc +++ b/inputs.cc @@ -228,7 +228,7 @@ int loadLIDAR(char *filenames, int resample) /* Now we need to rescale all tiles the the lowest resolution or the requested resolution. ie if we have * one 1m lidar and one 2m lidar, resize the 2m to fake 1m */ - int desired_resolution = smallest_res < resample ? resample : smallest_res; + int desired_resolution = resample != 0 && smallest_res < resample ? resample : smallest_res; if (desired_resolution > resample && debug ) fprintf(stderr, "Warning: Unable to rescale to requested resolution\n"); for (size_t i = 0; i< fc; i++) { @@ -270,7 +270,7 @@ int loadLIDAR(char *filenames, int resample) } size_t new_tile_alloc = new_width * new_height; - int * new_tile = (int*) calloc( new_tile_alloc, sizeof(int) ); + short * new_tile = (short*) calloc( new_tile_alloc, sizeof(int) ); if ( new_tile == NULL ){ free(tiles); return ENOMEM; @@ -296,8 +296,8 @@ int loadLIDAR(char *filenames, int resample) /* Copy it row-by-row from the tile */ for (size_t h = 0; h < tiles[i].height; h++) { - register int *dest_addr = &new_tile[ (north_pixel_offset+h)*new_width + west_pixel_offset]; - register int *src_addr = &tiles[i].data[h*tiles[i].width]; + register short *dest_addr = &new_tile[ (north_pixel_offset+h)*new_width + west_pixel_offset]; + register short *src_addr = &tiles[i].data[h*tiles[i].width]; // Check if we might overflow if ( dest_addr + tiles[i].width > new_tile + new_tile_alloc || dest_addr < new_tile ){ if (debug) @@ -305,7 +305,7 @@ int loadLIDAR(char *filenames, int resample) continue; } // fprintf(stderr,"dest:%p src:%p\n", dest_addr, src_addr); - memcpy( dest_addr, src_addr, tiles[i].width * sizeof(int) ); + memcpy( dest_addr, src_addr, tiles[i].width * sizeof(short) ); } } diff --git a/main.cc b/main.cc index b0d2549..cc19762 100644 --- a/main.cc +++ b/main.cc @@ -1146,7 +1146,7 @@ int main(int argc, char *argv[]) max_txsites = 30; fzone_clearance = 0.6; contour_threshold = 0; - resample = -1; + resample = 0; ano_filename[0] = 0; earthradius = EARTHRADIUS; diff --git a/tiles.cc b/tiles.cc index c4b47b4..05912af 100644 --- a/tiles.cc +++ b/tiles.cc @@ -26,11 +26,11 @@ double haversine_formula(double th1, double ph1, double th2, double ph2) int tile_load_lidar(tile_t *tile, char *filename){ FILE *fd; char line[MAX_LINE]; - int nextval; + short nextval; char *pch; /* Clear the tile data */ - memset(tile,0x00,sizeof(tile_t)); + memset(tile, 0x00, sizeof(tile_t)); /* Open the file handle and return on error */ if ( (fd = fopen(filename,"r")) == NULL ) @@ -88,7 +88,7 @@ int tile_load_lidar(tile_t *tile, char *filename){ /* Read the actual tile data */ /* Allocate the array for the lidar data */ - if ( (tile->data = (int*) calloc(tile->width * tile->height, sizeof(int))) == NULL ) { + if ( (tile->data = (short*) calloc(tile->width * tile->height, sizeof(short))) == NULL ) { fclose(fd); free(tile->filename); return ENOMEM; @@ -144,7 +144,7 @@ int tile_load_lidar(tile_t *tile, char *filename){ * (ie 2m LIDAR can be 4/6/8/... and 20m can be 40/60) */ int tile_rescale(tile_t *tile, float scale){ - int *new_data; + short *new_data; size_t skip_count = 1; size_t copy_count = 1; @@ -156,7 +156,7 @@ int tile_rescale(tile_t *tile, float scale){ size_t new_width = tile->width * scale; /* Allocate the array for the lidar data */ - if ( (new_data = (int*) calloc(new_height * new_width, sizeof(int))) == NULL ) { + if ( (new_data = (short*) calloc(new_height * new_width, sizeof(short))) == NULL ) { return ENOMEM; } diff --git a/tiles.hh b/tiles.hh index 899ef92..8bb0caf 100644 --- a/tiles.hh +++ b/tiles.hh @@ -29,10 +29,10 @@ typedef struct _tile_t{ }; double cellsize; long long datastart; - int nodata; - int max_el; - int min_el; - int *data; + short nodata; + short max_el; + short min_el; + short *data; int resolution; double width_deg; double height_deg;