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
*.bin
*.svg
view1090
*.swp

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

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;
initMaps();
}
void cleanup() {

View file

@ -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()

273
mapdata.c
View file

@ -1,150 +1,140 @@
#include "dump1090.h"
#include "mapdata.h"
#include <stdbool.h>
//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;
// }
// }
// }
// }

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