def test_surface(): import math import random from scipy.spatial import Delaunay size = 11 vertices = list() for i in range(-size, size): for j in range(-size, size): fact1 = - math.sin(i) * math.cos(j) fact2 = - math.exp(abs(1 - math.sqrt(i ** 2 + j ** 2) / math.pi)) z_coord = -abs(fact1 * fact2) vertices.append([i, j, z_coord]) c_arr = np.random.rand(len(vertices), 3) random.shuffle(vertices) vertices = np.array(vertices) tri = Delaunay(vertices[:, [0, 1]]) faces = tri.simplices c_loop = [None, c_arr] f_loop = [None, faces] s_loop = [None, "butterfly", "loop"] for smooth_type in s_loop: for face in f_loop: for color in c_loop: scene = window.Scene(background=(1, 1, 1)) surface_actor = actor.surface(vertices, faces=face, colors=color, smooth=smooth_type) scene.add(surface_actor) # window.show(scene, size=(600, 600), reset_camera=False) arr = window.snapshot(scene, 'test_surface.png', offscreen=True) report = window.analyze_snapshot(arr, find_objects=True) npt.assert_equal(report.objects, 1)
def _generate_surface(): size = 11 vertices = list() for i in range(-size, size): for j in range(-size, size): fact1 = -math.sin(i) * math.cos(j) fact2 = -math.exp(abs(1 - math.sqrt(i**2 + j**2) / math.pi)) z_coord = -abs(fact1 * fact2) vertices.append([i, j, z_coord]) c_arr = np.random.rand(len(vertices), 3) random.shuffle(vertices) vertices = np.array(vertices) tri = Delaunay(vertices[:, [0, 1]]) faces = tri.simplices c_loop = [None, c_arr] f_loop = [None, faces] s_loop = [None, "butterfly", "loop"] for smooth_type in s_loop: for face in f_loop: for color in c_loop: surface_actor = actor.surface(vertices, faces=face, colors=color, smooth=smooth_type) return surface_actor
def create_surface(x, y, equation, colormap_name): xyz, colors = update_surface(x, y, equation=equation, cmap_name=colormap_name) surf = actor.surface(xyz, colors=colors) surf.equation = equation surf.cmap_name = colormap_name surf.vertices = utils.vertices_from_actor(surf) surf.no_vertices_per_point = len(surf.vertices)/npoints**2 surf.initial_vertices = surf.vertices.copy() - \ np.repeat(xyz, surf.no_vertices_per_point, axis=0) return surf
def test_update_surface_actor_colors(): x = np.linspace(-1, 1, 20) y = np.linspace(-1, 1, 20) x, y = np.meshgrid(x, y) x = x.reshape(-1) y = y.reshape(-1) z = x**2 + y**2 colors = np.array([[0.2, 0.4, 0.8]] * 400) xyz = np.vstack([x, y, z]).T act = actor.surface(xyz) update_surface_actor_colors(act, colors) # Multiplying colors by 255 to convert them into RGB format used by VTK. colors *= 255 # colors obtained from the surface surface_colors = numpy_support.vtk_to_numpy( act.GetMapper().GetInput().GetPointData().GetScalars()) # Checking if the colors passed to the function and colors assigned are # same. npt.assert_equal(colors, surface_colors)
def plane_source2(scale=50): my_vertices = np.array([[0,0,0],[1,1,0],[0,1,0],[1,0,0]]) my_vertices = my_vertices * scale surface=actor.surface(my_vertices) return surface