def test_local_transform(self): R = moveable._rotation_matrix_from_angles(*self.rotation_angles, dummy_dimension=True) T = moveable._translation_matrix_from_vector(self.translation) L_ref = np.dot(T, R) L_ans = self.PAS.local_transform np.testing.assert_array_almost_equal(L_ref, L_ans)
def test_translation_matrix_from_vector(): x = np.random.randint(0, 5, size=(3)) y = np.random.randint(0, 5, size=(3)) yp = np.ones(4) yp[:3] = y T = moveable._translation_matrix_from_vector(x) assert np.all(np.dot(T, yp)[:3] == x + y) assert np.dot(T, yp)[3] == 1.0
def test_translation_matrix_from_vector(): x = np.random.randint(0,5,size=(3)) y = np.random.randint(0,5,size=(3)) yp = np.ones(4) yp[:3] = y T = moveable._translation_matrix_from_vector(x) assert np.all(np.dot(T, yp)[:3] == x + y) assert np.dot(T, yp)[3] == 1.0
def test_xyz(self): uxyz = self.PAS.untransformed_xyz buff = np.ones(list(uxyz.shape[:-1]) + [1], dtype=uxyz.dtype) uxyzd = np.concatenate([uxyz, buff], axis=-1) R = moveable._rotation_matrix_from_angles(*self.rotation_angles, dummy_dimension=True) T = moveable._translation_matrix_from_vector(self.translation) xyz_ans = np.dot(uxyzd, np.dot(T, R).T) np.testing.assert_array_almost_equal(self.PAS.xyz, xyz_ans[..., :3])
def test_xyz(self): uxyz = self.PAS.untransformed_xyz buff = np.ones( list(uxyz.shape[:-1]) + [1], dtype=uxyz.dtype) uxyzd = np.concatenate([uxyz, buff], axis=-1) R = moveable._rotation_matrix_from_angles(*self.rotation_angles, dummy_dimension=True) T = moveable._translation_matrix_from_vector(self.translation) xyz_ans = np.dot(uxyzd, np.dot(T, R).T) np.testing.assert_array_almost_equal(self.PAS.xyz, xyz_ans[...,:3])
def test_global_transform(self): ra_p = np.random.rand(3) * 360.0 t_p = np.random.randn(3) Rp = moveable._rotation_matrix_from_angles(*ra_p, dummy_dimension=True) Tp = moveable._translation_matrix_from_vector(t_p) parent_obj = camera.CompoundCamera(type_name='daddy', id_num=0, parent=None, rotation_angles=ra_p, translation=t_p) self.PAS.set_parent(parent_obj) R = moveable._rotation_matrix_from_angles(*self.rotation_angles, dummy_dimension=True) T = moveable._translation_matrix_from_vector(self.translation) G_ref = np.dot( np.dot( np.dot(Tp, Rp), T), R) # T_1 . R_1 . T_2 . R_2 G_ans = self.PAS.global_transform np.testing.assert_array_almost_equal(G_ref, G_ans)
def test_global_transform(self): ra_p = np.random.rand(3) * 360.0 t_p = np.random.randn(3) Rp = moveable._rotation_matrix_from_angles(*ra_p, dummy_dimension=True) Tp = moveable._translation_matrix_from_vector(t_p) parent_obj = camera.CompoundCamera(type_name='daddy', id_num=0, parent=None, rotation_angles=ra_p, translation=t_p) self.PAS.set_parent(parent_obj) R = moveable._rotation_matrix_from_angles(*self.rotation_angles, dummy_dimension=True) T = moveable._translation_matrix_from_vector(self.translation) G_ref = np.dot(np.dot(np.dot(Tp, Rp), T), R) # T_1 . R_1 . T_2 . R_2 G_ans = self.PAS.global_transform np.testing.assert_array_almost_equal(G_ref, G_ans)
def test_evaluate_transform(self): # for rotation x = np.array([[1.0, 0.0, 0.0]]) # vector pointing at x Rz = moveable._rotation_matrix_from_angles(90.0, 0.0, 0.0, dummy_dimension=True) ref = np.array([[0.0, 1.0, 0.0]]) ans = camera.CompoundCamera._evaluate_transform(Rz, x) np.testing.assert_array_almost_equal(ans, ref, err_msg='rotation') # for translation x = np.random.randint(0,5,size=(1,3)) y = np.random.randint(0,5,size=(1,3)) T = moveable._translation_matrix_from_vector(x) assert np.all( camera.CompoundCamera._evaluate_transform(T, y) == x + y )
def test_evaluate_transform(self): # for rotation x = np.array([[1.0, 0.0, 0.0]]) # vector pointing at x Rz = moveable._rotation_matrix_from_angles(90.0, 0.0, 0.0, dummy_dimension=True) ref = np.array([[0.0, 1.0, 0.0]]) ans = camera.CompoundCamera._evaluate_transform(Rz, x) np.testing.assert_array_almost_equal(ans, ref, err_msg='rotation') # for translation x = np.random.randint(0, 5, size=(1, 3)) y = np.random.randint(0, 5, size=(1, 3)) T = moveable._translation_matrix_from_vector(x) assert np.all(camera.CompoundCamera._evaluate_transform(T, y) == x + y)