From 16334f6097634f90f6a04b57b4515ed4814c564a Mon Sep 17 00:00:00 2001 From: mertyaylacigit Date: Mon, 3 Jun 2024 14:37:01 +0200 Subject: [PATCH 1/2] added centerline to track plot, json export and lyt export --- drawing_to_fsd_layout/export.py | 20 ++++++++++++++++---- streamlit_app.py | 17 ++++++++++++++--- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/drawing_to_fsd_layout/export.py b/drawing_to_fsd_layout/export.py index 2f035c5..bc1cc76 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) @@ -28,9 +31,15 @@ def export_json_string(edges_left: FloatArrayNx2, edges_right: FloatArrayNx2) -> + ["yellow"] * (len(edges_right) - 1) ) obj = { - "x": cones_x, - "y": cones_y, - "color": cones_color, + "cones":{ + "x": cones_x, + "y": cones_y, + "color": cones_color, + }, + "centerline": { + "x": centerline_x, + "y": centerline_y + } } return json.dumps(obj) @@ -225,6 +234,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 +256,7 @@ def cones_to_lyt( (cones_left[0], cones_right[0]) ) + cones_per_type.append(np.array(centerline)) + 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" From 83afed2fae6c9e24e2790082d7e35a17f32ccd46 Mon Sep 17 00:00:00 2001 From: Mert Yaylaci <151733368+mertyaylacigit@users.noreply.github.com> Date: Thu, 6 Jun 2024 14:41:17 +0200 Subject: [PATCH 2/2] updated json export and removed centerline in .lyt --- drawing_to_fsd_layout/export.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/drawing_to_fsd_layout/export.py b/drawing_to_fsd_layout/export.py index bc1cc76..cbe6997 100644 --- a/drawing_to_fsd_layout/export.py +++ b/drawing_to_fsd_layout/export.py @@ -31,15 +31,11 @@ def export_json_string(edges_left: FloatArrayNx2, edges_right: FloatArrayNx2, ce + ["yellow"] * (len(edges_right) - 1) ) obj = { - "cones":{ - "x": cones_x, - "y": cones_y, - "color": cones_color, - }, - "centerline": { - "x": centerline_x, - "y": centerline_y - } + "x": cones_x, + "y": cones_y, + "color": cones_color, + "centerline_x": centerline_x, + "centerline_y": centerline_y } return json.dumps(obj) @@ -256,7 +252,6 @@ def cones_to_lyt( (cones_left[0], cones_right[0]) ) - cones_per_type.append(np.array(centerline)) bytes_to_write = _traces_to_lyt_bytes(cones_per_type, offset) return bytes_to_write