map loading fixes

Former-commit-id: 77666b1c9b0f871cbf7ebedf29f0b966bb95279b
Former-commit-id: 5f1efcc29dc6236555166dd318fff26361161bc6
This commit is contained in:
nathan 2020-03-01 22:40:11 -08:00
parent 7c2fdbc634
commit 6916ee2a4c
9 changed files with 124 additions and 216 deletions

3
.gitignore vendored
View file

@ -1,4 +1,7 @@
*.o *.o
*.bin
*.svg
view1090 view1090
*.swp *.swp

44
draw.c
View file

@ -463,13 +463,6 @@ void drawPolys(QuadTree *tree, float screen_lat_min, float screen_lat_max, float
drawPolys(tree->se, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max); drawPolys(tree->se, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max);
float dx, dy; float dx, dy;
// if(!(tree->lat_min > screen_lat_min &&
// tree->lat_max < screen_lat_max &&
// tree->lon_min > screen_lon_min &&
// tree->lon_max < screen_lon_max)){
// //printf("%f %f\n", tree->lat_min, screen_lat_min);
// return;
// }
//Draw quadtree bounds //Draw quadtree bounds
// //
@ -489,44 +482,9 @@ void drawPolys(QuadTree *tree, float screen_lat_min, float screen_lat_max, float
// rectangleRGBA(appData.renderer, left, top, right, bottom, red.r, red.g, red.b, 255); // rectangleRGBA(appData.renderer, left, top, right, bottom, red.r, red.g, red.b, 255);
Polygon *currentPolygon = tree->polygons; Polygon *currentPolygon = tree->polygons;
while(currentPolygon != NULL) { while(currentPolygon != NULL) {
////polygon mode
// Sint16 *px = (Sint16*)malloc(sizeof(Sint16*)*currentPolygon->numPoints);
// Sint16 *py = (Sint16*)malloc(sizeof(Sint16*)*currentPolygon->numPoints);
// Point *currentPoint = currentPolygon->points;
// int i = 0;
// while(currentPoint != NULL){
// pxFromLonLat(&dx, &dy, currentPoint->lon, currentPoint->lat);
// screenCoords(&x, &y, dx, dy);
// px[i] = x;
// py[i] = y;
// i++;
// for(int k = 0; k < skip; k++) {
// currentPoint = currentPoint->next;
// if(currentPoint == NULL)
// break;
// }
// }
// float alpha = 1.0;
// //filledPolygonRGBA (appData.renderer, px, py, i, 0, 0, 0, 255);
// polygonRGBA (appData.renderer, px, py, i, alpha * purple.r + (1.0-alpha) * blue.r, alpha * purple.g + (1.0-alpha) * blue.g, alpha * purple.b + (1.0-alpha) * blue.b, 255 * alpha);
//// line version
int x1,y1,x2,y2; int x1,y1,x2,y2;
if(currentPolygon->points == NULL) if(currentPolygon->points == NULL)
@ -589,10 +547,8 @@ void drawPolys(QuadTree *tree, float screen_lat_min, float screen_lat_max, float
// int bottom = y; // int bottom = y;
// int right = x; // int right = x;
// rectangleRGBA(appData.renderer, left, top, right, bottom, purple.r, purple.g, purple.b, 255); // rectangleRGBA(appData.renderer, left, top, right, bottom, purple.r, purple.g, purple.b, 255);
currentPolygon = currentPolygon->next; currentPolygon = currentPolygon->next;
} }
} }

0
map_conversion/getmap.sh → getmap.sh Normal file → Executable file
View file

1
init.c
View file

@ -69,7 +69,6 @@ void init(char *title) {
appData.labelFontHeight = 12 * appData.screen_uiscale; appData.labelFontHeight = 12 * appData.screen_uiscale;
initMaps(); initMaps();
} }
void cleanup() { void cleanup() {

View file

@ -17,8 +17,11 @@ bin_file = open("mapdata.bin", "wt")
outlist = [] outlist = []
for p in polys: for p in polys:
currentPoints = p.attrib['points'] currentPoints = (p.attrib['points']).replace(","," ").split()
outlist.extend((currentPoints.replace(","," ") + " 0 0").split())
if(len(currentPoints) > 12): #remove little circles in the McCurley maps
outlist.extend(currentPoints)
outlist.extend(["0","0"])
np.asarray(outlist).astype(np.single).tofile(bin_file) np.asarray(outlist).astype(np.single).tofile(bin_file)
bin_file.close() bin_file.close()

275
mapdata.c
View file

@ -1,150 +1,140 @@
#include "dump1090.h" #include "dump1090.h"
#include "mapdata.h" #include "mapdata.h"
#include <stdbool.h> #include <stdbool.h>
//sourced from http://www.mccurley.org/svg/ void initQuadTree(QuadTree *tree) {
// if(tree == NULL) {
//extern float mapPoints[3878131]; return;
}
tree->polygons = NULL;
tree->nw = NULL;
tree->ne = NULL;
tree->sw = NULL;
tree->se = NULL;
}
void initPolygon(Polygon *currentPolygon) {
if(currentPolygon == NULL) {
return;
}
currentPolygon->lat_min = 180.0;
currentPolygon->lon_min = 180.0;
currentPolygon->lat_max = -180.0;
currentPolygon->lon_max = -180.0;
currentPolygon->numPoints = 0;
currentPolygon->points = NULL;
currentPolygon->next = NULL;
}
bool QTInsert(QuadTree *tree, Polygon* polygon) { bool QTInsert(QuadTree *tree, Polygon* polygon) {
// printf("Inserting %d point poly\n", polygon->numPoints); // printf("Inserting %d point poly\n", polygon->numPoints);
if (!(polygon->lat_min >= tree->lat_min && if (!(polygon->lat_min >= tree->lat_min &&
polygon->lat_max <= tree->lat_max && polygon->lat_max <= tree->lat_max &&
polygon->lon_min >= tree->lon_min && polygon->lon_min >= tree->lon_min &&
polygon->lon_max <= tree->lon_max)) { polygon->lon_max <= tree->lon_max)) {
// printf("doesnt fit: %f > %f, %f < %f, %f < %f,%f > %f \n",polygon->lat_min, tree->lat_min, polygon->lat_max, tree->lat_max, polygon->lon_min, tree->lon_min, polygon->lon_max,tree->lon_max); // printf("doesnt fit: %f > %f, %f < %f, %f < %f,%f > %f \n",polygon->lat_min, tree->lat_min, polygon->lat_max, tree->lat_max, polygon->lon_min, tree->lon_min, polygon->lon_max,tree->lon_max);
return false; return false;
} }
if (tree->nw == NULL) { if (tree->nw == NULL) {
tree->nw = (QuadTree*)malloc(sizeof(QuadTree)); tree->nw = (QuadTree*)malloc(sizeof(QuadTree));
tree->nw->polygons = NULL; initQuadTree(tree->nw);
tree->nw->nw = NULL;
tree->nw->ne = NULL;
tree->nw->sw = NULL;
tree->nw->se = NULL;
tree->nw->lat_min = tree->lat_min; tree->nw->lat_min = tree->lat_min;
tree->nw->lat_max = tree->lat_min + 0.5 * (tree->lat_max - tree->lat_min); tree->nw->lat_max = tree->lat_min + 0.5 * (tree->lat_max - tree->lat_min);
tree->nw->lon_min = tree->lon_min; tree->nw->lon_min = tree->lon_min;
tree->nw->lon_max = tree->lon_min + 0.5 * (tree->lon_max - tree->lon_min); tree->nw->lon_max = tree->lon_min + 0.5 * (tree->lon_max - tree->lon_min);
} }
if (QTInsert(tree->nw,polygon)){ if (QTInsert(tree->nw,polygon)){
return true; return true;
} }
if (tree->sw == NULL) { if (tree->sw == NULL) {
tree->sw = (QuadTree*)malloc(sizeof(QuadTree)); tree->sw = (QuadTree*)malloc(sizeof(QuadTree));
tree->sw->polygons = NULL; initQuadTree(tree->sw);
tree->sw->nw = NULL;
tree->sw->ne = NULL;
tree->sw->sw = NULL;
tree->sw->se = NULL;
tree->sw->lat_min = tree->lat_min; tree->sw->lat_min = tree->lat_min;
tree->sw->lat_max = tree->lat_min + 0.5 * (tree->lat_max - tree->lat_min); tree->sw->lat_max = tree->lat_min + 0.5 * (tree->lat_max - tree->lat_min);
tree->sw->lon_min = tree->lon_min + 0.5 * (tree->lon_max - tree->lon_min); tree->sw->lon_min = tree->lon_min + 0.5 * (tree->lon_max - tree->lon_min);
tree->sw->lon_max = tree->lon_max; tree->sw->lon_max = tree->lon_max;
} }
if (QTInsert(tree->sw,polygon)){ if (QTInsert(tree->sw,polygon)){
return true; return true;
} }
if (tree->ne == NULL) { if (tree->ne == NULL) {
tree->ne = (QuadTree*)malloc(sizeof(QuadTree)); tree->ne = (QuadTree*)malloc(sizeof(QuadTree));
tree->ne->polygons = NULL; initQuadTree(tree->ne);
tree->ne->nw = NULL;
tree->ne->ne = NULL;
tree->ne->sw = NULL;
tree->ne->se = NULL;
tree->ne->lat_min = tree->lat_min + 0.5 * (tree->lat_max - tree->lat_min); tree->ne->lat_min = tree->lat_min + 0.5 * (tree->lat_max - tree->lat_min);
tree->ne->lat_max = tree->lat_max; tree->ne->lat_max = tree->lat_max;
tree->ne->lon_min = tree->lon_min; tree->ne->lon_min = tree->lon_min;
tree->ne->lon_max = tree->lon_min + 0.5 * (tree->lon_max - tree->lon_min); tree->ne->lon_max = tree->lon_min + 0.5 * (tree->lon_max - tree->lon_min);
}
if (QTInsert(tree->ne,polygon)){
return true;
}
if (tree->se == NULL) {
tree->se = (QuadTree*)malloc(sizeof(QuadTree));
initQuadTree(tree->se);
tree->se->lat_min = tree->lat_min + 0.5 * (tree->lat_max - tree->lat_min);
tree->se->lat_max = tree->lat_max;
tree->se->lon_min = tree->lon_min + 0.5 * (tree->lon_max - tree->lon_min);
tree->se->lon_max = tree->lon_max;
} }
if (QTInsert(tree->ne,polygon)){ if (QTInsert(tree->se,polygon)){
return true; return true;
}
if (tree->se == NULL) {
tree->se = (QuadTree*)malloc(sizeof(QuadTree));
tree->se->polygons = NULL;
tree->se->nw = NULL;
tree->se->ne = NULL;
tree->se->sw = NULL;
tree->se->se = NULL;
tree->se->lat_min = tree->lat_min + 0.5 * (tree->lat_max - tree->lat_min);
tree->se->lat_max = tree->lat_max;
tree->se->lon_min = tree->lon_min + 0.5 * (tree->lon_max - tree->lon_min);
tree->se->lon_max = tree->lon_max;
}
if (QTInsert(tree->se,polygon)){
return true;
} }
polygon->next = tree->polygons; polygon->next = tree->polygons;
tree->polygons = polygon; tree->polygons = polygon;
// printf("insert done\n");
return true; return true;
} }
void initMaps() { void initMaps() {
mapPoints_count = sizeof(mapPoints) / sizeof(float);
FILE *fileptr; FILE *fileptr;
fileptr = fopen("mapdata.bin", "rb"); // Open the file in binary mode if(!(fileptr = fopen("mapdata.bin", "rb"))) {
fseek(fileptr, 0, SEEK_END); // Jump to the end of the file printf("Couldn't read mapdata.bin\nDid you run getmap.sh?\n");
mapPoints_count = ftell(fileptr) / sizeof(float); // Get the current byte offset in the file exit(0);
}
rewind(fileptr); // Jump back to the beginning of the file fseek(fileptr, 0, SEEK_END);
mapPoints_count = ftell(fileptr) / sizeof(float);
rewind(fileptr);
mapPoints = (float *)malloc(mapPoints_count * sizeof(float)); // Enough memory for the file mapPoints = (float *)malloc(mapPoints_count * sizeof(float));
fread(mapPoints, sizeof(float), mapPoints_count, fileptr); // Read in the entire file if(!fread(mapPoints, sizeof(float), mapPoints_count, fileptr)){
fclose(fileptr); // Close the fileptr printf("Read error\n");
exit(0);
}
fclose(fileptr);
printf("Read %d map points.\n",mapPoints_count); printf("Read %d map points.\n",mapPoints_count);
// load quad tree
//mapPoints_relative = (float *) malloc(sizeof(mapPoints)); root.lat_min = 180;
root.lon_min = 180;
root.lat_max = -180;
root.lon_max = -180;
// mapPoints_count = sizeof(mapPoints) / (2 * sizeof(double)); root.nw = NULL;
// mapPoints_x = (double *) malloc(sizeof(mapPoints) / 2); root.ne = NULL;
// mapPoints_y = (double *) malloc(sizeof(mapPoints) / 2); root.sw = NULL;
root.se = NULL;
// int current = 0;
// for(int i = 0; i < 2 * mapPoints_count; i++) {
// if(mapPoints[i] != 0) {
// if(i%2 == 0) { //longitude points
// double dLon = mapPoints[i] - Modes.fUserLon;
// mapPoints_x[current] = 6371.0 * dLon * M_PI / 180.0 * cos(((mapPoints[i+1] + Modes.fUserLat)/2.0) * M_PI / 180.0);
// } else { //latitude points
// double dLat = mapPoints[i] - Modes.fUserLat;
// mapPoints_y[current] = 6371.0 * dLat * M_PI / 180.0f;
// current++;
// }
// }
// }
root.lat_min = 180;
root.lon_min = 180;
root.lat_max = -180;
root.lon_max = -180;
root.nw = NULL;
root.ne = NULL;
root.sw = NULL;
root.se = NULL;
for(int i = 0; i < mapPoints_count; i+=2) { for(int i = 0; i < mapPoints_count; i+=2) {
if(mapPoints[i] == 0) if(mapPoints[i] == 0)
@ -163,38 +153,19 @@ void initMaps() {
} }
} }
Polygon *currentPolygon = (Polygon*)malloc(sizeof(Polygon)); Polygon *currentPolygon = (Polygon*)malloc(sizeof(Polygon));
initPolygon(currentPolygon);
currentPolygon->lat_min = 180.0; for(int i = 0; i < mapPoints_count; i+=2) {
currentPolygon->lon_min = 180.0;
currentPolygon->lat_max = -180.0;
currentPolygon->lon_max = -180.0;
currentPolygon->numPoints = 0; if(mapPoints[i] == 0) {
QTInsert(&root, currentPolygon);
currentPolygon = (Polygon*)malloc(sizeof(Polygon));
initPolygon(currentPolygon);
continue;
}
currentPolygon->points = NULL; currentPolygon->numPoints++;
currentPolygon->next = NULL;
for(int i = 0; i < mapPoints_count; i+=2) {
if(mapPoints[i] == 0) { //end of polygon
if(currentPolygon->numPoints != 7)
QTInsert(&root, currentPolygon);
currentPolygon = (Polygon*)malloc(sizeof(Polygon));
currentPolygon->lat_min = 180.0;
currentPolygon->lon_min = 180.0;
currentPolygon->lat_max = -180.0;
currentPolygon->lon_max = -180.0;
currentPolygon->numPoints = 0;
currentPolygon->points = NULL;
currentPolygon->next = NULL;
continue;
}
currentPolygon->numPoints++;
Point *currentPoint = (Point*)malloc(sizeof(Point)); Point *currentPoint = (Point*)malloc(sizeof(Point));
@ -216,24 +187,4 @@ void initMaps() {
currentPoint->next = currentPolygon->points; currentPoint->next = currentPolygon->points;
currentPolygon->points = currentPoint; currentPolygon->points = currentPoint;
} }
} }
// void recenter() {
// for(int i = 0; i < mapPoints_count; i++) {
// if(mapPoints[i] == 0) {
// mapPoints_relative[i] = 0;
// } else {
// if(i%2 == 0) { //longitude points
// double dLon = mapPoints[i] - Modes.fUserLon;
// mapPoints_relative[i] = 6371.0 * dLon * M_PI / 180.0 * cos(((mapPoints[i+1] + Modes.fUserLat)/2.0) * M_PI / 180.0);
// } else { //latitude points
// double dLat = mapPoints[i] - Modes.fUserLat;
// mapPoints_relative[i] = 6371.0 * dLat * M_PI / 180.0f;
// }
// }
// }
// }

2
run_view1090.sh Executable file
View file

@ -0,0 +1,2 @@
#!/bin/bash
./view1090 --screensize 640 480 --fullscreen --server adsb --lat 47.6 --lon -122.3

View file

@ -1 +1 @@
9ff39d15cbd3fab99fcdbff1a18051b256c66b1a 26bcc33e9a70c2cecf2a74f5154818e228a3b303

View file

@ -161,12 +161,6 @@ int setupConnection(struct client *c) {
c->service = c->service =
Modes.bis = fd; Modes.bis = fd;
Modes.clients = c; Modes.clients = c;
// replace with gps
Modes.fUserLat = 47.6611754;
Modes.fUserLon = -122.3562983;
appData.centerLon = Modes.fUserLon;
appData.centerLat = Modes.fUserLat;
} }
return fd; return fd;
} }