88from tqdm import tqdm
99
1010from simple_scenario import Scenario , EgoConfiguration , Vehicle
11- from simple_scenario .road import Road , StraightSegment
11+ from simple_scenario .road import SyntheticRoad , StraightSegment
1212
1313
1414class CutOutScenarioGenerator :
@@ -134,19 +134,7 @@ def _create_scenarios_of_plot_no(
134134 plot_no_result_dir = self ._result_dir / f"plot_{ plot_no :02d} "
135135 plot_no_result_dir .mkdir (exist_ok = True )
136136
137- # Scenarios
138- scenario_result_dir = plot_no_result_dir / "scenarios"
139- scenario_result_dir .mkdir (exist_ok = True )
140-
141- # Images
142- scenario_image_dir = plot_no_result_dir / "images"
143- if create_image :
144- scenario_image_dir .mkdir (exist_ok = True )
145-
146- # Gifs
147- scenario_gif_dir = plot_no_result_dir / "gifs"
148- if create_gif :
149- scenario_gif_dir .mkdir (exist_ok = True )
137+ # Each scenario will get its own subfolder under the plot directory
150138
151139 ve0 = ve0_kmh / 3.6
152140
@@ -160,9 +148,7 @@ def _create_scenarios_of_plot_no(
160148 vy = vy ,
161149 ve0 = ve0 ,
162150 plot_no = plot_no ,
163- scenario_result_dir = scenario_result_dir ,
164- scenario_gif_dir = scenario_gif_dir ,
165- scenario_image_dir = scenario_image_dir ,
151+ plot_no_result_dir = plot_no_result_dir ,
166152 create_gif = create_gif ,
167153 create_image = create_image ,
168154 create_openx = create_openx ,
@@ -180,9 +166,7 @@ def _create_single_scenario( # noqa: PLR0912
180166 scenario_name : str | None = None ,
181167 check_collision_feasibility : bool = True ,
182168 plot_no : str | None = None ,
183- scenario_result_dir : str | Path | None = None ,
184- scenario_gif_dir : str | Path | None = None ,
185- scenario_image_dir : str | Path | None = None ,
169+ plot_no_result_dir : str | Path | None = None ,
186170 create_gif : bool = False ,
187171 create_image : bool = False ,
188172 create_openx : bool = False ,
@@ -218,7 +202,7 @@ def _create_single_scenario( # noqa: PLR0912
218202 vy = self ._lane_width / object_vehicle_lc_duration
219203 scenario_duration = np .ceil (object_vehicle_lc_duration ) + 10
220204
221- dummy_vehicle = Vehicle (0 , 0 , 0 , 0 , 0 )
205+ dummy_vehicle = Vehicle (0 )
222206 # Object vehicle
223207 dx0 = ve0 * self ._thw0
224208 if dx0_ego_lead is not None :
@@ -230,10 +214,10 @@ def _create_single_scenario( # noqa: PLR0912
230214 vo0 = ve0
231215 object_vehicle = Vehicle (
232216 0 ,
233- self ._object_lanelet_id ,
234- object_vehicle_s0 ,
235- object_vehicle_t0 ,
236- vo0 ,
217+ start_lanelet_id = self ._object_lanelet_id ,
218+ start_s = object_vehicle_s0 ,
219+ start_t = object_vehicle_t0 ,
220+ v0 = vo0 ,
237221 lc_direction = - 1 ,
238222 lc_type = "vy" ,
239223 lc_vy = vy ,
@@ -242,20 +226,22 @@ def _create_single_scenario( # noqa: PLR0912
242226 # f vehicle (slow vehicle)
243227 f_vehicle_s0 = object_vehicle_s0 + dummy_vehicle .length + dx0_f
244228 f_vehicle_t0 = object_vehicle_t0
245- f_vehicle = Vehicle (1 , self ._f_lanelet_id , f_vehicle_s0 , f_vehicle_t0 , vf0 )
229+ f_vehicle = Vehicle (1 , start_lanelet_id = self ._f_lanelet_id , start_s = f_vehicle_s0 , start_t = f_vehicle_t0 , v0 = vf0 )
246230
247231 # Calculate road length
248232 ego_dist = ve0 * scenario_duration
249- road_length = max (ego_dist , self ._min_road_length ) + self ._ego_s0 + 100
233+ road_length = max (ego_dist , self ._min_road_length ) + self ._ego_s0 + 110 # TODO: check length of object trajectory as well
250234 goal_position = max (
251235 self ._ego_s0 + 0.75 * ego_dist ,
252236 f_vehicle_s0 + vf0 * scenario_duration + dummy_vehicle .length ,
253237 )
254- road = Road (
238+ ego_configuration = EgoConfiguration (
239+ self ._ego_lanelet_id , self ._ego_s0 , self ._ego_t0 , ve0 , target_s = goal_position , target_t = 0 , target_lanelet_id = self ._ego_lanelet_id
240+ )
241+ road = SyntheticRoad (
255242 self ._n_lanes ,
256243 self ._lane_width ,
257244 segments = [StraightSegment (road_length )],
258- goal_position = goal_position ,
259245 speed_limit = 60 ,
260246 )
261247
@@ -278,38 +264,49 @@ def _create_single_scenario( # noqa: PLR0912
278264 if not scenario_is_feasible :
279265 return None
280266
281- if scenario_result_dir is not None :
282- scenario_config_dir = scenario_result_dir / "configs"
267+ if plot_no_result_dir is not None :
268+ scenario_dir = Path (plot_no_result_dir ) / scenario_name
269+ scenario_dir .mkdir (exist_ok = True )
270+
271+ scenario_config_dir = scenario_dir / "configs"
283272 scenario_config_dir .mkdir (exist_ok = True )
284273 scenario .save (scenario_config_dir )
274+
285275 if create_openx :
286- scenario_result_dir_openx = scenario_result_dir / "openx"
287- scenario_result_dir_openx .mkdir (exist_ok = True )
288- scenario .save (scenario_result_dir_openx , mode = "openx" )
289- if scenario_image_dir is not None and create_image :
290- scenario .render (scenario_image_dir , dpi = 600 )
291- if scenario_gif_dir is not None and create_gif :
292- scenario .render_gif (scenario_gif_dir , dpi = 600 )
276+ scenario_openx_dir = scenario_dir / "openx"
277+ scenario_openx_dir .mkdir (exist_ok = True )
278+ scenario .save (scenario_openx_dir , mode = "openx" )
279+ if create_image or create_gif :
280+ scenario_image_dir = scenario_dir / "images"
281+ scenario_image_dir .mkdir (exist_ok = True )
282+ if create_image :
283+ scenario .render (scenario_image_dir , dpi = 600 )
284+ if create_gif :
285+ scenario .render_gif (scenario_image_dir , dpi = 600 )
293286
294287 return scenario
295288
296289
297290def unpack_and_run (args_list : list ) -> None :
298291 scenario_generator = CutOutScenarioGenerator (args_list [0 ])
299292 scenario_generator .create_all_scenarios (
300- only_plot_no = args_list [1 ], create_image = True , create_openx = True
293+ only_plot_no = args_list [1 ], create_image = args_list [ 2 ] , create_openx = args_list [ 3 ], create_gif = args_list [ 4 ]
301294 )
302295
303296
304297def generate_all_scenarios () -> None :
305298 result_dir = Path (__file__ ).parent / ".." / "results" / "annex3" / "cutout"
306299 result_dir .mkdir (exist_ok = True , parents = True )
307300
301+ create_image = True
302+ create_openx = True
303+ create_gif = False
304+
308305 n_plots_in_regulation = 6
309306
310307 n_workers = n_plots_in_regulation
311308
312- all_args_lists = [[result_dir , i + 1 ] for i in range (n_plots_in_regulation )]
309+ all_args_lists = [[result_dir , i + 1 , create_image , create_openx , create_gif ] for i in range (n_plots_in_regulation )]
313310
314311 if n_workers == 1 :
315312 for arg_list in all_args_lists :
0 commit comments