From 6916ee2a4cbe6640c59a938174957dbd879207e6 Mon Sep 17 00:00:00 2001 From: nathan Date: Sun, 1 Mar 2020 22:40:11 -0800 Subject: [PATCH] map loading fixes Former-commit-id: 77666b1c9b0f871cbf7ebedf29f0b966bb95279b Former-commit-id: 5f1efcc29dc6236555166dd318fff26361161bc6 --- .gitignore | 3 + draw.c | 46 +-- map_conversion/getmap.sh => getmap.sh | 0 init.c | 1 - .../mapconverter.py => mapconverter.py | 7 +- mapdata.c | 273 +++++++----------- run_view1090.sh | 2 + view1090.REMOVED.git-id | 2 +- view1090.c | 6 - 9 files changed, 124 insertions(+), 216 deletions(-) rename map_conversion/getmap.sh => getmap.sh (100%) mode change 100644 => 100755 rename map_conversion/mapconverter.py => mapconverter.py (67%) create mode 100755 run_view1090.sh diff --git a/.gitignore b/.gitignore index 94e612e..c595430 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ *.o +*.bin +*.svg + view1090 *.swp diff --git a/draw.c b/draw.c index e5a9da0..3e7849f 100644 --- a/draw.c +++ b/draw.c @@ -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); 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 // @@ -488,45 +481,10 @@ void drawPolys(QuadTree *tree, float screen_lat_min, float screen_lat_max, float // int right = x; // rectangleRGBA(appData.renderer, left, top, right, bottom, red.r, red.g, red.b, 255); - - Polygon *currentPolygon = tree->polygons; 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; if(currentPolygon->points == NULL) @@ -588,10 +546,8 @@ void drawPolys(QuadTree *tree, float screen_lat_min, float screen_lat_max, float // int bottom = y; // int right = x; - - + // rectangleRGBA(appData.renderer, left, top, right, bottom, purple.r, purple.g, purple.b, 255); - currentPolygon = currentPolygon->next; } diff --git a/map_conversion/getmap.sh b/getmap.sh old mode 100644 new mode 100755 similarity index 100% rename from map_conversion/getmap.sh rename to getmap.sh diff --git a/init.c b/init.c index bb78170..6d5f0a5 100644 --- a/init.c +++ b/init.c @@ -69,7 +69,6 @@ void init(char *title) { appData.labelFontHeight = 12 * appData.screen_uiscale; initMaps(); - } void cleanup() { diff --git a/map_conversion/mapconverter.py b/mapconverter.py similarity index 67% rename from map_conversion/mapconverter.py rename to mapconverter.py index 6206046..58df127 100644 --- a/map_conversion/mapconverter.py +++ b/mapconverter.py @@ -17,8 +17,11 @@ bin_file = open("mapdata.bin", "wt") outlist = [] for p in polys: - currentPoints = p.attrib['points'] - outlist.extend((currentPoints.replace(","," ") + " 0 0").split()) + currentPoints = (p.attrib['points']).replace(","," ").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) bin_file.close() \ No newline at end of file diff --git a/mapdata.c b/mapdata.c index da5b722..8ddc70c 100644 --- a/mapdata.c +++ b/mapdata.c @@ -1,150 +1,140 @@ #include "dump1090.h" #include "mapdata.h" - #include -//sourced from http://www.mccurley.org/svg/ -// -//extern float mapPoints[3878131]; +void initQuadTree(QuadTree *tree) { + if(tree == NULL) { + 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) { // printf("Inserting %d point poly\n", polygon->numPoints); - if (!(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; - } + if (!(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; + } - if (tree->nw == NULL) { - tree->nw = (QuadTree*)malloc(sizeof(QuadTree)); - tree->nw->polygons = NULL; - tree->nw->nw = NULL; - tree->nw->ne = NULL; - tree->nw->sw = NULL; - tree->nw->se = NULL; + if (tree->nw == NULL) { + tree->nw = (QuadTree*)malloc(sizeof(QuadTree)); + initQuadTree(tree->nw); - tree->nw->lat_min = 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_max = tree->lon_min + 0.5 * (tree->lon_max - tree->lon_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->lon_min = tree->lon_min; + tree->nw->lon_max = tree->lon_min + 0.5 * (tree->lon_max - tree->lon_min); + } - if (QTInsert(tree->nw,polygon)){ - return true; - } + if (QTInsert(tree->nw,polygon)){ + return true; + } - if (tree->sw == NULL) { - tree->sw = (QuadTree*)malloc(sizeof(QuadTree)); - tree->sw->polygons = NULL; - tree->sw->nw = NULL; - tree->sw->ne = NULL; - tree->sw->sw = NULL; - tree->sw->se = NULL; + if (tree->sw == NULL) { + tree->sw = (QuadTree*)malloc(sizeof(QuadTree)); + initQuadTree(tree->sw); - tree->sw->lat_min = 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_max = tree->lon_max; - } + tree->sw->lat_min = 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_max = tree->lon_max; + } if (QTInsert(tree->sw,polygon)){ - return true; - } + return true; + } - if (tree->ne == NULL) { - tree->ne = (QuadTree*)malloc(sizeof(QuadTree)); - tree->ne->polygons = NULL; - tree->ne->nw = NULL; - tree->ne->ne = NULL; - tree->ne->sw = NULL; - tree->ne->se = NULL; + if (tree->ne == NULL) { + tree->ne = (QuadTree*)malloc(sizeof(QuadTree)); + initQuadTree(tree->ne); - tree->ne->lat_min = tree->lat_min + 0.5 * (tree->lat_max - tree->lat_min); - tree->ne->lat_max = tree->lat_max; - tree->ne->lon_min = tree->lon_min; - tree->ne->lon_max = tree->lon_min + 0.5 * (tree->lon_max - tree->lon_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->lon_min = 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 (QTInsert(tree->ne,polygon)){ + 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; + 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; - } + 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; + if (QTInsert(tree->se,polygon)){ + return true; } - polygon->next = tree->polygons; - tree->polygons = polygon; - // printf("insert done\n"); - return true; + polygon->next = tree->polygons; + tree->polygons = polygon; + + return true; } void initMaps() { - mapPoints_count = sizeof(mapPoints) / sizeof(float); - - FILE *fileptr; - fileptr = fopen("mapdata.bin", "rb"); // Open the file in binary mode - fseek(fileptr, 0, SEEK_END); // Jump to the end of the file - mapPoints_count = ftell(fileptr) / sizeof(float); // Get the current byte offset in the file + if(!(fileptr = fopen("mapdata.bin", "rb"))) { + printf("Couldn't read mapdata.bin\nDid you run getmap.sh?\n"); + 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 - fread(mapPoints, sizeof(float), mapPoints_count, fileptr); // Read in the entire file - fclose(fileptr); // Close the fileptr + mapPoints = (float *)malloc(mapPoints_count * sizeof(float)); + if(!fread(mapPoints, sizeof(float), mapPoints_count, fileptr)){ + printf("Read error\n"); + exit(0); + } + + fclose(fileptr); 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)); - // mapPoints_x = (double *) malloc(sizeof(mapPoints) / 2); - // mapPoints_y = (double *) malloc(sizeof(mapPoints) / 2); - - // 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; + root.nw = NULL; + root.ne = NULL; + root.sw = NULL; + root.se = NULL; for(int i = 0; i < mapPoints_count; i+=2) { 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; - currentPolygon->lon_min = 180.0; - currentPolygon->lat_max = -180.0; - currentPolygon->lon_max = -180.0; + for(int i = 0; i < mapPoints_count; i+=2) { - currentPolygon->numPoints = 0; + if(mapPoints[i] == 0) { + QTInsert(&root, currentPolygon); + currentPolygon = (Polygon*)malloc(sizeof(Polygon)); + initPolygon(currentPolygon); + continue; + } - currentPolygon->points = NULL; - 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++; + currentPolygon->numPoints++; Point *currentPoint = (Point*)malloc(sizeof(Point)); @@ -216,24 +187,4 @@ void initMaps() { currentPoint->next = currentPolygon->points; 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; -// } -// } -// } -// } \ No newline at end of file diff --git a/run_view1090.sh b/run_view1090.sh new file mode 100755 index 0000000..47cff53 --- /dev/null +++ b/run_view1090.sh @@ -0,0 +1,2 @@ +#!/bin/bash +./view1090 --screensize 640 480 --fullscreen --server adsb --lat 47.6 --lon -122.3 diff --git a/view1090.REMOVED.git-id b/view1090.REMOVED.git-id index de1d1bd..0b83c3e 100644 --- a/view1090.REMOVED.git-id +++ b/view1090.REMOVED.git-id @@ -1 +1 @@ -9ff39d15cbd3fab99fcdbff1a18051b256c66b1a \ No newline at end of file +26bcc33e9a70c2cecf2a74f5154818e228a3b303 \ No newline at end of file diff --git a/view1090.c b/view1090.c index bfd0762..b29bc99 100644 --- a/view1090.c +++ b/view1090.c @@ -161,12 +161,6 @@ int setupConnection(struct client *c) { c->service = Modes.bis = fd; Modes.clients = c; - - // replace with gps - Modes.fUserLat = 47.6611754; - Modes.fUserLon = -122.3562983; - appData.centerLon = Modes.fUserLon; - appData.centerLat = Modes.fUserLat; } return fd; }