From 5473c8d34ac7e7d774461ea97972e93f89aa8ffc Mon Sep 17 00:00:00 2001
From: "Olivier J.N. Bertrand" <olivier.bertrand@uni-bielefeld.de>
Date: Wed, 18 Apr 2018 19:28:23 +0200
Subject: [PATCH] Update blender renderer

Rename test file for clarity
---
 navipy/sensors/blendtest1.py         |  69 ----------------
 navipy/sensors/blendtest_api.py      |  60 ++++++++++++++
 navipy/sensors/blendtest_renderer.py | 115 +++++++++++++++------------
 3 files changed, 122 insertions(+), 122 deletions(-)
 delete mode 100644 navipy/sensors/blendtest1.py
 create mode 100644 navipy/sensors/blendtest_api.py

diff --git a/navipy/sensors/blendtest1.py b/navipy/sensors/blendtest1.py
deleted file mode 100644
index a02c335..0000000
--- a/navipy/sensors/blendtest1.py
+++ /dev/null
@@ -1,69 +0,0 @@
-from navipy.sensors.renderer import BlenderRender
-from navipy.maths.euler import matrix, from_matrix
-from navipy.maths.quaternion import from_matrix as quat_matrix
-import pandas as pd
-import numpy as np
-import unittest
-
-
-class TestCase(unittest.TestCase):
-    def setUp(self):
-        """
-        Prepare for the test
-        """
-        convention = 'rxyz'
-        index = pd.MultiIndex.from_tuples(
-            [('location', 'x'), ('location', 'y'),
-             ('location', 'z'), (convention, 'alpha_0'),
-             (convention, 'alpha_1'), (convention, 'alpha_2')])
-        self.posorient = pd.Series(index=index)
-        self.posorient.loc['location']['x'] = 0
-        self.posorient.loc['location']['y'] = 0
-        self.posorient.loc['location']['z'] = 1
-        self.posorient.loc[convention]['alpha_0'] = np.pi/4
-        self.posorient.loc[convention]['alpha_1'] = np.pi/7
-        self.posorient.loc[convention]['alpha_2'] = np.pi/3
-
-        convention = self.posorient.index.get_level_values(0)[-1]
-        a, b, c = self.posorient.loc[convention]
-        self.matorient = matrix(a, b, c, axes=convention)
-
-        self.renderer = BlenderRender()
-        self.image_ref = self.renderer.scene(self.posorient)
-
-    def test_diff_euler_xyz2yzx(self):
-        """
-        Test if images rendered from two different conventions match \
-        one another
-        """
-        convention = 'ryzx'
-        index = pd.MultiIndex.from_tuples(
-            [('location', 'x'), ('location', 'y'),
-             ('location', 'z'), (convention, 'alpha_0'),
-             (convention, 'alpha_1'), (convention, 'alpha_2')])
-        posorient2 = pd.Series(index=index)
-        posorient2.loc['location'][:] = self.posorient.loc['location'][:]
-        # An orientation matrix need to be calculated from
-        # the euler angle of the convention of 'reference'
-        # so that it can be decompase in another convention
-        at, bt, ct = from_matrix(self.matorient, axes=convention)
-        posorient2.loc[convention] = [at, bt, ct]
-        image2 = self.renderer.scene(posorient2)
-        np.testing.assert_allclose(image2, self.image_ref)
-
-    def test_euler_xyz_2_quaternion(self):
-        convention = 'quaternion'
-        index = pd.MultiIndex.from_tuples(
-            [('location', 'x'), ('location', 'y'),
-             ('location', 'z'), (convention, 'q_0'),
-             (convention, 'q_1'), (convention, 'q_2'), (convention, 'q_3')],
-            names=['position', 'orientation'])
-        posorient2 = pd.Series(index=index)
-        posorient2.loc['location'][:] = self.posorient.loc['location'][:]
-        # An orientation matrix need to be calculated from
-        # the euler angle of the convention of 'reference'
-        # so that it can be decompase in another convention
-        at, bt, ct, dt = quat_matrix(self.matorient)
-        posorient2.loc[convention] = [at, bt, ct, dt]
-        image2 = self.renderer.scene(posorient2)
-        np.testing.assert_allclose(image2, self.image_ref, atol=1.2)
diff --git a/navipy/sensors/blendtest_api.py b/navipy/sensors/blendtest_api.py
new file mode 100644
index 0000000..37fd405
--- /dev/null
+++ b/navipy/sensors/blendtest_api.py
@@ -0,0 +1,60 @@
+"""
+ Unittesting under blender
+"""
+import unittest
+import numpy as np
+from navipy.sensors.renderer import BlenderRender
+
+
+class TestBlenderRender_api(unittest.TestCase):
+    @classmethod
+    def setUpClass(self):
+        self.cyberbee = BlenderRender()
+
+    def test_class_assigments_error(self):
+        """ Test that error are correctly raised
+        List of tested function:
+        * camera_rotation_mode
+        * cycle_samples
+        * camera_fov
+        * camera_gaussian_width
+        * camera_resolution
+        """
+        with self.assertRaises(TypeError):
+            # Should be an integer
+            self.cyberbee.cycle_samples = 0.1
+        with self.assertRaises(TypeError):
+            # Should be a tuple list or np.ndarray
+            self.cyberbee.camera_fov = 'bla'
+        with self.assertRaises(TypeError):
+            # Should be a float or int, so not a complex
+            self.cyberbee.camera_gaussian_width = 4 + 4j
+        with self.assertRaises(TypeError):
+            # Should be a tuple, list or nd.array
+            self.cyberbee.camera_resolution = 'bla'
+
+    def test_class_assigments(self):
+        """ Test set/get match
+
+        * camera_rotation_mode
+        * cycle_samples
+        * camera_fov
+        * camera_gaussian_width
+        * camera_resolution
+        """
+        # camera cycle_samples
+        val = 100
+        self.cyberbee.cycle_samples = val
+        self.assertEqual(val, self.cyberbee.cycle_samples)
+        # camera fov
+        val = np.array([[-90, 90], [-180, 180]])
+        self.cyberbee.camera_fov = val
+        np.testing.assert_allclose(val, self.cyberbee.camera_fov)
+        # camera gaussian
+        val = 1.5
+        self.cyberbee.gaussian_width = val
+        self.assertEqual(val, self.cyberbee.gaussian_width)
+        # camera resolution
+        val = np.array([360, 180])
+        self.cyberbee.camera_resolution = val
+        np.testing.assert_allclose(val, self.cyberbee.camera_resolution)
diff --git a/navipy/sensors/blendtest_renderer.py b/navipy/sensors/blendtest_renderer.py
index fd8af4f..c4b3b49 100644
--- a/navipy/sensors/blendtest_renderer.py
+++ b/navipy/sensors/blendtest_renderer.py
@@ -1,60 +1,69 @@
-"""
- Unittesting under blender
-"""
-import unittest
-import numpy as np
 from navipy.sensors.renderer import BlenderRender
