def test_cube(): cube = pyvista.Cube() assert np.any(cube.points) assert np.any(cube.faces) bounds = (1., 3., 5., 6., 7., 8.) cube = pyvista.Cube(bounds=bounds) assert np.any(cube.points) assert np.any(cube.faces) assert np.allclose(cube.bounds, bounds)
def test_axes(): plotter = pyvista.Plotter(off_screen=True) plotter.add_axes() plotter.add_mesh(pyvista.Sphere()) plotter.show() plotter = pyvista.Plotter(off_screen=True) plotter.add_orientation_widget(pyvista.Cube()) plotter.add_mesh(pyvista.Cube()) plotter.show()
def test_multi_renderers(): plotter = pyvista.Plotter(shape=(2, 2), off_screen=OFF_SCREEN) loc = (0, 0) plotter.add_text('Render Window 0', loc=loc, font_size=30) sphere = pyvista.Sphere() plotter.add_mesh(sphere, loc=loc, scalars=sphere.points[:, 2]) plotter.add_scalar_bar('Z', vertical=True) loc = (0, 1) plotter.add_text('Render Window 1', loc=loc, font_size=30) plotter.add_mesh(pyvista.Cube(), loc=loc, show_edges=True) loc = (1, 0) plotter.add_text('Render Window 2', loc=loc, font_size=30) plotter.add_mesh(pyvista.Arrow(), color='y', loc=loc, show_edges=True) plotter.subplot(1, 1) plotter.add_text('Render Window 3', loc=loc, font_size=30) plotter.add_mesh(pyvista.Cone(), color='g', loc=loc, show_edges=True, backface_culling=True) plotter.add_bounding_box(render_lines_as_tubes=True, line_width=5) plotter.show_bounds(all_edges=True) plotter.update_bounds_axes() plotter.show() # Test subplot indices (2 rows by 1 column) plotter = pyvista.Plotter(shape=(2, 1), off_screen=OFF_SCREEN) # First row plotter.subplot(0,0) plotter.add_mesh(pyvista.Sphere()) # Second row plotter.subplot(1,0) plotter.add_mesh(pyvista.Cube()) plotter.show() # Test subplot indices (1 row by 2 columns) plotter = pyvista.Plotter(shape=(1, 2), off_screen=OFF_SCREEN) # First column plotter.subplot(0,0) plotter.add_mesh(pyvista.Sphere()) # Second column plotter.subplot(0,1) plotter.add_mesh(pyvista.Cube()) plotter.show() with pytest.raises(IndexError): # Test bad indices plotter = pyvista.Plotter(shape=(1, 2), off_screen=OFF_SCREEN) plotter.subplot(0,0) plotter.add_mesh(pyvista.Sphere()) plotter.subplot(1,0) plotter.add_mesh(pyvista.Cube()) plotter.show()
def disp_results(filename, items): pv.set_plot_theme("document") mesh = pv.PolyData(filename + '.STL') plotter = pv.Plotter() plotter.add_mesh(mesh, opacity=0.3, color='#FFFFFF') shapetypes = [ 'O ring', 'Through hole', 'Blind hole', 'Triangular passage', 'Rectangular passage', 'Circular through slot', 'Triangular through slot', 'Rectangular through slot', 'Rectangular blind slot', 'Triangular pocket', 'Rectangular pocket', 'Circular end pocket', 'Triangular blind step', 'Circular blind step', 'Rectangular blind step', 'Rectangular through step', '2-sides through step', 'Slanted through step', 'Chamfer', 'Round', 'Vertical circular end blind slot', 'Horizontal circular end blind slot', '6-sides passage', '6-sides pocket' ] colors = [ '#000080', '#FF0000', '#FFFF00', '#00BFFF', '#DC143C', '#DAA520', '#DDA0DD', '#708090', '#556B2F', '#483D8B', '#CD5C5C', '#21618C', '#1C2833', '#4169E1', '#1E90FF', '#FFD700', '#FF4500', '#646464', '#DC143C', '#98FB98', '#9370DB', '#8B4513', '#00FF00', '#008080' ] flag = np.zeros(24) for i in range(items.shape[0]): if flag[int(items[i, 6])] == 0: plotter.add_mesh(pv.Cube((0, 0, 0), 0, 0, 0, (items[i, 0], items[i, 3], items[i, 1], items[i, 4], items[i, 2], items[i, 5])), opacity=1, color=colors[int(items[i, 6])], style='wireframe', line_width=2, label=shapetypes[int(items[i, 6])]) #print(shapetypes[int(items[i,6])]) flag[int(items[i, 6])] = 1 else: plotter.add_mesh(pv.Cube((0, 0, 0), 0, 0, 0, (items[i, 0], items[i, 3], items[i, 1], items[i, 4], items[i, 2], items[i, 5])), opacity=1, color=colors[int(items[i, 6])], style='wireframe', line_width=2) plotter.add_legend() plotter.show()
def test_multi_renderers(): plotter = pyvista.Plotter(shape=(2, 2), off_screen=OFF_SCREEN) loc = (0, 0) plotter.add_text('Render Window 0', loc=loc, font_size=30) sphere = pyvista.Sphere() plotter.add_mesh(sphere, loc=loc, scalars=sphere.points[:, 2]) plotter.add_scalar_bar('Z', vertical=True) loc = (0, 1) plotter.add_text('Render Window 1', loc=loc, font_size=30) plotter.add_mesh(pyvista.Cube(), loc=loc, show_edges=True) loc = (1, 0) plotter.add_text('Render Window 2', loc=loc, font_size=30) plotter.add_mesh(pyvista.Arrow(), color='y', loc=loc, show_edges=True) plotter.subplot(1, 1) plotter.add_text('Render Window 3', loc=loc, font_size=30) plotter.add_mesh(pyvista.Cone(), color='g', loc=loc, show_edges=True, backface_culling=True) plotter.add_bounding_box(render_lines_as_tubes=True, line_width=5) plotter.show_bounds(all_edges=True) plotter.update_bounds_axes() plotter.show()
def get_img(): """Generate a screenshot of a simple pyvista mesh. Returns ------- str Local path within the static directory of the image. """ # get the user selected mesh option meshtype = request.args.get('meshtype') if meshtype == 'Sphere': mesh = pyvista.Sphere() elif meshtype == 'Cube': mesh = pyvista.Cube() elif meshtype == 'Bohemian Dome': mesh = pyvista.ParametricBohemianDome() elif meshtype == 'Cylinder': mesh = pyvista.Cylinder() else: # invalid entry raise ValueError('Invalid Option') # generate screenshot filename = f'{meshtype}.png' filepath = os.path.join(static_image_path, filename) mesh.plot(off_screen=True, window_size=(300, 300), screenshot=filepath) return os.path.join('images', filename)
def test_multi_renderers(): plotter = pyvista.Plotter(shape=(2, 2)) plotter.subplot(0, 0) plotter.add_text('Render Window 0', font_size=30) sphere = pyvista.Sphere() plotter.add_mesh(sphere, scalars=sphere.points[:, 2]) plotter.add_scalar_bar('Z', vertical=True) plotter.subplot(0, 1) plotter.add_text('Render Window 1', font_size=30) plotter.add_mesh(pyvista.Cube(), show_edges=True) plotter.subplot(1, 0) plotter.add_text('Render Window 2', font_size=30) plotter.add_mesh(pyvista.Arrow(), color='y', show_edges=True) plotter.subplot(1, 1) plotter.add_text('Render Window 3', position=(0., 0.), font_size=30, viewport=True) plotter.add_mesh(pyvista.Cone(), color='g', show_edges=True, culling=True) plotter.add_bounding_box(render_lines_as_tubes=True, line_width=5) plotter.show_bounds(all_edges=True) plotter.update_bounds_axes() plotter.show(before_close_callback=verify_cache_image)
def test_clip_box(): for i, dataset in enumerate(DATASETS): clp = dataset.clip_box(invert=True) assert clp is not None assert isinstance(clp, pyvista.UnstructuredGrid) dataset = examples.load_airplane() # test length 3 bounds result = dataset.clip_box(bounds=(900, 900, 200), invert=False) dataset = examples.load_uniform() result = dataset.clip_box(bounds=0.5) assert result.n_cells with pytest.raises(ValueError): dataset.clip_box(bounds=( 5, 6, )) # allow Sequence but not Iterable bounds with pytest.raises(TypeError): dataset.clip_box(bounds={5, 6, 7}) # Test with a poly data box mesh = examples.load_airplane() box = pyvista.Cube(center=(0.9e3, 0.2e3, mesh.center[2]), x_length=500, y_length=500, z_length=500) box.rotate_z(33) result = mesh.clip_box(box, invert=False) assert result.n_cells result = mesh.clip_box(box, invert=True) assert result.n_cells with pytest.raises(ValueError): dataset.clip_box(bounds=pyvista.Sphere())
def test_subplot_groups(): plotter = pyvista.Plotter(shape=(3, 3), groups=[(1, [1, 2]), (np.s_[:], 0)]) plotter.subplot(0, 0) plotter.add_mesh(pyvista.Sphere()) plotter.subplot(0, 1) plotter.add_mesh(pyvista.Cube()) plotter.subplot(0, 2) plotter.add_mesh(pyvista.Arrow()) plotter.subplot(1, 1) plotter.add_mesh(pyvista.Cylinder()) plotter.subplot(2, 1) plotter.add_mesh(pyvista.Cone()) plotter.subplot(2, 2) plotter.add_mesh(pyvista.Box()) # Test group overlap with pytest.raises(AssertionError): # Partial overlap pyvista.Plotter(shape=(3, 3), groups=[([1, 2], [0, 1]), ([0, 1], [1, 2])]) with pytest.raises(AssertionError): # Full overlap (inner) pyvista.Plotter(shape=(4, 4), groups=[(np.s_[:], np.s_[:]), ([1, 2], [1, 2])]) with pytest.raises(AssertionError): # Full overlap (outer) pyvista.Plotter(shape=(4, 4), groups=[(1, [1, 2]), ([0, 3], np.s_[:])])
def test_plot_show_bounds_params(grid, location): plotter = pyvista.Plotter(off_screen=OFF_SCREEN) plotter.add_mesh(pyvista.Cube()) plotter.show_bounds(grid=grid, ticks='inside', location=location) plotter.show_bounds(grid=grid, ticks='outside', location=location) plotter.show_bounds(grid=grid, ticks='both', location=location) plotter.show()
def create_axes_orientation_box(line_width=1, text_scale=0.366667, edge_color='black', x_color='lightblue', y_color='seagreen', z_color='tomato', x_face_color=(255, 0, 0), y_face_color=(0, 255, 0), z_face_color=(0, 0, 255), color_box=False): """Create a Box axes orientation widget with labels. """ axes_actor = vtk.vtkAnnotatedCubeActor() axes_actor.SetFaceTextScale(text_scale) axes_actor.SetXPlusFaceText("X+") axes_actor.SetXMinusFaceText("X-") axes_actor.SetYPlusFaceText("Y+") axes_actor.SetYMinusFaceText("Y-") axes_actor.SetZPlusFaceText("Z+") axes_actor.SetZMinusFaceText("Z-") axes_actor.GetTextEdgesProperty().SetColor(parse_color(edge_color)) axes_actor.GetTextEdgesProperty().SetLineWidth(line_width) axes_actor.GetXPlusFaceProperty().SetColor(parse_color(x_color)) axes_actor.GetXMinusFaceProperty().SetColor(parse_color(x_color)) axes_actor.GetYPlusFaceProperty().SetColor(parse_color(y_color)) axes_actor.GetYMinusFaceProperty().SetColor(parse_color(y_color)) axes_actor.GetZPlusFaceProperty().SetColor(parse_color(z_color)) axes_actor.GetZMinusFaceProperty().SetColor(parse_color(z_color)) if color_box: # Hide the cube so we can color each face axes_actor.GetCubeProperty().SetOpacity(0) cube = pyvista.Cube() cube.clear_arrays() # remove normals face_colors = np.array([x_face_color, x_face_color, y_face_color, y_face_color, z_face_color, z_face_color, ], dtype=np.uint8) cube.cell_arrays['face_colors'] = face_colors cube_mapper = vtk.vtkPolyDataMapper() cube_mapper.SetInputData(cube) cube_mapper.SetColorModeToDirectScalars() cube_mapper.Update() cube_actor = vtk.vtkActor() cube_actor.SetMapper(cube_mapper) cube_actor.GetProperty().BackfaceCullingOn() prop_assembly = vtk.vtkPropAssembly() prop_assembly.AddPart(axes_actor) prop_assembly.AddPart(cube_actor) actor = prop_assembly else: actor = axes_actor return actor
def sample_to_volume(sample, resolution=32, center: tuple = (0., 0., 0.)): grid = pv.create_grid(pv.Cube(center=center), dimensions=(resolution, resolution, resolution)) grid["recon"] = sample.flatten(order='F') grid.set_active_scalars("recon") # grid.plot(volume=True, show_grid=True) return grid
def test_extract_feature_edges(sphere): # Test extraction of NO edges edges = sphere.extract_feature_edges(90) assert not edges.n_points mesh = pyvista.Cube( ) # use a mesh that actually has strongly defined edges more_edges = mesh.extract_feature_edges(10) assert more_edges.n_points
def test_multi_renderers_bad_indices(): with pytest.raises(IndexError): # Test bad indices plotter = pyvista.Plotter(shape=(1, 2)) plotter.subplot(0, 0) plotter.add_mesh(pyvista.Sphere()) plotter.subplot(1, 0) plotter.add_mesh(pyvista.Cube()) plotter.show()
def test_multi_renderers_subplot_ind_1x2(): # Test subplot indices (1 row by 2 columns) plotter = pyvista.Plotter(shape=(1, 2)) # First column plotter.subplot(0, 0) plotter.add_mesh(pyvista.Sphere()) # Second column plotter.subplot(0, 1) plotter.add_mesh(pyvista.Cube()) plotter.show(before_close_callback=verify_cache_image)
def test_multi_renderers_subplot_ind_2x1(): # Test subplot indices (2 rows by 1 column) plotter = pyvista.Plotter(shape=(2, 1)) # First row plotter.subplot(0, 0) plotter.add_mesh(pyvista.Sphere()) # Second row plotter.subplot(1, 0) plotter.add_mesh(pyvista.Cube()) plotter.show(before_close_callback=verify_cache_image)
def test_extract_edges(): # Test extraction of NO edges mesh = SPHERE.copy() edges = mesh.extract_edges(90) assert not edges.n_points mesh = pyvista.Cube() # use a mesh that actually has strongly defined edges more_edges = mesh.extract_edges(10) assert more_edges.n_points mesh.extract_edges(10, inplace=True) assert mesh.n_points == more_edges.n_points
def test_multi_renderers_subplot_ind_1x3(): # Test subplot 3 on bottom, 1 on top plotter = pyvista.Plotter(shape='1|3') # First column plotter.subplot(0) plotter.add_mesh(pyvista.Sphere()) plotter.subplot(1) plotter.add_mesh(pyvista.Cube()) plotter.subplot(2) plotter.add_mesh(pyvista.Cylinder()) plotter.subplot(3) plotter.add_mesh(pyvista.Cone()) plotter.show(before_close_callback=verify_cache_image)
def test_subplot_groups(): plotter = pyvista.Plotter(shape=(3,3), groups=[(1,[1,2]),(np.s_[:],0)]) plotter.subplot(0, 0) plotter.add_mesh(pyvista.Sphere()) plotter.subplot(0, 1) plotter.add_mesh(pyvista.Cube()) plotter.subplot(0, 2) plotter.add_mesh(pyvista.Arrow()) plotter.subplot(1, 1) plotter.add_mesh(pyvista.Cylinder()) plotter.subplot(2, 1) plotter.add_mesh(pyvista.Cone()) plotter.subplot(2, 2) plotter.add_mesh(pyvista.Box()) plotter.show(before_close_callback=verify_cache_image)
def __init__(self, plotter, meshes, poly_meshes, ordered_points): self.plotter = plotter self.meshes = meshes self.poly_meshes = poly_meshes self.ordered_points = ordered_points self._points = [] self.cube = pv.Cube() # Multiple modes # MODES = ['None', 'Delete', 'Add'] self.mode = 0 # The block being added, only when 'Add' is selected self.texture_dict = None self.add_actors = None self.add_manager = None self.changed_blocks = []
def test_plot_rgb(): """"Test adding a texture to a plot""" cube = pyvista.Cube() cube.clear_arrays() x_face_color=(255, 0, 0) y_face_color=(0, 255, 0) z_face_color=(0, 0, 255) face_colors = np.array([x_face_color, x_face_color, y_face_color, y_face_color, z_face_color, z_face_color, ], dtype=np.uint8) cube.cell_arrays['face_colors'] = face_colors plotter = pyvista.Plotter(off_screen=OFF_SCREEN) plotter.add_mesh(cube, scalars='face_colors', rgb=True) plotter.show()
def test_plot_rgb(): """"Test adding a texture to a plot""" cube = pyvista.Cube() cube.clear_arrays() x_face_color = (255, 0, 0) y_face_color = (0, 255, 0) z_face_color = (0, 0, 255) face_colors = np.array([x_face_color, x_face_color, y_face_color, y_face_color, z_face_color, z_face_color, ], dtype=np.uint8) cube.cell_arrays['face_colors'] = face_colors plotter = pyvista.Plotter() plotter.add_mesh(cube, scalars='face_colors', rgb=True) plotter.show(before_close_callback=verify_cache_image)
def show_prism(self): ''' It generates and plots a prism using the bounds variables at the center of coordinates. Then with the help of a slider bar widget the prism can be translated to every point of the trajectory. ''' bounds = [ -self.bounds[0], +self.bounds[0], -self.bounds[1], +self.bounds[1], -self.bounds[2], +self.bounds[2] ] t = self.trajectories[self.cbTrajectory.currentText()] ctraj = t.compute_traj(self.step) ftraj = t.flat_ctraj(ctraj) points = np.array([list(i) for i, z in ftraj]) prism = pv.Cube(bounds=bounds) # Translate it to the initial position before the plotting to avoid # a plot in the origin of coordinates far from the data. prism.translate(points[0]) self.plotter.add_mesh(prism, color='white', opacity=1.) def move_prism(indx): ''' Translates the prism to a point of the trajectory according to indx which is obtained from the slider bar. ''' # To use the ctraj vector = points[int(indx)] - np.array(prism.center) # To use the self.traj # vector = t.traj['P'][int(indx)]- np.array(prism.center) prism.translate(vector) return self.plotter.add_slider_widget(move_prism, [0, len(points)-1], value=0., title='Trajectory point', event_type='always')
def test_find_cells_within_bounds(): mesh = pyvista.Cube() bounds = [ mesh.bounds[0] * 2.0, mesh.bounds[1] * 2.0, mesh.bounds[2] * 2.0, mesh.bounds[3] * 2.0, mesh.bounds[4] * 2.0, mesh.bounds[5] * 2.0, ] indices = mesh.find_cells_within_bounds(bounds) assert len(indices) == mesh.n_cells bounds = [ mesh.bounds[0] * 0.5, mesh.bounds[1] * 0.5, mesh.bounds[2] * 0.5, mesh.bounds[3] * 0.5, mesh.bounds[4] * 0.5, mesh.bounds[5] * 0.5, ] indices = mesh.find_cells_within_bounds(bounds) assert len(indices) == 0
def show_processing(self, mesh): if not mesh: print(f"Can't render mesh of type {type(mesh)}") return None new_data = self.normalizer.mono_run_pipeline(mesh) history = new_data["history"] num_of_operations = len(history) plt = BackgroundPlotter(shape=(2, num_of_operations // 2)) elements = history plt.show_axes_all() for idx in range(num_of_operations): plt.subplot(int(idx / 3), idx % 3) if elements[idx]["op"] == "Center": plt.add_mesh(pv.Cube().extract_all_edges()) curr_mesh = pv.PolyData(elements[idx]["data"]["vertices"], elements[idx]["data"]["faces"]) plt.add_mesh(curr_mesh, color='w', show_edges=True) plt.reset_camera() plt.view_isometric() plt.add_text(elements[idx]["op"] + "\nVertices: " + str(len(curr_mesh.points)) + "\nFaces: " + str(curr_mesh.n_faces)) plt.show_grid()
def test_plot_boundaries(): # make sure to plot an object that has boundaries pyvista.Cube().plot_boundaries(off_screen=True)
import pyvista from pyvista import examples from pyvista.plotting import system_supports_plotting from pyvista.core.errors import NotAllTrianglesError radius = 0.5 SPHERE = pyvista.Sphere(radius, theta_resolution=10, phi_resolution=10) SPHERE_SHIFTED = pyvista.Sphere(center=[0.5, 0.5, 0.5], theta_resolution=10, phi_resolution=10) SPHERE_DENSE = pyvista.Sphere(radius, theta_resolution=100, phi_resolution=100) CUBE_DENSE = pyvista.Cube() test_path = os.path.dirname(os.path.abspath(__file__)) try: CONDA_ENV = os.environ['CONDA_ALWAYS_YES'] == "1" except KeyError: CONDA_ENV = False def is_binary(filename): """Return ``True`` when a file is binary""" textchars = bytearray({7, 8, 9, 10, 12, 13, 27} | set(range(0x20, 0x100)) - {0x7f}) with open(filename, 'rb') as f: data = f.read(1024)
############################################################################### # This example shows how to create a multi-window plotter by specifying the # ``shape`` parameter. The window generated is a two by two window by setting # ``shape=(2, 2)``. Use the :func:`pyvista.BasePlotter.subplot` function to # select the subplot you wish to be the active subplot. plotter = pv.Plotter(shape=(2, 2)) plotter.subplot(0, 0) plotter.add_text("Render Window 0", font_size=30) plotter.add_mesh(examples.load_globe()) plotter.subplot(0, 1) plotter.add_text("Render Window 1", font_size=30) plotter.add_mesh(pv.Cube(), show_edges=True, color="tan") plotter.subplot(1, 0) plotter.add_text("Render Window 2", font_size=30) sphere = pv.Sphere() plotter.add_mesh(sphere, scalars=sphere.points[:, 2]) plotter.add_scalar_bar("Z") # plotter.add_axes() plotter.add_axes(interactive=True) plotter.subplot(1, 1) plotter.add_text("Render Window 3", font_size=30) plotter.add_mesh(pv.Cone(), color="g", show_edges=True) plotter.show_bounds(all_edges=True) # Display the window
def create_axes_orientation_box( line_width=1, text_scale=0.366667, edge_color='black', x_color=None, y_color=None, z_color=None, xlabel='X', ylabel='Y', zlabel='Z', x_face_color='red', y_face_color='green', z_face_color='blue', color_box=False, label_color=None, labels_off=False, opacity=0.5, ): """Create a Box axes orientation widget with labels.""" if x_color is None: x_color = rcParams['axes']['x_color'] if y_color is None: y_color = rcParams['axes']['y_color'] if z_color is None: z_color = rcParams['axes']['z_color'] if edge_color is None: edge_color = rcParams['edge_color'] axes_actor = vtk.vtkAnnotatedCubeActor() axes_actor.SetFaceTextScale(text_scale) if xlabel is not None: axes_actor.SetXPlusFaceText(f"+{xlabel}") axes_actor.SetXMinusFaceText(f"-{xlabel}") if ylabel is not None: axes_actor.SetYPlusFaceText(f"+{ylabel}") axes_actor.SetYMinusFaceText(f"-{ylabel}") if zlabel is not None: axes_actor.SetZPlusFaceText(f"+{zlabel}") axes_actor.SetZMinusFaceText(f"-{zlabel}") axes_actor.SetFaceTextVisibility(not labels_off) axes_actor.SetTextEdgesVisibility(False) # axes_actor.GetTextEdgesProperty().SetColor(parse_color(edge_color)) # axes_actor.GetTextEdgesProperty().SetLineWidth(line_width) axes_actor.GetXPlusFaceProperty().SetColor(parse_color(x_color)) axes_actor.GetXMinusFaceProperty().SetColor(parse_color(x_color)) axes_actor.GetYPlusFaceProperty().SetColor(parse_color(y_color)) axes_actor.GetYMinusFaceProperty().SetColor(parse_color(y_color)) axes_actor.GetZPlusFaceProperty().SetColor(parse_color(z_color)) axes_actor.GetZMinusFaceProperty().SetColor(parse_color(z_color)) axes_actor.GetCubeProperty().SetOpacity(opacity) # axes_actor.GetCubeProperty().SetEdgeColor(parse_color(edge_color)) axes_actor.GetCubeProperty().SetEdgeVisibility(True) axes_actor.GetCubeProperty().BackfaceCullingOn() if opacity < 1.0: # Hide the text edges axes_actor.GetTextEdgesProperty().SetOpacity(0) if color_box: # Hide the cube so we can color each face axes_actor.GetCubeProperty().SetOpacity(0) axes_actor.GetCubeProperty().SetEdgeVisibility(False) cube = pyvista.Cube() cube.clear_arrays() # remove normals face_colors = np.array([ parse_color(x_face_color), parse_color(x_face_color), parse_color(y_face_color), parse_color(y_face_color), parse_color(z_face_color), parse_color(z_face_color), ]) face_colors = (face_colors * 255).astype(np.uint8) cube.cell_arrays['face_colors'] = face_colors cube_mapper = vtk.vtkPolyDataMapper() cube_mapper.SetInputData(cube) cube_mapper.SetColorModeToDirectScalars() cube_mapper.Update() cube_actor = vtk.vtkActor() cube_actor.SetMapper(cube_mapper) cube_actor.GetProperty().BackfaceCullingOn() cube_actor.GetProperty().SetOpacity(opacity) prop_assembly = vtk.vtkPropAssembly() prop_assembly.AddPart(axes_actor) prop_assembly.AddPart(cube_actor) actor = prop_assembly else: actor = axes_actor update_axes_label_color(actor, label_color) return actor
def test_multi_renderers(): plotter = pyvista.Plotter(shape=(2, 2), off_screen=OFF_SCREEN) plotter.subplot(0, 0) plotter.add_text('Render Window 0', font_size=30) sphere = pyvista.Sphere() plotter.add_mesh(sphere, scalars=sphere.points[:, 2]) plotter.add_scalar_bar('Z', vertical=True) plotter.subplot(0, 1) plotter.add_text('Render Window 1', font_size=30) plotter.add_mesh(pyvista.Cube(), show_edges=True) plotter.subplot(1, 0) plotter.add_text('Render Window 2', font_size=30) plotter.add_mesh(pyvista.Arrow(), color='y', show_edges=True) plotter.subplot(1, 1) plotter.add_text('Render Window 3', position=(0., 0.), font_size=30, viewport=True) plotter.add_mesh(pyvista.Cone(), color='g', show_edges=True, culling=True) plotter.add_bounding_box(render_lines_as_tubes=True, line_width=5) plotter.show_bounds(all_edges=True) plotter.update_bounds_axes() plotter.show() # Test subplot indices (2 rows by 1 column) plotter = pyvista.Plotter(shape=(2, 1), off_screen=OFF_SCREEN) # First row plotter.subplot(0, 0) plotter.add_mesh(pyvista.Sphere()) # Second row plotter.subplot(1, 0) plotter.add_mesh(pyvista.Cube()) plotter.show() # Test subplot indices (1 row by 2 columns) plotter = pyvista.Plotter(shape=(1, 2), off_screen=OFF_SCREEN) # First column plotter.subplot(0, 0) plotter.add_mesh(pyvista.Sphere()) # Second column plotter.subplot(0, 1) plotter.add_mesh(pyvista.Cube()) plotter.show() with pytest.raises(IndexError): # Test bad indices plotter = pyvista.Plotter(shape=(1, 2), off_screen=OFF_SCREEN) plotter.subplot(0, 0) plotter.add_mesh(pyvista.Sphere()) plotter.subplot(1, 0) plotter.add_mesh(pyvista.Cube()) plotter.show() # Test subplot 3 on left, 1 on right plotter = pyvista.Plotter(shape='3|1', off_screen=OFF_SCREEN) # First column plotter.subplot(0) plotter.add_mesh(pyvista.Sphere()) plotter.subplot(1) plotter.add_mesh(pyvista.Cube()) plotter.subplot(2) plotter.add_mesh(pyvista.Cylinder()) plotter.subplot(3) plotter.add_mesh(pyvista.Cone()) plotter.show() # Test subplot 3 on bottom, 1 on top plotter = pyvista.Plotter(shape='1|3', off_screen=OFF_SCREEN) # First column plotter.subplot(0) plotter.add_mesh(pyvista.Sphere()) plotter.subplot(1) plotter.add_mesh(pyvista.Cube()) plotter.subplot(2) plotter.add_mesh(pyvista.Cylinder()) plotter.subplot(3) plotter.add_mesh(pyvista.Cone()) plotter.show()