diff options
Diffstat (limited to 'src/argaze.test/AreaOfInterest/AOI3DScene.py')
-rw-r--r-- | src/argaze.test/AreaOfInterest/AOI3DScene.py | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/argaze.test/AreaOfInterest/AOI3DScene.py b/src/argaze.test/AreaOfInterest/AOI3DScene.py new file mode 100644 index 0000000..5a575bb --- /dev/null +++ b/src/argaze.test/AreaOfInterest/AOI3DScene.py @@ -0,0 +1,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()
\ No newline at end of file |