+from navipy.maths.euler import matrix, from_matrix
+from navipy.maths.quaternion import from_matrix as quat_matrix
+import pandas as pd
+import numpy as np
+import unittest
 
 
-class TestBlenderRender(unittest.TestCase):
-    @classmethod
-    def setUpClass(self):
-        self.cyberbee = BlenderRender()
-
-    def test_class_assigments_error(self):
-        """ Test that error are correctly raised
-        List of tested function:
-        * camera_rotation_mode
-        * cycle_samples
-        * camera_fov
-        * camera_gaussian_width
-        * camera_resolution
+class TestBlenderRender_renderer(unittest.TestCase):
+    def setUp(self):
         """
-        with self.assertRaises(TypeError):
-            # Should be an integer
-            self.cyberbee.cycle_samples = 0.1
-        with self.assertRaises(TypeError):
-            # Should be a tuple list or np.ndarray
-            self.cyberbee.camera_fov = 'bla'
-        with self.assertRaises(TypeError):
-            # Should be a float or int, so not a complex
-            self.cyberbee.camera_gaussian_width = 4 + 4j
-        with self.assertRaises(TypeError):
-            # Should be a tuple, list or nd.array
-            self.cyberbee.camera_resolution = 'bla'
+        Prepare for the test
+        """
+        convention = 'rxyz'
+        index = pd.MultiIndex.from_tuples(
+            [('location', 'x'), ('location', 'y'),
+             ('location', 'z'), (convention, 'alpha_0'),
+             (convention, 'alpha_1'), (convention, 'alpha_2')])
+        self.posorient = pd.Series(index=index)
+        self.posorient.loc['location']['x'] = 0
+        self.posorient.loc['location']['y'] = 0
+        self.posorient.loc['location']['z'] = 1
+        self.posorient.loc[convention]['alpha_0'] = np.pi/4
+        self.posorient.loc[convention]['alpha_1'] = np.pi/7
+        self.posorient.loc[convention]['alpha_2'] = np.pi/3
+
+        convention = self.posorient.index.get_level_values(0)[-1]
+        a, b, c = self.posorient.loc[convention]
+        self.matorient = matrix(a, b, c, axes=convention)
 
-    def test_class_assigments(self):
-        """ Test set/get match
+        self.renderer = BlenderRender()
+        self.image_ref = self.renderer.scene(self.posorient)
 
