def test_rodriguesToRotationMatrix(): RES = np.array([[0.50017235, -0.80049871, 0.33019604], [0.80739289, 0.56894174, 0.15627544], [-0.3129606, 0.18843328, 0.9308859]]) R = gtr._rodriguesToRotationMatrix(TEST_UVEC, TEST_ANGLE) # assess rotation matrix properties: # detR = +=1 nt.assert_almost_equal(np.linalg.det(R), 1.) # R.T = R^-1 nt.assert_true(np.allclose(np.linalg.inv(R), R.transpose())) # check against calculated matrix nt.assert_true(np.allclose(R, RES)) # check if opposite sign generates inverse Rinv = gtr._rodriguesToRotationMatrix(TEST_UVEC, -TEST_ANGLE) nt.assert_true(np.allclose(np.dot(Rinv, R), np.identity(3))) # check basic rotations with a range of angles for angle in np.linspace(0., 2. * np.pi, 10): Rx = gtr._rodriguesToRotationMatrix(np.array([1., 0., 0.]), angle) Ry = gtr._rodriguesToRotationMatrix(np.array([0., 1., 0.]), angle) Rz = gtr._rodriguesToRotationMatrix(np.array([0., 0., 1.]), angle) nt.assert_true(np.allclose(Rx, _Rx(angle))) nt.assert_true(np.allclose(Ry, _Ry(angle))) nt.assert_true(np.allclose(Rz, _Rz(angle)))
def test_affineTransformPoint(): point = TREE.value[:COLS.R] # rotate 180 and translate, translate back and rotate 180 # change origin as well m = copy(point) R = gtr._rodriguesToRotationMatrix(TEST_UVEC, 2. * np.pi) gtr._affineTransformPoint(m, R, np.zeros(3)) nt.assert_true(np.allclose(point, m)) new_orig = np.array([10. , 45., 50.]) t = np.array([0.1, - 0.1, 40.3]) R = gtr._rodriguesToRotationMatrix(TEST_UVEC, np.pi) m = copy(point) # change origin, rotate 180 and translate gtr._affineTransformPoint(m, R, t, origin=new_orig) # translate back gtr._affineTransformPoint(m, np.identity(3), -t, origin=np.zeros(3)) # rotate back gtr._affineTransformPoint(m, R, np.zeros(3), origin=new_orig) nt.assert_true(np.allclose(point, m))
def test_affineTransformNeuron(): # rotate 180 and translate, translate back and rotate 180 # change origin as well new_orig = np.array([10. , 45., 50.]) t = np.array([0.1, - 0.1, 40.3]) R = gtr._rodriguesToRotationMatrix(TEST_UVEC, np.pi) m = NEURON.copy() # change origin, rotate 180 and translate gtr._affineTransformNeuron(m, R, t, origin=new_orig) # translate back gtr._affineTransformNeuron(m, np.identity(3), -t, origin=np.zeros(3)) # rotate back gtr._affineTransformNeuron(m, R, np.zeros(3), origin=new_orig) nt.assert_true(np.allclose(list(m.soma.iter()), list(NEURON.soma.iter()))) for neu1, neu2 in izip(NEURON.neurites, m.neurites): _evaluate(neu1, neu2, lambda x, y: np.allclose(x, y))
def test_rotate_tree(): m = gtr.rotate(TREE, TEST_UVEC, TEST_ANGLE) R = gtr._rodriguesToRotationMatrix(TEST_UVEC, TEST_ANGLE) # rotation matrix inverse equals its transpose Rinv = R.transpose() # check that if the inverse rotation on the rotated result returns # the initial coordinates _evaluate(TREE, m, lambda x, y: np.allclose(np.dot(Rinv, y), x) ) # check with origin new_orig = np.array([-50., 45., 30.]) m = gtr.rotate(TREE, TEST_UVEC, TEST_ANGLE, origin=new_orig) m = gtr.rotate(m, TEST_UVEC, -TEST_ANGLE, origin=new_orig) _evaluate(TREE, m, lambda x, y: np.allclose(x, y) )
def test_affineTransformTree(): # rotate 180 and translate, translate back and rotate 180 # change origin as well new_orig = np.array([10. , 45., 50.]) t = np.array([0.1, - 0.1, 40.3]) R = gtr._rodriguesToRotationMatrix(TEST_UVEC, np.pi) # change origin, rotate 180 and translate m = make_copy(TREE) gtr._affineTransformTree(m, R, t, origin=new_orig) # translate back gtr._affineTransformTree(m, np.identity(3), -t, origin=np.zeros(3)) # rotate back gtr._affineTransformTree(m, R, np.zeros(3), origin=new_orig) _evaluate(TREE, m, lambda x, y: np.allclose(x, y))