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
|
"""
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <https://www.gnu.org/licenses/>.
"""
__author__ = "Théo de la Hogue"
__credits__ = []
__copyright__ = "Copyright 2023, Ecole Nationale de l'Aviation Civile (ENAC)"
__license__ = "GPLv3"
import unittest
import math
import os
from argaze.AreaOfInterest import AOIFeatures, AOI3DScene, AOI2DScene
from argaze import GazeFeatures
import numpy
class TestAOI3DSceneClass(unittest.TestCase):
"""Test AOI3DScene class."""
def test_new(self):
"""Test AOI3DScene creation."""
# Check empty AOI3DScene creation
aoi_3d_scene = AOI3DScene.AOI3DScene()
self.assertEqual(aoi_3d_scene.dimension, 3)
self.assertEqual(len(aoi_3d_scene.items()), 0)
# Check AOI3DScene creation
aoi_3D_A = AOIFeatures.AreaOfInterest([[0, 0, 0], [0, 1, 0], [1, 1, 0], [1, 0, 0]])
aoi_3D_B = AOIFeatures.AreaOfInterest([[1, 1, 0], [1, 2, 0], [2, 2, 0], [2, 1, 0]])
aoi_3d_scene = AOI3DScene.AOI3DScene({"A": aoi_3D_A, "B": aoi_3D_B})
self.assertEqual(aoi_3d_scene.dimension, 3)
def test_from_obj(self):
"""Test AOI3DScene from_obj method."""
current_directory = os.path.dirname(os.path.abspath(__file__))
aoi_3d_scene_tt = AOI3DScene.AOI3DScene.from_obj(os.path.join(current_directory, 'utils/scene.obj'))
self.assertEqual(len(aoi_3d_scene_tt.items()), 2)
def test_project(self):
"""Test AOI3DScene project method."""
aoi_3D_A = AOIFeatures.AreaOfInterest([[0, 0, 0], [0, 1, 0], [1, 1, 0], [1, 0, 0]])
aoi_3D_B = AOIFeatures.AreaOfInterest([[1, 1, 0], [1, 2, 0], [2, 2, 0], [2, 1, 0]])
aoi_3d_scene = AOI3DScene.AOI3DScene({"A": aoi_3D_A, "B": aoi_3D_B})
# Check default projection
aoi_2d_scene = aoi_3d_scene.project()
self.assertIsNone(numpy.testing.assert_array_equal(aoi_2d_scene['A'], [[0.0, 0.0], [0.0, 1.0], [1.0, 1.0], [1.0, 0.0]]))
self.assertIsNone(numpy.testing.assert_array_equal(aoi_2d_scene['B'], [[1.0, 1.0], [1.0, 2.0], [2.0, 2.0], [2.0, 1.0]]))
# Check projection with translation
aoi_2d_scene = aoi_3d_scene.project(T = numpy.array([1., 0., 0.]))
self.assertIsNone(numpy.testing.assert_array_equal(aoi_2d_scene['A'], [[1.0, 0.0], [1.0, 1.0], [2.0, 1.0], [2.0, 0.0]]))
self.assertIsNone(numpy.testing.assert_array_equal(aoi_2d_scene['B'], [[2.0, 1.0], [2.0, 2.0], [3.0, 2.0], [3.0, 1.0]]))
def test_transform(self):
"""Test AOI3DScene transform method."""
aoi_3D_A = AOIFeatures.AreaOfInterest([[0, 0, 0], [0, 1, 0], [1, 1, 0], [1, 0, 0]])
aoi_3D_B = AOIFeatures.AreaOfInterest([[1, 1, 0], [1, 2, 0], [2, 2, 0], [2, 1, 0]])
aoi_3d_scene = AOI3DScene.AOI3DScene({"A": aoi_3D_A, "B": aoi_3D_B})
# Check translation transformation
aoi_3d_scene = aoi_3d_scene.transform(T = numpy.array([1., 0., 0.]))
self.assertIsNone(numpy.testing.assert_array_equal(aoi_3d_scene['A'], [[1.0, 0.0, 0.0], [1.0, 1.0, 0.0], [2.0, 1.0, 0.0], [2.0, 0.0, 0.0]]))
self.assertIsNone(numpy.testing.assert_array_equal(aoi_3d_scene['B'], [[2.0, 1.0, 0.0], [2.0, 2.0, 0.0], [3.0, 2.0, 0.0], [3.0, 1.0, 0.0]]))
def test_copy(self):
"""Test AOI2DScene copy method."""
aoi_3D_A = AOIFeatures.AreaOfInterest([[0, 0, 0], [0, 1, 0], [1, 1, 0], [1, 0, 0]])
aoi_3D_B = AOIFeatures.AreaOfInterest([[1, 1, 0], [1, 2, 0], [2, 2, 0], [2, 1, 0]])
aoi_3d_scene = AOI3DScene.AOI3DScene({"A": aoi_3D_A, "B": aoi_3D_B})
# Check full copy
aoi_3d_scene_copy = aoi_3d_scene.copy()
self.assertEqual(aoi_3d_scene_copy.dimension, 3)
self.assertEqual(len(aoi_3d_scene_copy.items()), 2)
self.assertEqual(list(aoi_3d_scene_copy.keys()), ["A", "B"])
# Check cpy with exclusion
aoi_3d_scene_copy = aoi_3d_scene.copy(exclude=["B"])
self.assertEqual(aoi_3d_scene_copy.dimension, 3)
self.assertEqual(len(aoi_3d_scene_copy.items()), 1)
self.assertEqual(list(aoi_3d_scene_copy.keys()), ["A"])
if __name__ == '__main__':
unittest.main()
|