From 8e4d7a014fafe5e35e23ba391f72b09093300d7b Mon Sep 17 00:00:00 2001 From: "lodenthal@uni-bielefeld.de" <lodenthal@uni-bielefeld.de> Date: Thu, 12 Apr 2018 13:42:19 +0300 Subject: [PATCH] uploaded convention tests for blender, but still not working --- navipy/sensors/blendtest1.py | 158 +++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 navipy/sensors/blendtest1.py diff --git a/navipy/sensors/blendtest1.py b/navipy/sensors/blendtest1.py new file mode 100644 index 0000000..51ade5f --- /dev/null +++ b/navipy/sensors/blendtest1.py @@ -0,0 +1,158 @@ +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 os +import sys +import unittest + + +class TestCase(unittest.TestCase): + def setUp(self): + self.i = [np.array(['location', 'location', 'location', + 'sxyz', 'sxyz', 'sxyz']), + np.array(['x', 'y', 'z', + 'alpha_0', 'alpha_1', 'alpha_2'])] + self.i2 = [np.array(['location', 'location', 'location', + 'syzx', 'syzx', 'syzx']), + np.array(['x', 'y', 'z', 'alpha_0', + 'alpha_1', 'alpha_2'])] + self.image2 = np.zeros((4, 180, 360, 4, 1)) + self.posorient2 = pd.Series(index=self.i2) + self.posorient2.loc['location']['x'] = 0 + self.posorient2.loc['location']['y'] = 0 + self.posorient2.loc['location']['z'] = 0 + self.posorient2.loc['syzx']['alpha_0'] = 0 + self.posorient2.loc['syzx']['alpha_1'] = 0 + self.posorient2.loc['syzx']['alpha_2'] = 0 + + self.a = 1 + self.b = 0.75 + self.c = 0.5 + + self.posorient = pd.Series(index=self.i) + self.posorient.loc['location']['x'] = 0 + self.posorient.loc['location']['y'] = 0 + self.posorient.loc['location']['z'] = 0 + self.posorient.loc['sxyz']['alpha_0'] = self.a + self.posorient.loc['sxyz']['alpha_1'] = self.b + self.posorient.loc['sxyz']['alpha_2'] = self.c + + def test_diff_euler_xyz2yzx(self): + # print("euler test") + logfile = 'blender_render.log' + open(logfile, 'a').close() + old = os.dup(1) + sys.stdout.flush() + os.close(1) + os.open(logfile, os.O_WRONLY) + + renderer = BlenderRender() + renderer2 = BlenderRender() + mat1 = matrix(self.a, self.b, self.c, axes='sxyz') + a1, a2, a3 = from_matrix(mat1, axes='sxyz') + + at, bt, ct = from_matrix(mat1, axes='syzx') + + self.posorient2.loc['syzx']['alpha_0'] = at + self.posorient2.loc['syzx']['alpha_1'] = bt + self.posorient2.loc['syzx']['alpha_2'] = ct + # renderer.camera_rotation_mode = 'YZX' + # print("poorient ### ",self.posorient2.loc[['syzx'], + # ['alpha_0', 'alpha_1', 'alpha_2']].values) + self.image2[0] = renderer2.scene(self.posorient2) + # conv = renderer2.camera_rotation_mode + + # self.posorient.loc['sxyz']['alpha_0'] = a + # self.posorient.loc['sxyz']['alpha_1'] = b + # self.posorient.loc['sxyz']['alpha_2'] = c + # print("poorient ### ",posorient.loc[['sxyz'], + # ['alpha_0', 'alpha_1', 'alpha_2']].values) + # renderer.camera_rotation_mode = 'XYZ' + self.image2[1] = renderer.scene(self.posorient) + + # disable output redirection + os.close(1) + os.dup(old) + os.close(old) + # print("first image") + # print(self.image[0,:,0,0] - self.image[1,:,0,0]) + # print("second image") + # print(self.image[1,:,0,0]) + # conv2= renderer.camera_rotation_mode + # print("angels xyz",a1,a2,a3,"angles yzx",at,bt,ct) + # print("sh be yzx",conv,"sh be xyz",conv2) + # print(np.sum(np.abs(image2[0,:,:,0]-image2[1,:,:,0]))) + # print("max diff ",np.max(np.abs(self.image2[0]-self.image2[1]))) + # assert np.testing,assert_allclose(self.image[0], + # self.image[1], atol = 0.007) + + def test_euler_xyz_2_quaternion(self): + # print("quaternion test") + logfile = 'blender_render.log' + open(logfile, 'a').close() + old = os.dup(1) + sys.stdout.flush() + os.close(1) + os.open(logfile, os.O_WRONLY) + + i2 = [np.array(['location', 'location', 'location', + 'quaternion', 'quaternion', 'quaternion', + 'quaternion']), + np.array(['x', 'y', 'z', 'q_0', 'q_1', 'q_2', 'q_3'])] + renderer = BlenderRender() + renderer2 = BlenderRender() + + mat1 = matrix(self.a, self.b, self.c, axes='sxyz') + at, bt, ct, dt = quat_matrix(mat1) + + posorient2 = pd.Series(index=i2) + posorient2.loc['location']['x'] = 0 + posorient2.loc['location']['y'] = 0 + posorient2.loc['location']['z'] = 0 + posorient2.loc['quaternion']['q_0'] = at + posorient2.loc['quaternion']['q_1'] = bt + posorient2.loc['quaternion']['q_2'] = ct + posorient2.loc['quaternion']['q_3'] = dt + # renderer.camera_rotation_mode = 'YZX' + # print("poorient ### ",posorient2.loc[['quternion'], + # ['q_0', 'q_1', + # 'q_2', 'q_3']].values) + self.image2[2] = renderer2.scene(posorient2) + # conv = renderer2.camera_rotation_mode + + # self.posorient = pd.Series(index=self.i) + + # self.posorient.loc['sxyz']['alpha_0'] = a + # self.posorient.loc['sxyz']['alpha_1'] = b + # self.posorient.loc['sxyz']['alpha_2'] = c + # print("poorient ### ",self.posorient.loc[['sxyz'], + # ['alpha_0', 'alpha_1', 'alpha_2']].values) + # renderer.camera_rotation_mode = 'XYZ' + self.image2[3] = renderer.scene(self.posorient) + + # disable output redirection + os.close(1) + os.dup(old) + os.close(old) + + # print(self.image2[2,:,0,0] - self.image2[3,:,0,0]) + # print("max diff ",np.max(np.abs(self.image2[2]-self.image2[3]))) + # print("alternative"); + # indices = np.where(np.abs(self.image2[0,:,:,0] - + # self.image2[1,:,:,0]) + # ==np.max(np.abs(self.image2[0,:,:,0] + # - self.image2[1,:,:,0]))) + # print("indices", indices) + # print("first image") + # print(self.image[0,0,:,0]) + # print("second image") + # print(self.image[1,0,:,0]) + # conv2= renderer.camera_rotation_mode + # print("angels xyz",a,b,c,"angles yzx",at,bt,ct) + # print("sh be yzx",conv,"sh be xyz",conv2) + # print(np.sum(np.abs(self.image[0,:,:,0]-self.image[1,:,:,0]))) + # print(np.all(np.isclose(self.image[0], self.image[1]))) + # assert np.testing.assert_allclose(self.image[0], + # self.image[1], atol = 0.007) -- GitLab