-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGazeTuple.py
71 lines (57 loc) · 2.89 KB
/
GazeTuple.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import math
from objects import constant
from objects.object import Point
class GazeTuple:
def __init__(self, raw_data):
self.raw_data = raw_data
self.id = 0
self.timestamp = 0
self.left_point = Point(0, 0, 0)
self.right_point = Point(0, 0, 0)
def initialize(self, screen_size, paint_point, display_geometry):
self.id = self.raw_data.get('id')
self.timestamp = self.raw_data.get('device_time_stamp')
self.extract_points()
self.calibrate(screen_size, paint_point, display_geometry.point)
self.check_in_range(display_geometry.size)
def extract_points(self):
self.left_point = self.extract_point(constant.LEFT)
self.right_point = self.extract_point(constant.RIGHT)
def extract_point(self, direction):
validity_attribute = '_gaze_point_validity'
coordinate_attribute = '_gaze_point_on_display_area'
attribute = 'left' if direction is constant.LEFT else 'right'
validity = self.raw_data.get(attribute + validity_attribute)
x = self.raw_data.get(attribute + coordinate_attribute)[0]
y = self.raw_data.get(attribute + coordinate_attribute)[1]
if math.isnan(x) or math.isnan(y):
validity = 0
x = 0 if math.isnan(y) else x
y = 0 if math.isnan(y) else y
return Point(x, y, validity)
def calibrate(self, screen_size, paint_point, display_point):
self.left_point.x *= screen_size.width
self.left_point.y *= screen_size.height
self.right_point.x *= screen_size.width
self.right_point.y *= screen_size.height
self.left_point.x -= (paint_point.x + display_point.x)
self.left_point.y -= (paint_point.y + display_point.y)
self.right_point.x -= (paint_point.x + display_point.x)
self.right_point.y -= (paint_point.y + display_point.y)
def check_in_range(self, display_size):
self.left_point.validity = 1 if self.is_in_range(constant.LEFT, display_size) else 0
self.right_point.validity = 1 if self.is_in_range(constant.RIGHT, display_size) else 0
def is_in_range(self, direction, display_size):
if direction is constant.LEFT:
if self.left_point.x <= 0 or self.left_point.x >= display_size.width: return False
if self.left_point.y <= 0 or self.left_point.y >= display_size.height: return False
return True
if direction is constant.RIGHT:
if self.right_point.x <= 0 or self.right_point.x >= display_size.width: return False
if self.right_point.y <= 0 or self.right_point.y >= display_size.height: return False
return True
def is_validate(self, direction):
if direction is constant.LEFT:
return True if self.left_point.validity is 1 else False
elif direction is constant.RIGHT:
return True if self.right_point.validity is 1 else False