def test_cut_plane(): dt = np.dtype(np.float32) refx = np.array([[0,0,0],[1,0,0],[2,0,0],[3,0,0]],dtype=dt) bundlex = [np.array([[0.5,1,0],[1.5,2,0],[2.5,3,0]],dtype=dt), np.array([[0.5,2,0],[1.5,3,0],[2.5,4,0]],dtype=dt), np.array([[0.5,1,1],[1.5,2,2],[2.5,3,3]],dtype=dt), np.array([[-0.5,2,-1],[-1.5,3,-2],[-2.5,4,-3]],dtype=dt)] expected_hit0 = [ [ 1. , 1.5 , 0. , 0.70710683, 0. ], [ 1. , 2.5 , 0. , 0.70710677, 1. ], [ 1. , 1.5 , 1.5 , 0.81649661, 2. ]] expected_hit1 = [ [ 2. , 2.5 , 0. , 0.70710677, 0. ], [ 2. , 3.5 , 0. , 0.70710677, 1. ], [ 2. , 2.5 , 2.5 , 0.81649655, 2. ]] hitx=pf.cut_plane(bundlex,refx) assert_array_almost_equal(hitx[0], expected_hit0) assert_array_almost_equal(hitx[1], expected_hit1) # check that algorithm allows types other than float32 bundlex[0] = np.asarray(bundlex[0], dtype=np.float64) hitx=pf.cut_plane(bundlex,refx) assert_array_almost_equal(hitx[0], expected_hit0) assert_array_almost_equal(hitx[1], expected_hit1) refx = np.asarray(refx, dtype=np.float64) hitx=pf.cut_plane(bundlex,refx) assert_array_almost_equal( hitx[0], expected_hit0) assert_array_almost_equal( hitx[1], expected_hit1)
def test_cut_plane(): dt = np.dtype(np.float32) refx = np.array([[0, 0, 0], [1, 0, 0], [2, 0, 0], [3, 0, 0]], dtype=dt) bundlex = [ np.array([[0.5, 1, 0], [1.5, 2, 0], [2.5, 3, 0]], dtype=dt), np.array([[0.5, 2, 0], [1.5, 3, 0], [2.5, 4, 0]], dtype=dt), np.array([[0.5, 1, 1], [1.5, 2, 2], [2.5, 3, 3]], dtype=dt), np.array([[-0.5, 2, -1], [-1.5, 3, -2], [-2.5, 4, -3]], dtype=dt) ] expected_hit0 = [[1., 1.5, 0., 0.70710683, 0.], [1., 2.5, 0., 0.70710677, 1.], [1., 1.5, 1.5, 0.81649661, 2.]] expected_hit1 = [[2., 2.5, 0., 0.70710677, 0.], [2., 3.5, 0., 0.70710677, 1.], [2., 2.5, 2.5, 0.81649655, 2.]] hitx = pf.cut_plane(bundlex, refx) assert_array_almost_equal(hitx[0], expected_hit0) assert_array_almost_equal(hitx[1], expected_hit1) # check that algorithm allows types other than float32 bundlex[0] = np.asarray(bundlex[0], dtype=np.float64) hitx = pf.cut_plane(bundlex, refx) assert_array_almost_equal(hitx[0], expected_hit0) assert_array_almost_equal(hitx[1], expected_hit1) refx = np.asarray(refx, dtype=np.float64) hitx = pf.cut_plane(bundlex, refx) assert_array_almost_equal(hitx[0], expected_hit0) assert_array_almost_equal(hitx[1], expected_hit1)
def compute_cross_sections(streamlines, ref_streamline): print('Computing sections...') if not isinstance(streamlines, list): # To make sure it is as a list. streamlines = [streamlines] hits = cut_plane(streamlines, ref_streamline) hitpoints = [h[:, :3] for h in hits] # angles = [h[:, 3:] for h in hits] #We don't use it. print('---done') return hitpoints