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_save_rectilinear(extension, binary, tmpdir): filename = str(tmpdir.mkdir("tmpdir").join('tmp.%s' % extension)) ogrid = examples.load_rectilinear() ogrid.save(filename, binary) grid = vtki.RectilinearGrid(filename) assert grid.n_cells == ogrid.n_cells assert np.allclose(grid.x, ogrid.x) assert np.allclose(grid.y, ogrid.y) assert np.allclose(grid.z, ogrid.z) assert grid.dimensions == ogrid.dimensions
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_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_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_multi_block_set_get_ers(): """This puts all of the example data objects into a a MultiBlock container""" multi = vtki.MultiBlock() # Set the number of blocks multi.n_blocks = 6 assert multi.GetNumberOfBlocks() == 6 # Check that VTK side registered it assert multi.n_blocks == 6 # Check vtki side registered it # Add data to the MultiBlock data = ex.load_rectilinear() multi[1, 'rect'] = data # Make sure number of blocks is constant assert multi.n_blocks == 6 # Check content assert isinstance(multi[1], vtki.RectilinearGrid) for i in [0, 2, 3, 4, 5]: assert multi[i] == None # Check the bounds assert multi.bounds == list(data.bounds) multi[5] = ex.load_uniform() multi.set_block_name(5, 'uni') multi.set_block_name(5, None) # Make sure it doesn't get overwritten assert isinstance(multi.get(5), vtki.UniformGrid) # Test get by name assert isinstance(multi['uni'], vtki.UniformGrid) assert isinstance(multi['rect'], vtki.RectilinearGrid) # Test the del operator del multi[0] assert multi.n_blocks == 5 # Make sure the rect grid was moved up assert isinstance(multi[0], vtki.RectilinearGrid) assert multi.get_block_name(0) == 'rect' assert multi.get_block_name(2) == None # test del by name del multi['uni'] assert multi.n_blocks == 4 # test the pop operator pop = multi.pop(0) assert isinstance(pop, vtki.RectilinearGrid) assert multi.n_blocks == 3 assert multi.get_block_name(10) is None with pytest.raises(KeyError): idx = multi.get_index_by_name('foo')
def test_create_rectilinear_grid_from_file(): grid = examples.load_rectilinear() assert grid.n_cells == 16146 assert grid.n_points == 18144 assert grid.bounds == [-350.0, 1350.0, -400.0, 1350.0, -850.0, 0.0] assert grid.n_scalars == 1
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