def test_sample_locations_between_surfaces(depth, n_points): inner = flat_mesh(5, 7) outer = inner[0] + [0., 0., 1.], inner[1] locations = surface._sample_locations_between_surfaces( outer, inner, np.eye(4), n_points=n_points, depth=depth) if depth is None: # can be simplified when we drop support for np 1.15 # (broadcasting linspace) expected = np.asarray( [np.linspace(b, a, n_points) for (a, b) in zip(inner[0].ravel(), outer[0].ravel())]) expected = np.rollaxis( expected.reshape((*outer[0].shape, n_points)), 2, 1) else: offsets = ([[0., 0., - z] for z in depth]) expected = np.asarray([vertex + offsets for vertex in outer[0]]) assert np.allclose(locations, expected)
N_T = 10 u, v = np.mgrid[:N_T, :N_Z] triangulation = matplotlib.tri.Triangulation(u.flatten(), v.flatten()) angles = u.flatten() * 2 * np.pi / N_T x, y = np.cos(angles), np.sin(angles) z = v.flatten() * 2 / N_Z mesh = [np.asarray([x, y, z]).T, triangulation.triangles] inner_mesh = [[.7, .7, 1.] * mesh[0], triangulation.triangles] ######################################################################### # Get the locations from which vol_to_surf would draw its samples ######################################################################### nested_sample_points = surface._sample_locations_between_surfaces( mesh, inner_mesh, np.eye(4)) line_sample_points = surface._line_sample_locations( mesh, np.eye(4), segment_half_width=.2, n_points=6) ball_sample_points = surface._ball_sample_locations( mesh, np.eye(4), ball_radius=.15, n_points=20) ###################################################################### # Plot the mesh and the sample locations ###################################################################### fig = plt.figure() ax = plt.subplot(projection='3d') ax.view_init(67, -42)