77from .. import config , episode , naming , plane , process , session , synchronization
88
99
10- def run (working_dir : str | pathlib .Path , config_dir : str | pathlib .Path = None , show_visualization = False , show_planes = True , show_only_intervals = True , ** study_settings ):
10+ def run (working_dir : str | pathlib .Path , config_dir : str | pathlib .Path = None , show_visualization = False , show_planes = True , show_only_intervals = True , progress_indicator : process_pool . JobProgress = None , ** study_settings ):
1111 # if show_visualization, each frame is shown in a viewer, overlaid with info about detected planes and projected gaze
1212 # if show_poster, gaze in space of each plane is also drawn in a separate windows
1313 # if show_only_intervals, only the coded mapping episodes (if available) are shown in the viewer while the rest of the scene video is skipped past
@@ -26,15 +26,21 @@ def run(working_dir: str|pathlib.Path, config_dir: str|pathlib.Path = None, show
2626 gui .set_show_play_percentage (True )
2727 gui .set_show_action_tooltip (True )
2828
29- proc_thread = propagating_thread .PropagatingThread (target = do_the_work , args = (working_dir , config_dir , gui , show_planes , show_only_intervals ), kwargs = study_settings , cleanup_fun = gui .stop )
29+ proc_thread = propagating_thread .PropagatingThread (target = do_the_work , args = (working_dir , config_dir , gui , show_planes , show_only_intervals , progress_indicator ), kwargs = study_settings , cleanup_fun = gui .stop )
3030 proc_thread .start ()
3131 gui .start ()
3232 proc_thread .join ()
3333 else :
34- do_the_work (working_dir , config_dir , None , False , False , ** study_settings )
34+ do_the_work (working_dir , config_dir , None , False , False , progress_indicator , ** study_settings )
3535
3636
37- def do_the_work (working_dir : pathlib .Path , config_dir : pathlib .Path , gui : GUI , show_planes : bool , show_only_intervals : bool , ** study_settings ):
37+ def do_the_work (working_dir : pathlib .Path , config_dir : pathlib .Path , gui : GUI , show_planes : bool , show_only_intervals : bool , progress_indicator : process_pool .JobProgress , ** study_settings ):
38+ # progress indicator
39+ if progress_indicator is None :
40+ progress_indicator = process_pool .JobProgress (printer = lambda x : print (x ))
41+ progress_indicator .set_unit ('samples' )
42+ progress_indicator .set_start_time_to_now ()
43+
3844 # get settings for the study
3945 study_config = config .read_study_config_with_overrides (config_dir , {config .OverrideLevel .Session : working_dir .parent , config .OverrideLevel .Recording : working_dir }, ** study_settings )
4046
@@ -77,13 +83,17 @@ def do_the_work(working_dir: pathlib.Path, config_dir: pathlib.Path, gui: GUI, s
7783 head_gazes = gaze_headref .read_dict_from_file (working_dir / gt_naming .gaze_data_fname , processing_intervals if should_load_part else None , ts_column_suffixes = ['VOR' , '' ])[0 ]
7884 poses = {p :gt_pose .read_dict_from_file (working_dir / f'{ naming .plane_pose_prefix } { p } .tsv' , mapping_setup [p ] if should_load_part else None ) for p in mapping_setup }
7985
86+ # prep progress indicator
87+ total = sum (len (head_gazes [f ]) for p in poses for f in poses [p ] if f in head_gazes )
88+ progress_indicator .set_total (total )
89+ progress_indicator .set_intervals (int (total / 200 ), int (total / 200 ))
8090 # get camera calibration info
8191 camera_params = ocv .CameraParams .read_from_file (working_dir / gt_naming .scene_camera_calibration_fname )
8292
8393 # transform gaze to plane(s)
8494 plane_gazes : dict [str , dict [int ,list [gaze_worldref .Gaze ]]] = {}
8595 for p in planes :
86- plane_gazes [p ] = gaze_worldref .from_head (poses [p ], head_gazes , camera_params )
96+ plane_gazes [p ] = gaze_worldref .from_head (poses [p ], head_gazes , camera_params , progress_indicator . update )
8797 gaze_worldref .write_dict_to_file (plane_gazes [p ], working_dir / f'{ naming .world_gaze_prefix } { p } .tsv' , skip_missing = True )
8898
8999 # update state
0 commit comments