diff options
author | Théo de la Hogue | 2022-04-20 16:04:27 +0200 |
---|---|---|
committer | Théo de la Hogue | 2022-04-20 16:04:27 +0200 |
commit | 859a4b4230c1fc6fc0f61b5ae48f3e3f70bd5d2a (patch) | |
tree | c8d381ba755df5f36e58f40273ad25adab118153 /src/argaze/GazeFeatures.py | |
parent | a4a0ef9e28a009ad073958891382b3215c8d96f6 (diff) | |
download | argaze-859a4b4230c1fc6fc0f61b5ae48f3e3f70bd5d2a.zip argaze-859a4b4230c1fc6fc0f61b5ae48f3e3f70bd5d2a.tar.gz argaze-859a4b4230c1fc6fc0f61b5ae48f3e3f70bd5d2a.tar.bz2 argaze-859a4b4230c1fc6fc0f61b5ae48f3e3f70bd5d2a.tar.xz |
Processing pointer based visual scan.
Diffstat (limited to 'src/argaze/GazeFeatures.py')
-rw-r--r-- | src/argaze/GazeFeatures.py | 86 |
1 files changed, 66 insertions, 20 deletions
diff --git a/src/argaze/GazeFeatures.py b/src/argaze/GazeFeatures.py index 13bd9f5..e132849 100644 --- a/src/argaze/GazeFeatures.py +++ b/src/argaze/GazeFeatures.py @@ -193,7 +193,24 @@ class DispersionBasedFixationIdentifier(FixationIdentifier): return -1, None -class VisualScan(): +class VisualScanStep(DataStructures.DictObject): + """Define a visual scan step as a duration and an area of interest.""" + + def __init__(self, duration, aoi): + + super().__init__(type(self).__name__, **{'duration': duration, 'aoi': aoi}) + +class TimeStampedVisualScanSteps(DataStructures.TimeStampedBuffer): + """Define timestamped buffer to store visual scan steps.""" + + def __setitem__(self, key, value: VisualScanStep): + """Force value to be a VisualScanStep""" + if type(value) != VisualScanStep: + raise ValueError('value must be a VisualScanStep') + + super().__setitem__(key, value) + +class VisualScanGenerator(): """Abstract class to define when an aoi starts to be looked and when it stops.""" def __init__(self, ts_aoi_scenes: AOIFeatures.TimeStampedAOIScenes): @@ -204,34 +221,68 @@ class VisualScan(): def __iter__(self): raise NotImplementedError('__iter__() method not implemented') - def __next__(self): - raise NotImplementedError('__next__() method not implemented') + def build(self): + + visual_scan_steps = TimeStampedVisualScanSteps() + + for ts, step in self: + + if step == None: + continue -class PointerBasedVisualScan(VisualScan): + if step.get_type() == 'VisualScanStep': + + visual_scan_steps[ts] = step + + return visual_scan_steps + +class PointerBasedVisualScan(VisualScanGenerator): """Build visual scan on the basis of AOI's pointer information.""" - def __init__(self, ts_aoi_scenes: AOIFeatures.TimeStampedAOIScenes, tolerance_to_lacking: int): + def __init__(self, ts_aoi_scenes: AOIFeatures.TimeStampedAOIScenes): # TODO : add tolerance_to_lacking ? super().__init__(ts_aoi_scenes) # process identification on a copy self.__ts_aoi_scenes = ts_aoi_scenes.copy() - def __iter__(self): - """Start to build visual scan.""" - return self + # a dictionary to store when an aoi starts to be looked + self.__start_dict = {} - def __next__(self): + def __iter__(self): + """Visual scan generator function.""" # while there is aoi scene to process - if len(self.__ts_aoi_scenes) > 0: + while len(self.__ts_aoi_scenes) > 0: + + (ts_current, aoi_scene_current) = self.__ts_aoi_scenes.pop_first() - #if not ts_aoi.looked: + #if not aoi_scene_current.looked: # raise ValueError('TimeStampedAOIScenes must be looked using look_at method.') - return # start timestamp, AOI name, duration + for name in aoi_scene_current.areas(): + + aoi_looked = aoi_scene_current[name].pointer != None + + if aoi_looked: + + if not name in self.__start_dict.keys(): + + # aoi starts to be looked + self.__start_dict[name] = ts_current -class FixationBasedVisualScan(VisualScan): + elif name in self.__start_dict.keys(): + + # aoi stops to be looked + ts_start = self.__start_dict[name] + duration = ts_current - ts_start + + # forget the aoi + del self.__start_dict[name] + + yield ts_start, VisualScanStep(duration, name) + +class FixationBasedVisualScan(VisualScanGenerator): """Build visual scan on the basis of timestamped fixations.""" def __init__(self, ts_aoi_scenes: AOIFeatures.TimeStampedAOIScenes, ts_fixations: TimeStampedFixations): @@ -246,11 +297,6 @@ class FixationBasedVisualScan(VisualScan): self.__ts_fixations = ts_fixations.copy() def __iter__(self): - """Start to build visual scan.""" - return self - - def __next__(self): + """Visual scan generator function.""" - # while there is aoi scene to process - if len(self.__ts_aoi_scenes) > 0: - return
\ No newline at end of file + yield -1, None |