Skip to content
Snippets Groups Projects
Commit 5473c8d3 authored by Olivier Bertrand's avatar Olivier Bertrand
Browse files

Update blender renderer

Rename test file for clarity
parent 907dd41f
No related branches found
No related tags found
No related merge requests found
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)
"""
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)
"""
Unittesting under blender
"""
import unittest
import numpy as np
from navipy.sensors.renderer import BlenderRender 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): class TestBlenderRender_renderer(unittest.TestCase):
@classmethod def setUp(self):
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): Prepare for the test
# Should be an integer """
self.cyberbee.cycle_samples = 0.1 convention = 'rxyz'
with self.assertRaises(TypeError): index = pd.MultiIndex.from_tuples(
# Should be a tuple list or np.ndarray [('location', 'x'), ('location', 'y'),
self.cyberbee.camera_fov = 'bla' ('location', 'z'), (convention, 'alpha_0'),
with self.assertRaises(TypeError): (convention, 'alpha_1'), (convention, 'alpha_2')])
# Should be a float or int, so not a complex self.posorient = pd.Series(index=index)
self.cyberbee.camera_gaussian_width = 4 + 4j self.posorient.loc['location']['x'] = 0
with self.assertRaises(TypeError): self.posorient.loc['location']['y'] = 0
# Should be a tuple, list or nd.array self.posorient.loc['location']['z'] = 1
self.cyberbee.camera_resolution = 'bla' 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): self.renderer = BlenderRender()
""" Test set/get match self.image_ref = self.renderer.scene(self.posorient)
* camera_rotation_mode def test_diff_euler_xyz2yzx(self):
* cycle_samples
* camera_fov
* camera_gaussian_width
* camera_resolution
""" """
# camera cycle_samples Test if images rendered from two different conventions match \
val = 100 one another
self.cyberbee.cycle_samples = val """
self.assertEqual(val, self.cyberbee.cycle_samples) convention = 'ryzx'
# camera fov index = pd.MultiIndex.from_tuples(
val = np.array([[-90, 90], [-180, 180]]) [('location', 'x'), ('location', 'y'),
self.cyberbee.camera_fov = val ('location', 'z'), (convention, 'alpha_0'),
np.testing.assert_allclose(val, self.cyberbee.camera_fov) (convention, 'alpha_1'), (convention, 'alpha_2')])
# camera gaussian posorient2 = pd.Series(index=index)
val = 1.5 posorient2.loc['location'][:] = self.posorient.loc['location'][:]
self.cyberbee.gaussian_width = val # An orientation matrix need to be calculated from
self.assertEqual(val, self.cyberbee.gaussian_width) # the euler angle of the convention of 'reference'
# camera resolution # so that it can be decompase in another convention
val = np.array([360, 180]) at, bt, ct = from_matrix(self.matorient, axes=convention)
self.cyberbee.camera_resolution = val posorient2.loc[convention] = [at, bt, ct]
np.testing.assert_allclose(val, self.cyberbee.camera_resolution) 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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment