diff --git a/Map.cpp b/Map.cpp index 4f9e4a7..238f8c3 100644 --- a/Map.cpp +++ b/Map.cpp @@ -4,24 +4,37 @@ bool Map::QTInsert(QuadTree *tree, Line *line, int depth) { + if(depth > 25) { + // printf("fail [%f %f] -> [%f %f]\n",line->start.lon,line->start.lat,line->end.lon,line->end.lat); + + // printf("bounds %f %f %f %f\n",tree->lon_min, tree->lon_max, tree->lat_min, tree->lat_max); + // fflush(stdout); + tree->lines.push_back(&(*line)); + return true; + } + + bool startInside = line->start.lat >= tree->lat_min && line->start.lat <= tree->lat_max && line->start.lon >= tree->lon_min && - line->start.lon <= tree->lon_max; + line->start.lon <= tree->lon_max; bool endInside = line->end.lat >= tree->lat_min && line->end.lat <= tree->lat_max && line->end.lon >= tree->lon_min && - line->end.lon <= tree->lon_max; + line->end.lon <= tree->lon_max; - if (!startInside && !endInside) { + if (!startInside || !endInside) { return false; } + // if (!startInside && !endInside) { + // return false; + // } - if (startInside != endInside) { - tree->lines.push_back(&(*line)); - return true; - } + // if (startInside != endInside) { + // tree->lines.push_back(&(*line)); + // return true; + // } if (tree->nw == NULL) { tree->nw = new QuadTree; @@ -76,6 +89,7 @@ bool Map::QTInsert(QuadTree *tree, Line *line, int depth) { } tree->lines.push_back(&(*line)); + return true; } @@ -178,6 +192,8 @@ Map::Map() { } } + printf("map bounds: %f %f %f %f\n",root.lon_min, root.lon_max, root.lat_min, root.lat_max); + Point currentPoint; Point nextPoint; @@ -196,7 +212,10 @@ Map::Map() { nextPoint.lon = mapPoints[i + 2]; nextPoint.lat = mapPoints[i + 3]; + // printf("inserting [%f %f] -> [%f %f]\n",currentPoint.lon,currentPoint.lat,nextPoint.lon,nextPoint.lat); + QTInsert(&root, new Line(currentPoint, nextPoint), 0); } + printf("done\n"); } diff --git a/View.cpp b/View.cpp index a477a4e..5b04dda 100644 --- a/View.cpp +++ b/View.cpp @@ -667,6 +667,26 @@ void View::drawLinesRecursive(QuadTree *tree, float screen_lat_min, float screen lineRGBA(renderer, x1, y1, x2, y2, style.mapInnerColor.r, style.mapInnerColor.g, style.mapInnerColor.b, 255); } + //Debug quadtree + int tl_x,tl_y,tr_x,tr_y,bl_x,bl_y,br_x,br_y; + float dx,dy; + + pxFromLonLat(&dx, &dy, tree->lat_min, tree->lon_min); + screenCoords(&tl_x, &tl_y, dx, dy); + + pxFromLonLat(&dx, &dy, tree->lat_max, tree->lon_min); + screenCoords(&tr_x, &tr_y, dx, dy); + + pxFromLonLat(&dx, &dy, tree->lat_min, tree->lon_max); + screenCoords(&bl_x, &bl_y, dx, dy); + + pxFromLonLat(&dx, &dy, tree->lat_max, tree->lon_max); + screenCoords(&br_x, &br_y, dx, dy); + + lineRGBA(renderer, tl_x, tl_y, tr_x, tr_y, 255, 0, 0, 255); + lineRGBA(renderer, tr_x, tr_y, br_x, br_y, 255, 0, 0, 255); + lineRGBA(renderer, bl_x, bl_y, br_x, br_y, 255, 0, 0, 255); + lineRGBA(renderer, tl_x, tl_y, bl_x, bl_y, 255, 0, 0, 255); } diff --git a/drawPolys.REMOVED.git-id b/drawPolys.REMOVED.git-id deleted file mode 100644 index f60973a..0000000 --- a/drawPolys.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -85c850fc7f07d0cf30352d3385c7a2aeb57fecf3 \ No newline at end of file diff --git a/font/TerminusTTF-4.46.0.ttf b/font/TerminusTTF-4.46.0.ttf new file mode 100644 index 0000000..eafa3a6 Binary files /dev/null and b/font/TerminusTTF-4.46.0.ttf differ diff --git a/font/TerminusTTF-4.46.0.ttf.REMOVED.git-id b/font/TerminusTTF-4.46.0.ttf.REMOVED.git-id deleted file mode 100644 index 0fe2e2e..0000000 --- a/font/TerminusTTF-4.46.0.ttf.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -eafa3a6e408def39bcd002f60a6d9a9810d54234 \ No newline at end of file diff --git a/font/TerminusTTF-Bold-4.46.0.ttf b/font/TerminusTTF-Bold-4.46.0.ttf new file mode 100644 index 0000000..9dc2aed Binary files /dev/null and b/font/TerminusTTF-Bold-4.46.0.ttf differ diff --git a/font/TerminusTTF-Bold-4.46.0.ttf.REMOVED.git-id b/font/TerminusTTF-Bold-4.46.0.ttf.REMOVED.git-id deleted file mode 100644 index c1e10e0..0000000 --- a/font/TerminusTTF-Bold-4.46.0.ttf.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -9dc2aed0a76993fd7ba9c28e0f55fce873a8c790 \ No newline at end of file diff --git a/mapbox_testing b/mapbox_testing deleted file mode 100644 index 5a82f5c..0000000 --- a/mapbox_testing +++ /dev/null @@ -1,6 +0,0 @@ -curl "https://api.mapbox.com/v4/mapbox.mapbox-streets-v8/8/40/89.mvt?access_token=pk.eyJ1Ijoibm1hdHN1ZGEiLCJhIjoiY2swazhrdGNjMGZ3NzNvcmE0OGxoaGd2byJ9.PAYHqO3any_6vLdjQ44RGw" - -mapbox://styles/nmatsuda/ck0k7rvvt3rkv1cq6l74wjda2 - - -47.695,-123.489 \ No newline at end of file diff --git a/mapconverter.py b/mapconverter.py index e73dcb2..d139dd5 100644 --- a/mapconverter.py +++ b/mapconverter.py @@ -1,76 +1,103 @@ -import json +import geopandas import numpy as np -import sys from tqdm import tqdm -import argparse - -parser = argparse.ArgumentParser(description='viz1090 SVG Map Converter') -parser.add_argument("--resolution", default=250, type=int, help="downsample resolution") -parser.add_argument("file", nargs="+", help="filename") - -args = parser.parse_args() - -if(len(args.file) == 0): - print("No input filename given") - exit() - -bin_file = open("mapdata.bin", "wb") outlist = [] -resolution = args.resolution +tolerance = .05 -for file in args.file: - with open(file, "r") as read_file: - data = json.load(read_file) +coast = geopandas.read_file("ne_10m_coastline.shp") +coast_simple = coast['geometry'].simplify(tolerance, preserve_topology=False) +for i in tqdm(range(len(coast_simple))): + pointx = coast_simple[i].coords.xy[0] + pointy = coast_simple[i].coords.xy[1] - print("Reading points") - for i in tqdm(range(len(data['features']))): + for j in range(len(pointx)): + outlist.extend([float(pointx[j]),float(pointy[j])]) + outlist.extend([0,0]) - if(data['features'][i]['geometry']['type'] == 'LineString'): - prevx = 0 - prevy = 0 - - temp = [] - - for currentPoint in data['features'][i]['geometry']['coordinates']: - - currentx = float(int(resolution * float(currentPoint[0]))) / resolution - currenty = float(int(resolution * float(currentPoint[1]))) / resolution - - if(currentx != prevx or currenty != prevy): - temp.extend([currentx,currenty]) - - prevx = currentx - prevy = currenty - temp.extend(["0","0"]) - else: - prevx = 0 - prevy = 0 - - temp = [] - - for currentLine in data['features'][i]['geometry']['coordinates']: - for currentPoint in currentLine: - - currentx = float(int(resolution * float(currentPoint[0]))) / resolution - currenty = float(int(resolution * float(currentPoint[1]))) / resolution - - if(currentx != prevx or currenty != prevy): - temp.extend([currentx,currenty]) - - prevx = currentx - prevy = currenty - - temp.extend(["0","0"]) - - - outlist.extend(temp) - +bin_file = open("mapdata.bin", "wb") np.asarray(outlist).astype(np.single).tofile(bin_file) bin_file.close() print("Wrote %d points" % (len(outlist) / 2)) + +# import json +# import numpy as np +# import sys +# from tqdm import tqdm +# import argparse + +# parser = argparse.ArgumentParser(description='viz1090 SVG Map Converter') +# parser.add_argument("--resolution", default=250, type=int, help="downsample resolution") +# parser.add_argument("file", nargs="+", help="filename") + +# args = parser.parse_args() + +# if(len(args.file) == 0): +# print("No input filename given") +# exit() + +# bin_file = open("mapdata.bin", "wb") + +# outlist = [] + +# resolution = args.resolution + +# for file in args.file: +# with open(file, "r") as read_file: +# data = json.load(read_file) + + + +# print("Reading points") +# for i in tqdm(range(len(data['features']))): + + +# if(data['features'][i]['geometry']['type'] == 'LineString'): +# prevx = 0 +# prevy = 0 + +# temp = [] + +# for currentPoint in data['features'][i]['geometry']['coordinates']: + +# currentx = float(int(resolution * float(currentPoint[0]))) / resolution +# currenty = float(int(resolution * float(currentPoint[1]))) / resolution + +# if(currentx != prevx or currenty != prevy): +# temp.extend([currentx,currenty]) + +# prevx = currentx +# prevy = currenty +# temp.extend(["0","0"]) +# else: +# prevx = 0 +# prevy = 0 + +# temp = [] + +# for currentLine in data['features'][i]['geometry']['coordinates']: +# for currentPoint in currentLine: + +# currentx = float(int(resolution * float(currentPoint[0]))) / resolution +# currenty = float(int(resolution * float(currentPoint[1]))) / resolution + +# if(currentx != prevx or currenty != prevy): +# temp.extend([currentx,currenty]) + +# prevx = currentx +# prevy = currenty + +# temp.extend(["0","0"]) + + +# outlist.extend(temp) + +# np.asarray(outlist).astype(np.single).tofile(bin_file) +# bin_file.close() + +# print("Wrote %d points" % (len(outlist) / 2)) diff --git a/ne_10m_coastline.shp b/ne_10m_coastline.shp new file mode 100644 index 0000000..e6f0c1a Binary files /dev/null and b/ne_10m_coastline.shp differ diff --git a/ne_10m_coastline.shx b/ne_10m_coastline.shx new file mode 100644 index 0000000..3599df7 Binary files /dev/null and b/ne_10m_coastline.shx differ diff --git a/out.prof.REMOVED.git-id b/out.prof.REMOVED.git-id deleted file mode 100644 index 5f8f31c..0000000 --- a/out.prof.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -34c8403286643597ad193fa68d13266d3a5f07a6 \ No newline at end of file diff --git a/seen b/seen deleted file mode 100644 index 6075aa7..0000000 --- a/seen +++ /dev/null @@ -1,172 +0,0 @@ -net_io.c: while ((p) && (p->next != c)) { -net_io.c: p = p->next; -net_io.c: p->next = c->next; -Binary file .git/objects/pack/pack-bf860161866f3e6c65f8f17c93e90565fe339dff.idx matches -Binary file .git/objects/pack/pack-bf860161866f3e6c65f8f17c93e90565fe339dff.pack matches -AircraftList.cpp: if (p->addr == addr) return (p); -AircraftList.cpp: p = p->next; -AircraftList.cpp: p->live = 0; -AircraftList.cpp: p = p->next; -AircraftList.cpp: p->next = head; -AircraftList.cpp: p->prev_seen = p->seen; -AircraftList.cpp: p->live = 1; -AircraftList.cpp: if(p->seen == a->seen) { -AircraftList.cpp: p->seen = a->seen; -AircraftList.cpp: p->msSeen = now(); -AircraftList.cpp: if((p->seen - p->prev_seen) > 0) { -AircraftList.cpp: p->messageRate = 1.0 / (double)(p->seen - p->prev_seen); -AircraftList.cpp: memcpy(p->flight, a->flight, sizeof(p->flight)); -AircraftList.cpp: memcpy(p->signalLevel, a->signalLevel, sizeof(p->signalLevel)); -AircraftList.cpp: p->altitude = a->altitude; -AircraftList.cpp: p->speed = a->speed; -AircraftList.cpp: p->track = a->track; -AircraftList.cpp: p->vert_rate = a->vert_rate; -AircraftList.cpp: p->lon = a->lon; -AircraftList.cpp: p->lat = a->lat; -AircraftList.cpp: if(p->seenLatLon < a->seenLatLon) { -AircraftList.cpp: p->msSeenLatLon = now(); -AircraftList.cpp: // p->oldIdx = (p->oldIdx+1) % 32; -AircraftList.cpp: // p->oldLon[p->oldIdx] = p->lon; -AircraftList.cpp: // p->oldLat[p->oldIdx] = p->lat; -AircraftList.cpp: p->lonHistory.push_back(p->lon); -AircraftList.cpp: p->latHistory.push_back(p->lat); -AircraftList.cpp: p->headingHistory.push_back(p->track); -AircraftList.cpp: p->timestampHistory.push_back(p->msSeenLatLon); -AircraftList.cpp: // p->oldHeading[p->oldIdx] = p->track; -AircraftList.cpp: // p->oldSeen[p->oldIdx] = p->seenLatLon; -AircraftList.cpp: p->seenLatLon = a->seenLatLon; -AircraftList.cpp: if(!p->live) { -AircraftList.cpp: head = p->next; -AircraftList.cpp: prev->next = p->next; -AircraftList.cpp: p = p->next; -Binary file mapdata.bin matches -Binary file viz1090 matches -View.cpp: if(p->lonHistory.empty()) { -View.cpp: std::vector::iterator lon_idx = p->lonHistory.begin(); -View.cpp: std::vector::iterator lat_idx = p->latHistory.begin(); -View.cpp: std::vector::iterator heading_idx = p->headingHistory.begin(); -View.cpp: int idx = p->lonHistory.size(); -View.cpp: for(; std::next(lon_idx) != p->lonHistory.end(); ++lon_idx, ++lat_idx, ++heading_idx) { -View.cpp: // float age = pow(1.0 - (float)idx / (float)p->lonHistory.size(), 2.2); -View.cpp: float age = 1.0 - (float)idx / (float)p->lonHistory.size(); -View.cpp: unsigned char * pSig = p->signalLevel; -View.cpp: if(elapsed(p->msSeen) < 1024) { -View.cpp: seenFade = (Uint8) (255.0 - elapsed(p->msSeen) / 4.0); -View.cpp: if(elapsed(p->msSeenLatLon) < 1024) { -View.cpp: seenFade = (Uint8) (255.0 - elapsed(p->msSeenLatLon) / 4.0); -View.cpp: if(elapsed(p->msSeenLatLon) < 500) { -View.cpp: circleRGBA(renderer, p->cx, p->cy, elapsed(p->msSeenLatLon) * screen_width / (8192), 255,255, 255, 64 - (uint8_t)(64.0 * elapsed(p->msSeenLatLon) / 500.0)); -View.cpp: if(p->pressure * screen_width < pressure_scale) { -View.cpp: drawSignalMarks(p, p->x, p->y); -View.cpp: maxCharCount = snprintf(flight,10," %s", p->flight); -View.cpp: drawStringBG(flight, p->x, p->y, mapBoldFont, white, black); -View.cpp: //roundedRectangleRGBA(renderer, p->x, p->y, p->x + maxCharCount * mapFontWidth, p->y + mapFontHeight, ROUND_RADIUS, white.r, white.g, white.b, SDL_ALPHA_OPAQUE); -View.cpp: //drawString(flight, p->x, p->y, mapBoldFont, white); -View.cpp: if(p->pressure * screen_width < 0.5f * pressure_scale) { -View.cpp: currentCharCount = snprintf(alt,10," %dm", (int) (p->altitude / 3.2828)); -View.cpp: currentCharCount = snprintf(alt,10," %d'", p->altitude); -View.cpp: drawStringBG(alt, p->x, p->y + currentLine * mapFontHeight, mapFont, grey, black); -View.cpp: currentCharCount = snprintf(speed,10," %dkm/h", (int) (p->speed * 1.852)); -View.cpp: currentCharCount = snprintf(speed,10," %dmph", p->speed); -View.cpp: drawStringBG(speed, p->x, p->y + currentLine * mapFontHeight, mapFont, grey, black); -View.cpp: Sint16 vx[4] = {p->cx, p->cx + (p->x - p->cx) / 2, p->x, p->x}; -View.cpp: Sint16 vy[4] = {p->cy, p->cy + (p->y - p->cy) / 2, p->y - mapFontHeight, p->y}; -View.cpp: if(p->cy > p->y + currentLine * mapFontHeight) { -View.cpp: vy[2] = p->y + currentLine * mapFontHeight + mapFontHeight; -View.cpp: vy[3] = p->y + currentLine * mapFontHeight; -View.cpp: thickLineRGBA(renderer,p->x,p->y,p->x,p->y+currentLine*mapFontHeight,screen_uiscale,200,200,200,SDL_ALPHA_OPAQUE); -View.cpp: p->w = maxCharCount * mapFontWidth; -View.cpp: p->h = currentLine * mapFontHeight; -View.cpp: int x = p->cx - 20; -View.cpp: int y = p->cy + 22; -View.cpp: if(elapsed(p->msSeenLatLon) < 500) { -View.cpp: circleRGBA(renderer, p->cx, p->cy, elapsed(p->msSeenLatLon) * screen_width / (8192), 255,255, 255, 64 - (uint8_t)(64.0 * elapsed(p->msSeenLatLon) / 500.0)); -View.cpp: maxCharCount = snprintf(flight,10," %s", p->flight); -View.cpp: //roundedRectangleRGBA(renderer, p->x, p->y, p->x + maxCharCount * mapFontWidth, p->y + mapFontHeight, ROUND_RADIUS, white.r, white.g, white.b, SDL_ALPHA_OPAQUE); -View.cpp: //drawString(flight, p->x, p->y, mapBoldFont, white); -View.cpp: currentCharCount = snprintf(alt,10," %dm", (int) (p->altitude / 3.2828)); -View.cpp: currentCharCount = snprintf(alt,10," %d'", p->altitude); -View.cpp: currentCharCount = snprintf(speed,10," %dkm/h", (int) (p->speed * 1.852)); -View.cpp: currentCharCount = snprintf(speed,10," %dmph", p->speed); -View.cpp: int p_left = p->x - 10 * screen_uiscale; -View.cpp: int p_right = p->x + p->w + 10 * screen_uiscale; -View.cpp: int p_top = p->y - 10 * screen_uiscale; -View.cpp: int p_bottom = p->y + p->h + 10 * screen_uiscale; -View.cpp: //rectangleRGBA(renderer, p->x, p->y, p->x + p->w, p->y + p->h, 255,0,0, SDL_ALPHA_OPAQUE); -View.cpp: //lineRGBA(renderer, p->cx, p->cy, p->x, p->y, 0,255,0, SDL_ALPHA_OPAQUE); -View.cpp: p->ddox = 0; -View.cpp: p->ddoy = 0; -View.cpp: float o_mag = sqrt(p->ox*p->ox + p->oy*p->oy); -View.cpp: p->ddox -= p->ox / o_mag * spring_force * (o_mag - spring_length); -View.cpp: p->ddoy -= p->oy / o_mag * spring_force * (o_mag - spring_length); -View.cpp: p->ox += (float)(10 * screen_uiscale - p_left); -View.cpp: p->ox -= (float)(p_right - (screen_width - 10 * screen_uiscale)); -View.cpp: p->oy += (float)(10 * screen_uiscale - p_top); -View.cpp: p->oy -= (float)(p_bottom - (screen_height - 10 * screen_uiscale)); -View.cpp: p->pressure = 0; -View.cpp: if(check_p->addr != p->addr) { -View.cpp: int check_left = check_p->x - 5 * screen_uiscale; -View.cpp: int check_right = check_p->x + check_p->w + 5 * screen_uiscale; -View.cpp: int check_top = check_p->y - 5 * screen_uiscale; -View.cpp: int check_bottom = check_p->y + check_p->h + 5 * screen_uiscale; -View.cpp: p->pressure += 1.0f / ((check_p->cx - p->cx) * (check_p->cx - p->cx) + (check_p->cy - p->cy) * (check_p->cy - p->cy)); -View.cpp: check_p->ddox -= label_force * (float)(check_left - p_right); -View.cpp: check_p->ddox -= label_force * (float)(check_right - p_left); -View.cpp: check_p->ddoy -= label_force * (float)(check_top - p_bottom); -View.cpp: check_p->ddoy -= label_force * (float)(check_bottom - p_top); -View.cpp: p_left = p->x - 5 * screen_uiscale; -View.cpp: p_right = p->x + 5 * screen_uiscale; -View.cpp: p_top = p->y - 5 * screen_uiscale; -View.cpp: p_bottom = p->y + 5 * screen_uiscale; -View.cpp: int check_left = check_p->x - 5 * screen_uiscale; -View.cpp: int check_right = check_p->x + check_p->w + 5 * screen_uiscale; -View.cpp: int check_top = check_p->y - 5 * screen_uiscale; -View.cpp: int check_bottom = check_p->y + check_p->h + 5 * screen_uiscale; -View.cpp: check_p->ddox -= plane_force * (float)(check_left - p_right); -View.cpp: check_p->ddox -= plane_force * (float)(check_right - p_left); -View.cpp: check_p->ddoy -= plane_force * (float)(check_top - p_bottom); -View.cpp: check_p->ddoy -= plane_force * (float)(check_bottom - p_top); -View.cpp: p = p->next; -View.cpp: p->dox += p->ddox; -View.cpp: p->doy += p->ddoy; -View.cpp: p->dox *= damping_force; -View.cpp: p->doy *= damping_force; -View.cpp: if(fabs(p->dox) > 10.0f) { -View.cpp: p->dox = sign(p->dox) * 10.0f; -View.cpp: if(fabs(p->doy) > 10.0f) { -View.cpp: p->doy = sign(p->doy) * 10.0f; -View.cpp: if(fabs(p->dox) < 1.0f) { -View.cpp: p->dox = 0; -View.cpp: if(fabs(p->doy) < 1.0f) { -View.cpp: p->doy = 0; -View.cpp: p->ox += p->dox; -View.cpp: p->oy += p->doy; -View.cpp: p->x = p->cx + (int)round(p->ox); -View.cpp: p->y = p->cy + (int)round(p->oy); -View.cpp: p = p->next; -View.cpp: p = p->next; -View.cpp: if (p->lon && p->lat) { -View.cpp: pxFromLonLat(&dx, &dy, p->lon, p->lat); -View.cpp: if(p->created == 0) { -View.cpp: p->created = now(); -View.cpp: float age_ms = (float)elapsed(p->created); -View.cpp: if(p->msSeenLatLon > p->timestampHistory.back()) { -View.cpp: pxFromLonLat(&dx, &dy, p->lonHistory.back(), p->latHistory.back()); -View.cpp: float velx = (x - oldx) / (p->msSeenLatLon - p->timestampHistory.back()); -View.cpp: float vely = (y - oldy) / (p->msSeenLatLon - p->timestampHistory.back()); -View.cpp: usex = x + elapsed(p->msSeenLatLon) * velx; -View.cpp: usey = y + elapsed(p->msSeenLatLon) * vely; -View.cpp: planeColor = lerpColor(style.planeColor, style.planeGoneColor, float(elapsed_s(p->seen)) / (float) DISPLAY_ACTIVE); -View.cpp: drawPlaneOffMap(x, y, &(p->cx), &(p->cy), planeColor); -View.cpp: drawPlaneIcon(usex, usey, p->track, planeColor); -View.cpp: p->cx = usex; -View.cpp: p->cy = usey; -View.cpp: p = p->next; -View.cpp: if((p->cx - x) * (p->cx - x) + (p->cy - y) * (p->cy - y) < 900) { -View.cpp: if((p->cx - x) * (p->cx - x) + (p->cy - y) * (p->cy - y) < -View.cpp: p = p->next; -all.svg: -AppData.cpp: unsigned char * pSig = p->signalLevel; -AppData.cpp: if (p->lon && p->lat) { -AppData.cpp: msgRateAccumulate += p->messageRate; -AppData.cpp: p = p->next;