diff --git a/drawing_to_fsd_layout/export.py b/drawing_to_fsd_layout/export.py index 2f035c5..cbe6997 100644 --- a/drawing_to_fsd_layout/export.py +++ b/drawing_to_fsd_layout/export.py @@ -8,7 +8,7 @@ from drawing_to_fsd_layout.common import FloatArrayNx2 -def export_json_string(edges_left: FloatArrayNx2, edges_right: FloatArrayNx2) -> str: +def export_json_string(edges_left: FloatArrayNx2, edges_right: FloatArrayNx2, centerline: FloatArrayNx2) -> str: """ Export the track edges to a JSON string that can be used in the FSD layout editor. @@ -21,6 +21,9 @@ def export_json_string(edges_left: FloatArrayNx2, edges_right: FloatArrayNx2) -> """ cones_x = np.concatenate((edges_left[:, 0], edges_right[:, 0])).tolist() cones_y = np.concatenate((edges_left[:, 1], edges_right[:, 1])).tolist() + centerline_x = centerline[:,0].tolist() + centerline_y = centerline[:,1].tolist() + centerline cones_color = ( ["orange_big"] + ["blue"] * (len(edges_left) - 1) @@ -31,6 +34,8 @@ def export_json_string(edges_left: FloatArrayNx2, edges_right: FloatArrayNx2) -> "x": cones_x, "y": cones_y, "color": cones_color, + "centerline_x": centerline_x, + "centerline_y": centerline_y } return json.dumps(obj) @@ -225,6 +230,7 @@ def cones_to_lyt( world_name: Literal["BL4", "AU1", "AU2", "AU3", "WE3", "LA2"], cones_left: FloatArrayNx2, cones_right: FloatArrayNx2, + centerline: FloatArrayNx2 ) -> bytes: offset = { "BL4": (-261, 124), @@ -246,5 +252,6 @@ def cones_to_lyt( (cones_left[0], cones_right[0]) ) + bytes_to_write = _traces_to_lyt_bytes(cones_per_type, offset) return bytes_to_write diff --git a/streamlit_app.py b/streamlit_app.py index 94482ef..f9cece8 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -11,6 +11,7 @@ from drawing_to_fsd_layout.cone_placement import ( calculate_min_track_width, decide_start_finish_line_position_and_direction, + estimate_centerline_from_edges, estimate_centerline_length, fix_edge_direction, place_cones, @@ -254,7 +255,7 @@ def main() -> None: f" {centerline_length:.2f} m*" ) - # centerline = estimate_centerline_from_edges(contour_a_splined, contour_b_splined) + centerline = estimate_centerline_from_edges(contour_a_splined, contour_b_splined) st.title("Place start/finish line") @@ -357,6 +358,16 @@ def main() -> None: head_width=min_track_width, ) + + plt.plot( + *centerline.T, + "--", + c="red", + label="Centerline", + markersize=5, + markeredgecolor="red", + ) + plt.plot( *right_cones[1:].T, "o", @@ -400,7 +411,7 @@ def main() -> None: st.info( "The JSON object has 3 keys: `x`, `y` and `color`. `x` and `y` are lists of floats representing the x and y coordinates of the cones. `color` is a list of strings representing the color of the cones. The colors are either `blue`, `yellow` or `orange_big`. The length of the three lists should be the same. The cones appear in the same order as the track direction. The first cone is the start/finish line. The cones are ordered in the direction of the track." ) - json_string = export_json_string(left_cones, right_cones) + json_string = export_json_string(left_cones, right_cones, centerline) st.download_button( "Download JSON", json_string, @@ -409,7 +420,7 @@ def main() -> None: ) with tab_lfs: world_name = "LA2" - lyt_bytes = cones_to_lyt(world_name, left_cones, right_cones) + lyt_bytes = cones_to_lyt(world_name, left_cones, right_cones, centerline) filename = f"{world_name}_{track_name_normalized}.lyt"