forked from ExternalVendorCode/Signal-Server
Move tile loading into tiles.cc
This commit is contained in:
162
inputs.cc
162
inputs.cc
@@ -231,92 +231,6 @@ int loadClutter(char *filename, double radius, struct site tx)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void readLIDAR(FILE *fd, int h, int w, int indx,double n, double e, double s, double west)
|
||||
{
|
||||
int x = 0, y = 0, reads = 0, a=0, b=0, avg=0, tWidth = 0, tHeight = 0;
|
||||
char line[25000];
|
||||
char *pch;
|
||||
|
||||
dem[indx].max_north=n;
|
||||
dem[indx].min_west=e;
|
||||
dem[indx].min_north=s;
|
||||
dem[indx].max_west=west;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
for (y = h-1; y > -1; y--) {
|
||||
x = w-1;
|
||||
|
||||
if (fgets(line, 25000, fd) != NULL) {
|
||||
pch = strtok(line, " "); // split line into values
|
||||
|
||||
while (pch != NULL && x > -1) {
|
||||
if (atoi(pch) <= -9999)
|
||||
pch = "0";
|
||||
dem[indx].data[y][x] = atoi(pch);
|
||||
dem[indx].signal[x][y] = 0;
|
||||
dem[indx].mask[x][y] = 0;
|
||||
if (atoi(pch) > dem[indx].max_el) {
|
||||
dem[indx].max_el = atoi(pch);
|
||||
max_elevation = atoi(pch);
|
||||
}
|
||||
if (atoi(pch) < dem[indx].min_el) {
|
||||
dem[indx].min_el = atoi(pch);
|
||||
min_elevation = dem[indx].min_el;
|
||||
}
|
||||
|
||||
x--;
|
||||
pch = strtok(NULL, " ");
|
||||
}//while
|
||||
|
||||
|
||||
} else {
|
||||
fprintf(stderr, "LIDAR error @ x %d y %d indx %d\n",
|
||||
x, y, indx);
|
||||
}//if
|
||||
}//for
|
||||
|
||||
}
|
||||
|
||||
int loadLIDAR(char *filenames)
|
||||
{
|
||||
char *filename;
|
||||
@@ -391,13 +305,75 @@ int loadLIDAR(char *filenames)
|
||||
// reset the IPPD after allocations
|
||||
IPPD -= 50;
|
||||
|
||||
for ( int indx = 0; indx < fc; indx++ ) {
|
||||
if ( (fd = fopen(files[indx],"rb")) == NULL)
|
||||
return errno;
|
||||
fseek(fd, tiles[indx].datastart, SEEK_SET);
|
||||
if (debug)
|
||||
fprintf(stderr, "readLIDAR(fd,%d,%d,%d,%.4f,%.4f,%.4f,%.4f)\n", tiles[indx].height, tiles[indx].width, indx, tiles[indx].yur, tiles[indx].xur, tiles[indx].yll, tiles[indx].xll);
|
||||
readLIDAR(fd, tiles[indx].height, tiles[indx].width, indx, tiles[indx].yur, tiles[indx].xur, tiles[indx].yll, tiles[indx].xll);
|
||||
/* Load the data into the global dem array */
|
||||
for (size_t indx = 0; indx < fc; indx++) {
|
||||
dem[indx].max_north = tiles[indx].yur;
|
||||
dem[indx].min_west = tiles[indx].xur;
|
||||
dem[indx].min_north = tiles[indx].yll;
|
||||
dem[indx].max_west = tiles[indx].xll;
|
||||
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...)
|
||||
*/
|
||||
int y = tiles[indx].height-1;
|
||||
for (size_t h = 0; h < tiles[indx].height; h++, y--) {
|
||||
int x = tiles[indx].width-1;
|
||||
for (size_t w = 0; w < tiles[indx].width; w++, x--) {
|
||||
dem[indx].data[y][x] = tiles[indx].data[h*tiles[indx].width + w];
|
||||
dem[indx].signal[y][x] = 0;
|
||||
dem[indx].mask[y][x] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ippd=IPPD;
|
||||
|
9
tiles.cc
9
tiles.cc
@@ -12,7 +12,6 @@ int tile_load_lidar(tile_t *tile, char *filename){
|
||||
char line[MAX_LINE];
|
||||
int nextval;
|
||||
char *pch;
|
||||
int w, x, y;
|
||||
|
||||
/* Clear the tile data */
|
||||
memset(tile,0x00,sizeof(tile_t));
|
||||
@@ -71,7 +70,6 @@ int tile_load_lidar(tile_t *tile, char *filename){
|
||||
if (debug)
|
||||
fprintf(stderr, "POST yll %.7f yur %.7f xur %.7f xll %.7f delta %.6f\n", tile->yll, tile->yur, tile->xur, tile->xll, delta);
|
||||
|
||||
#ifdef _LOAD_TILEDATA
|
||||
/* Read the actual tile data */
|
||||
/* Allocate the array for the lidar data */
|
||||
if ( (tile->data = (int*) calloc(tile->width * tile->height, sizeof(int))) == NULL ) {
|
||||
@@ -84,7 +82,7 @@ int tile_load_lidar(tile_t *tile, char *filename){
|
||||
for (size_t h = 0; h < tile->height; h++) {
|
||||
if (fgets(line, MAX_LINE, fd) != NULL) {
|
||||
pch = strtok(line, " "); // split line into values
|
||||
for (w = 0; w < tile->width && pch != NULL; w++) {
|
||||
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)
|
||||
@@ -98,13 +96,12 @@ int tile_load_lidar(tile_t *tile, char *filename){
|
||||
pch = strtok(NULL, " ");
|
||||
}//while
|
||||
} else {
|
||||
fprintf(stderr, "LIDAR error @ x %d y %d file %s\n", x, y, filename);
|
||||
fprintf(stderr, "LIDAR error @ h %zu file %s\n", h, filename);
|
||||
}//if
|
||||
}
|
||||
|
||||
if (debug)
|
||||
fprintf(stderr,"Pixels loaded: %zu/%zu\n",loaded,tile->width*tile->height);
|
||||
#endif
|
||||
fprintf(stderr,"Pixels loaded: %zu/%d\n",loaded,tile->width*tile->height);
|
||||
|
||||
/* All done, close the LIDAR file */
|
||||
fclose(fd);
|
||||
|
Reference in New Issue
Block a user