def test_multi_block_init_list(): data = [ex.load_rectilinear(), ex.load_airplane()] multi = vtki.MultiBlock(data) assert isinstance(multi, vtki.MultiBlock) assert multi.n_blocks == 2 assert isinstance(multi[0], vtki.RectilinearGrid) assert isinstance(multi[1], vtki.PolyData)
def test_multi_block_plot(): multi = vtki.MultiBlock() multi.append(examples.load_rectilinear()) uni = examples.load_uniform() arr = np.random.rand(uni.n_cells) uni._add_cell_scalar(arr, 'Random Data') multi.append(uni) # And now add a data set without the desired array and a NULL component multi[3] = examples.load_airplane() multi.plot(scalars='Random Data', off_screen=OFF_SCREEN, multi_colors=True)
def test_export_color(tmpdir): filename = str(tmpdir.mkdir("tmpdir").join('scene')) data = ex.load_airplane() # Create the scene plotter = vtki.Plotter(off_screen=OFF_SCREEN) plotter.add_mesh(data, color='yellow') plotter.export_vtkjs(filename) cpos_out = plotter.show() # Export must be called before showing! plotter.close() # Now make sure the file is there assert os.path.isfile('{}.vtkjs'.format(filename))
def test_multi_block_repr(): multi = vtki.MultiBlock() # Add examples multi.append(ex.load_ant()) multi.append(ex.load_sphere()) multi.append(ex.load_uniform()) multi.append(ex.load_airplane()) multi.append(None) # Now check everything assert multi.n_blocks == 5 assert multi._repr_html_() is not None
def test_multi_block_init_dict(): data = dict() data['grid'] = ex.load_rectilinear() data['poly'] = ex.load_airplane() multi = vtki.MultiBlock(data) assert isinstance(multi, vtki.MultiBlock) assert multi.n_blocks == 2 # Note that disctionaries do not maintain order assert isinstance(multi[0], (vtki.RectilinearGrid, vtki.PolyData)) assert multi.get_block_name(0) in ['grid', 'poly'] assert isinstance(multi[1], (vtki.RectilinearGrid, vtki.PolyData)) assert multi.get_block_name(1) in ['grid', 'poly']
def test_clip_box(): for i, dataset in enumerate(datasets): clp = dataset.clip_box(invert=True) assert clp is not None assert isinstance(clp, vtki.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) with pytest.raises(AssertionError): dataset.clip_box(bounds=(5, 6,))
def test_contour(): dataset = examples.load_uniform() iso = dataset.contour() assert iso is not None iso = dataset.contour(isosurfaces=[100, 300, 500]) assert iso is not None with pytest.raises(AssertionError): result = dataset.contour(scalars='Spatial Cell Data') with pytest.raises(RuntimeError): result = dataset.contour(isosurfaces=vtki.PolyData()) dataset = examples.load_airplane() with pytest.raises(AssertionError): result = dataset.contour()
def test_combine_filter(): multi = vtki.MultiBlock() # Add examples multi.append(ex.load_ant()) multi.append(ex.load_sphere()) multi.append(ex.load_uniform()) multi.append(ex.load_airplane()) multi.append(ex.load_globe()) # Now check everything assert multi.n_blocks == 5 # Now apply the geometry filter to combine a plethora of data blocks geom = multi.combine() assert isinstance(geom, vtki.UnstructuredGrid)
def test_texture_map_to_plane(): dataset = examples.load_airplane() # Automatically decide plane out = dataset.texture_map_to_plane(inplace=False) assert isinstance(out, type(dataset)) # Define the plane explicitly bnds = dataset.bounds origin = bnds[0::2] point_u = (bnds[1], bnds[2], bnds[4]) point_v = (bnds[0], bnds[3], bnds[4]) out = dataset.texture_map_to_plane(origin=origin, point_u=point_u, point_v=point_v) assert isinstance(out, type(dataset)) assert 'Texture Coordinates' in out.scalar_names # FINAL: Test in place modifiacation dataset.texture_map_to_plane(inplace=True) assert 'Texture Coordinates' in dataset.scalar_names
def test_export_multi(tmpdir): filename = str(tmpdir.mkdir("tmpdir").join('scene')) multi = vtki.MultiBlock() # Add examples multi.append(ex.load_ant()) multi.append(ex.load_sphere()) multi.append(ex.load_uniform()) multi.append(ex.load_airplane()) multi.append(ex.load_rectilinear()) # Create the scene plotter = vtki.Plotter(off_screen=OFF_SCREEN) plotter.add_mesh(multi) plotter.export_vtkjs(filename, compress_arrays=True) cpos_out = plotter.show() # Export must be called before showing! plotter.close() # Now make sure the file is there assert os.path.isfile('{}.vtkjs'.format(filename))
def test_multi_block_io(extension, binary, tmpdir): filename = str(tmpdir.mkdir("tmpdir").join('tmp.%s' % extension)) multi = vtki.MultiBlock() # Add examples multi.append(ex.load_ant()) multi.append(ex.load_sphere()) multi.append(ex.load_uniform()) multi.append(ex.load_airplane()) multi.append(ex.load_globe()) # Now check everything assert multi.n_blocks == 5 # Save it out multi.save(filename, binary) foo = vtki.MultiBlock(filename) assert foo.n_blocks == multi.n_blocks foo = vtki.read(filename) assert foo.n_blocks == multi.n_blocks
def test_multi_block_append(): """This puts all of the example data objects into a a MultiBlock container""" multi = vtki.MultiBlock() # Add examples multi.append(ex.load_ant()) multi.append(ex.load_sphere()) multi.append(ex.load_uniform()) multi.append(ex.load_airplane()) multi.append(ex.load_rectilinear()) # Now check everything assert multi.n_blocks == 5 assert multi.bounds is not None assert isinstance(multi[0], vtki.PolyData) assert isinstance(multi[1], vtki.PolyData) assert isinstance(multi[2], vtki.UniformGrid) assert isinstance(multi[3], vtki.PolyData) assert isinstance(multi[4], vtki.RectilinearGrid)
def test_load_airplane(): """ Load ply airplane mesh """ mesh = examples.load_airplane() assert mesh.n_points
import numpy as np import pytest import vtki from vtki import examples datasets = [ examples.load_uniform(), # UniformGrid examples.load_rectilinear(), # RectilinearGrid examples.load_hexbeam(), # UnstructuredGrid examples.load_airplane(), # PolyData examples.load_structured(), # StructuredGrid ] normals = ['x', 'y', '-z', (1, 1, 1), (3.3, 5.4, 0.8)] def test_clip_filter(): """This tests the clip filter on all datatypes avaialble filters""" for i, dataset in enumerate(datasets): clp = dataset.clip(normal=normals[i], invert=True) assert clp is not None assert isinstance(clp, vtki.UnstructuredGrid) def test_clip_box(): for i, dataset in enumerate(datasets): clp = dataset.clip_box(invert=True) assert clp is not None assert isinstance(clp, vtki.UnstructuredGrid) dataset = examples.load_airplane() # test length 3 bounds
# plotter.add_axes() plotter.add_axes(interactive=True) plotter.subplot(1, 1) plotter.add_text('Render Window 3', font_size=30) plotter.add_mesh(vtki.Cone(), color='g', show_edges=True) plotter.show_bounds(all_edges=True) # Display the window plotter.show() ################################################################################ import vtki from vtki import examples plotter = vtki.Plotter(shape=(1, 2)) # Note that the (0, 0) location is active by default # load and plot an airplane on the left half of the screen plotter.add_text('Airplane Example\n', font_size=30) plotter.add_mesh(examples.load_airplane(), show_edges=False) # load and plot the uniform data example on the right-hand side plotter.subplot(0, 1) plotter.add_text('Uniform Data Example\n', font_size=30) plotter.add_mesh(examples.load_uniform(), show_edges=True) # Display the window plotter.show()