Skip to content
Snippets Groups Projects
Commit 8e4d7a01 authored by Luise Odenthal's avatar Luise Odenthal
Browse files

uploaded convention tests for blender, but still not working

parent 29cac28a
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 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)
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