Skip to content

Commit

Permalink
added centerline to track plot, json export and lyt export
Browse files Browse the repository at this point in the history
  • Loading branch information
mertyaylacigit committed Jun 3, 2024
1 parent f2c28e7 commit 16334f6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
20 changes: 16 additions & 4 deletions drawing_to_fsd_layout/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -21,16 +21,25 @@ 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)
+ ["orange_big"]
+ ["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)
Expand Down Expand Up @@ -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),
Expand All @@ -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
17 changes: 14 additions & 3 deletions streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand All @@ -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"

Expand Down

0 comments on commit 16334f6

Please sign in to comment.