Change data to short to restrain memory usage

This commit is contained in:
Gareth Evans
2017-06-14 20:33:32 +01:00
parent cb2939b244
commit 02bd67f11b
4 changed files with 15 additions and 15 deletions

View File

@@ -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) );
}
}

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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;