-        * camera_rotation_mode
-        * cycle_samples
-        * camera_fov
-        * camera_gaussian_width
-        * camera_resolution
+    def test_diff_euler_xyz2yzx(self):
         """
-        # camera cycle_samples
-        val = 100
-        self.cyberbee.cycle_samples = val
-        self.assertEqual(val, self.cyberbee.cycle_samples)
-        # camera fov
-        val = np.array([[-90, 90], [-180, 180]])
-        self.cyberbee.camera_fov = val
-        np.testing.assert_allclose(val, self.cyberbee.camera_fov)
-        # camera gaussian
-        val = 1.5
-        self.cyberbee.gaussian_width = val
-        self.assertEqual(val, self.cyberbee.gaussian_width)
-        # camera resolution
-        val = np.array([360, 180])
-        self.cyberbee.camera_resolution = val
-        np.testing.assert_allclose(val, self.cyberbee.camera_resolution)
+        Test if images rendered from two different conventions match \
+        one another
+        """
+        convention = 'ryzx'
+        index = pd.MultiIndex.from_tuples(
+            [('location', 'x'), ('location', 'y'),
+             ('location', 'z'), (convention, 'alpha_0'),
+             (convention, 'alpha_1'), (convention, 'alpha_2')])
+        posorient2 = pd.Series(index=index)
+        posorient2.loc['location'][:] = self.posorient.loc['location'][:]
+        # An orientation matrix need to be calculated from
+        # the euler angle of the convention of 'reference'
+        # so that it can be decompase in another convention
+        at, bt, ct = from_matrix(self.matorient, axes=convention)
+        posorient2.loc[convention] = [at, bt, ct]
+        image2 = self.renderer.scene(posorient2)
+        np.testing.assert_allclose(image2, self.image_ref)
+
+    def test_euler_xyz_2_quaternion(self):
+        convention = 'quaternion'
+        index = pd.MultiIndex.from_tuples(
+            [('location', 'x'), ('location', 'y'),
+             ('location', 'z'), (convention, 'q_0'),
+             (convention, 'q_1'), (convention, 'q_2'), (convention, 'q_3')],
+            names=['position', 'orientation'])
+        posorient2 = pd.Series(index=index)
+        posorient2.loc['location'][:] = self.posorient.loc['location'][:]
+        # An orientation matrix need to be calculated from
+        # the euler angle of the convention of 'reference'
+        # so that it can be decompase in another convention
+        at, bt, ct, dt = quat_matrix(self.matorient)
+        posorient2.loc[convention] = [at, bt, ct, dt]
+        image2 = self.renderer.scene(posorient2)
+        np.testing.assert_allclose(image2, self.image_ref, atol=1.2)
-- 
GitLab