aboutsummaryrefslogtreecommitdiff
path: root/src/argaze.test/AreaOfInterest/AOI3DScene.py
blob: 5a575bbf22e0e186d656e6262f2a024a03c42f0e (plain)
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
#!/usr/bin/env python

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_load(self):
        """Test AOI3DScene load method."""

        aoi_3d_scene_tt = AOI3DScene.AOI3DScene()

        current_directory = os.path.dirname(os.path.abspath(__file__))
        aoi_3d_scene_tt.load(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]]))


if __name__ == '__main__':

    unittest.main()