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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
#!/usr/bin/env python
import unittest
import math
from argaze.AreaOfInterest import AOIFeatures, AOI2DScene
from argaze import GazeFeatures
import numpy
class TestAOI2DSceneClass(unittest.TestCase):
"""Test AOI2DScene class."""
def test_new(self):
"""Test AOI2DScene creation."""
# Check empty AOI2DScene creation
aoi_2d_scene = AOI2DScene.AOI2DScene()
self.assertEqual(aoi_2d_scene.dimension, 2)
self.assertEqual(len(aoi_2d_scene.items()), 0)
# Check AOI2DScene creation
aoi_2D_A = AOIFeatures.AreaOfInterest([[0, 0], [0, 1], [1, 1], [1, 0]])
aoi_2D_B = AOIFeatures.AreaOfInterest([[1, 1], [1, 2], [2, 2], [2, 1]])
aoi_2d_scene = AOI2DScene.AOI2DScene({"A": aoi_2D_A, "B": aoi_2D_B})
self.assertEqual(aoi_2d_scene.dimension, 2)
def test_raycast(self):
"""Test AOI2DScene raycast method."""
aoi_2D_A = AOIFeatures.AreaOfInterest([[0, 0], [0, 1], [1, 1], [1, 0]])
aoi_2D_B = AOIFeatures.AreaOfInterest([[1, 1], [1, 2], [2, 2], [2, 1]])
aoi_2d_scene = AOI2DScene.AOI2DScene({"A": aoi_2D_A, "B": aoi_2D_B})
gaze_position_A = GazeFeatures.GazePosition((0.5, 0.5))
gaze_position_B = GazeFeatures.GazePosition((1.5, 1.5))
gaze_position_C = GazeFeatures.GazePosition((0.5, 1.5))
# Check raycast results for gaze postion A
for name, aoi, looked in aoi_2d_scene.raycast(gaze_position_A):
if name == "A":
self.assertIsNone(numpy.testing.assert_array_equal(aoi, aoi_2D_A))
self.assertEqual(looked, True)
elif name == "B":
self.assertIsNone(numpy.testing.assert_array_equal(aoi, aoi_2D_B))
self.assertEqual(looked, False)
# Check raycast results for gaze postion B
for name, aoi, looked in aoi_2d_scene.raycast(gaze_position_B):
if name == "A":
self.assertIsNone(numpy.testing.assert_array_equal(aoi, aoi_2D_A))
self.assertEqual(looked, False)
elif name == "B":
self.assertIsNone(numpy.testing.assert_array_equal(aoi, aoi_2D_B))
self.assertEqual(looked, True)
# Check raycast results for gaze postion C
for name, aoi, looked in aoi_2d_scene.raycast(gaze_position_C):
if name == "A":
self.assertIsNone(numpy.testing.assert_array_equal(aoi, aoi_2D_A))
self.assertEqual(looked, False)
elif name == "B":
self.assertIsNone(numpy.testing.assert_array_equal(aoi, aoi_2D_B))
self.assertEqual(looked, False)
def test_circlecast(self):
"""Test AOI2DScene circlecast method."""
aoi_2D_A = AOIFeatures.AreaOfInterest([[0, 0], [0, 1], [1, 1], [1, 0]])
aoi_2D_B = AOIFeatures.AreaOfInterest([[1, 1], [1, 2], [2, 2], [2, 1]])
aoi_2d_scene = AOI2DScene.AOI2DScene({"A": aoi_2D_A, "B": aoi_2D_B})
gaze_position_A = GazeFeatures.GazePosition((0.5, 0.5), precision=0.5)
gaze_position_B = GazeFeatures.GazePosition((1.5, 1.5), precision=0.5)
gaze_position_C = GazeFeatures.GazePosition((1., 1.), precision=1)
gaze_position_D = GazeFeatures.GazePosition((0.5, 1.5), precision=0.25)
# Check circlecast results for gaze postion A
for name, aoi, looked_region, aoi_ratio, gaze_ratio in aoi_2d_scene.circlecast(gaze_position_A):
if name == "A":
self.assertIsNone(numpy.testing.assert_array_equal(aoi, aoi_2D_A))
self.assertTrue(math.isclose(aoi_ratio, math.pi / 4, abs_tol=1e-2))
self.assertTrue(math.isclose(gaze_ratio, 1., abs_tol=1e-3))
elif name == "B":
self.assertIsNone(numpy.testing.assert_array_equal(aoi, aoi_2D_B))
self.assertEqual(aoi_ratio, 0.)
self.assertEqual(gaze_ratio, 0.)
# Check circlecast results for gaze postion B
for name, aoi, looked_region, aoi_ratio, gaze_ratio in aoi_2d_scene.circlecast(gaze_position_B):
if name == "A":
self.assertIsNone(numpy.testing.assert_array_equal(aoi, aoi_2D_A))
self.assertEqual(aoi_ratio, 0.)
self.assertEqual(gaze_ratio, 0.)
elif name == "B":
self.assertIsNone(numpy.testing.assert_array_equal(aoi, aoi_2D_B))
self.assertTrue(math.isclose(aoi_ratio, math.pi / 4, abs_tol=1e-2))
self.assertTrue(math.isclose(gaze_ratio, 1., abs_tol=1e-3))
# Check circlecast results for gaze postion C
for name, aoi, looked_region, aoi_ratio, gaze_ratio in aoi_2d_scene.circlecast(gaze_position_C):
if name == "A":
self.assertIsNone(numpy.testing.assert_array_equal(aoi, aoi_2D_A))
self.assertTrue(math.isclose(aoi_ratio, math.pi / 4, abs_tol=1e-2))
self.assertTrue(math.isclose(gaze_ratio, 1 / 4, abs_tol=1e-3))
elif name == "B":
self.assertIsNone(numpy.testing.assert_array_equal(aoi, aoi_2D_B))
self.assertTrue(math.isclose(aoi_ratio, math.pi / 4, abs_tol=1e-2))
self.assertTrue(math.isclose(gaze_ratio, 1 / 4, abs_tol=1e-3))
# Check circlecast results for gaze postion D
for name, aoi, looked_region, aoi_ratio, gaze_ratio in aoi_2d_scene.circlecast(gaze_position_D):
if name == "A":
self.assertIsNone(numpy.testing.assert_array_equal(aoi, aoi_2D_A))
self.assertEqual(aoi_ratio, 0.)
self.assertEqual(gaze_ratio, 0.)
elif name == "B":
self.assertIsNone(numpy.testing.assert_array_equal(aoi, aoi_2D_B))
self.assertEqual(aoi_ratio, 0.)
self.assertEqual(gaze_ratio, 0.)
def test_copy(self):
"""Test AOI2DScene copy method."""
aoi_2D_A = AOIFeatures.AreaOfInterest([[0, 0], [0, 1], [1, 1], [1, 0]])
aoi_2D_B = AOIFeatures.AreaOfInterest([[1, 1], [1, 2], [2, 2], [2, 1]])
aoi_2d_scene = AOI2DScene.AOI2DScene({"A": aoi_2D_A, "B": aoi_2D_B})
# Check full copy
aoi_2d_scene_copy = aoi_2d_scene.copy()
self.assertEqual(aoi_2d_scene_copy.dimension, 2)
self.assertEqual(len(aoi_2d_scene_copy.items()), 2)
self.assertEqual(list(aoi_2d_scene_copy.keys()), ["A", "B"])
# Check cpy with exclusion
aoi_2d_scene_copy = aoi_2d_scene.copy(exclude=["B"])
self.assertEqual(aoi_2d_scene_copy.dimension, 2)
self.assertEqual(len(aoi_2d_scene_copy.items()), 1)
self.assertEqual(list(aoi_2d_scene_copy.keys()), ["A"])
class TestTimeStampedAOIScenesClass(unittest.TestCase):
"""Test TimeStampedAOIScenes class."""
def test___setitem__(self):
"""Test TimeStampedAOIScenes creation."""
aoi_2D_A = AOIFeatures.AreaOfInterest([[0, 0], [0, 1], [1, 1], [1, 0]])
aoi_2D_B = AOIFeatures.AreaOfInterest([[1, 1], [1, 2], [2, 2], [2, 1]])
aoi_2d_scene = AOI2DScene.AOI2DScene({"A": aoi_2D_A, "B": aoi_2D_B})
ts_aois_scenes = AOIFeatures.TimeStampedAOIScenes()
ts_aois_scenes[0] = aoi_2d_scene
# Check that only AOIScene can be added
with self.assertRaises(AssertionError):
ts_aois_scenes[1] = "This string is not an AOI2DScene"
if __name__ == '__main__':
unittest.main()
|