map loading fixes
Former-commit-id: 77666b1c9b0f871cbf7ebedf29f0b966bb95279b Former-commit-id: 5f1efcc29dc6236555166dd318fff26361161bc6
This commit is contained in:
parent
7c2fdbc634
commit
6916ee2a4c
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,4 +1,7 @@
|
|||
*.o
|
||||
*.bin
|
||||
*.svg
|
||||
|
||||
view1090
|
||||
|
||||
*.swp
|
||||
|
|
44
draw.c
44
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
|
||||
//
|
||||
|
@ -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);
|
||||
|
||||
|
||||
|
||||
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)
|
||||
|
@ -589,10 +547,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
0
map_conversion/getmap.sh → getmap.sh
Normal file → Executable file
1
init.c
1
init.c
|
@ -69,7 +69,6 @@ void init(char *title) {
|
|||
appData.labelFontHeight = 12 * appData.screen_uiscale;
|
||||
|
||||
initMaps();
|
||||
|
||||
}
|
||||
|
||||
void cleanup() {
|
||||
|
|
|
@ -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()
|
145
mapdata.c
145
mapdata.c
|
@ -1,11 +1,32 @@
|
|||
#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);
|
||||
|
@ -21,11 +42,7 @@ bool QTInsert(QuadTree *tree, Polygon* polygon) {
|
|||
|
||||
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;
|
||||
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);
|
||||
|
@ -39,11 +56,7 @@ bool QTInsert(QuadTree *tree, Polygon* polygon) {
|
|||
|
||||
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;
|
||||
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);
|
||||
|
@ -57,11 +70,7 @@ bool QTInsert(QuadTree *tree, Polygon* polygon) {
|
|||
|
||||
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;
|
||||
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;
|
||||
|
@ -75,11 +84,7 @@ bool QTInsert(QuadTree *tree, Polygon* polygon) {
|
|||
|
||||
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;
|
||||
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;
|
||||
|
@ -93,48 +98,33 @@ bool QTInsert(QuadTree *tree, Polygon* polygon) {
|
|||
|
||||
polygon->next = tree->polygons;
|
||||
tree->polygons = polygon;
|
||||
// printf("insert done\n");
|
||||
|
||||
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);
|
||||
|
||||
|
||||
//mapPoints_relative = (float *) malloc(sizeof(mapPoints));
|
||||
|
||||
// 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++;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// load quad tree
|
||||
|
||||
root.lat_min = 180;
|
||||
root.lon_min = 180;
|
||||
|
@ -164,33 +154,14 @@ void initMaps() {
|
|||
}
|
||||
|
||||
Polygon *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;
|
||||
initPolygon(currentPolygon);
|
||||
|
||||
for(int i = 0; i < mapPoints_count; i+=2) {
|
||||
|
||||
if(mapPoints[i] == 0) { //end of polygon
|
||||
if(currentPolygon->numPoints != 7)
|
||||
if(mapPoints[i] == 0) {
|
||||
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;
|
||||
initPolygon(currentPolygon);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -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
2
run_view1090.sh
Executable file
|
@ -0,0 +1,2 @@
|
|||
#!/bin/bash
|
||||
./view1090 --screensize 640 480 --fullscreen --server adsb --lat 47.6 --lon -122.3
|
|
@ -1 +1 @@
|
|||
9ff39d15cbd3fab99fcdbff1a18051b256c66b1a
|
||||
26bcc33e9a70c2cecf2a74f5154818e228a3b303
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue