Esempio n. 1
0
def test_threshold():
    for i, dataset in enumerate(datasets[0:3]):
        thresh = dataset.threshold()
        assert thresh is not None
        assert isinstance(thresh, vtki.UnstructuredGrid)
    # Test value ranges
    dataset = examples.load_uniform()  # UniformGrid
    thresh = dataset.threshold(100, invert=False)
    assert thresh is not None
    assert isinstance(thresh, vtki.UnstructuredGrid)
    thresh = dataset.threshold([100, 500], invert=False)
    assert thresh is not None
    assert isinstance(thresh, vtki.UnstructuredGrid)
    thresh = dataset.threshold([100, 500], invert=True)
    assert thresh is not None
    assert isinstance(thresh, vtki.UnstructuredGrid)
    # Now test datasets without arrays
    with pytest.raises(AssertionError):
        for i, dataset in enumerate(datasets[3:-1]):
            thresh = dataset.threshold()
            assert thresh is not None
            assert isinstance(thresh, vtki.UnstructuredGrid)
    dataset = examples.load_uniform()
    with pytest.raises(AssertionError):
        dataset.threshold([10, 100, 300])
Esempio n. 2
0
def test_elevation():
    dataset = examples.load_uniform()
    # Test default params
    elev = dataset.elevation()
    assert 'Elevation' in elev.scalar_names
    assert 'Elevation' == elev.active_scalar_name
    assert elev.get_data_range() == (dataset.bounds[4], dataset.bounds[5])
    # test vector args
    c = list(dataset.center)
    t = list(c)  # cast so it doesnt point to `c`
    t[2] = dataset.bounds[-1]
    elev = dataset.elevation(low_point=c, high_point=t)
    assert 'Elevation' in elev.scalar_names
    assert 'Elevation' == elev.active_scalar_name
    assert elev.get_data_range() == (dataset.center[2], dataset.bounds[5])
    # Test not setting active
    elev = dataset.elevation(set_active=False)
    assert 'Elevation' in elev.scalar_names
    assert 'Elevation' != elev.active_scalar_name
    # Set use a range by scalar name
    elev = dataset.elevation(scalar_range='Spatial Point Data')
    assert 'Elevation' in elev.scalar_names
    assert 'Elevation' == elev.active_scalar_name
    assert dataset.get_data_range('Spatial Point Data') == (
        elev.get_data_range('Elevation'))
    # Set use a user defined range
    elev = dataset.elevation(scalar_range=[1.0, 100.0])
    assert 'Elevation' in elev.scalar_names
    assert 'Elevation' == elev.active_scalar_name
    assert elev.get_data_range('Elevation') == (1.0, 100.0)
    # test errors
    with pytest.raises(RuntimeError):
        elev = dataset.elevation(scalar_range=0.5)
Esempio n. 3
0
def test_remove_actor():
    data = examples.load_uniform()
    plotter = vtki.Plotter(off_screen=OFF_SCREEN)
    plotter.add_mesh(data, name='data')
    plotter.add_mesh(data, name='data')
    plotter.add_mesh(data, name='data')
    plotter.show()
Esempio n. 4
0
def test_orthographic_slicer():
    data = examples.load_uniform()
    data.set_active_scalar('Spatial Cell Data')

    slices = data.slice_orthogonal()

    # Orthographic Slicer
    p = vtki.Plotter(shape=(2, 2), off_screen=OFF_SCREEN)

    p.subplot(1, 1)
    p.add_mesh(slices, clim=data.get_data_range())
    p.add_axes()
    p.enable()

    p.subplot(0, 0)
    p.add_mesh(slices['XY'])
    p.view_xy()
    p.disable()

    p.subplot(0, 1)
    p.add_mesh(slices['XZ'])
    p.view_xz(negative=True)
    p.disable()

    p.subplot(1, 0)
    p.add_mesh(slices['YZ'])
    p.view_yz()
    p.disable()

    p.show()
Esempio n. 5
0
def test_resample():
    mesh = vtki.Sphere(center=(4.5, 4.5, 4.5), radius=4.5)
    data_to_probe = examples.load_uniform()
    result = mesh.sample(data_to_probe)
    name = 'Spatial Point Data'
    assert name in result.scalar_names
    assert isinstance(result, type(mesh))
Esempio n. 6
0
def test_create_uniform_grid_from_file():
    grid = examples.load_uniform()
    assert grid.n_cells == 729
    assert grid.n_points == 1000
    assert grid.bounds == [0.0, 9.0, 0.0, 9.0, 0.0, 9.0]
    assert grid.n_scalars == 2
    assert grid.dimensions == [10, 10, 10]
Esempio n. 7
0
def test_is_inside_bounds():
    data = ex.load_uniform()
    bnds = data.bounds
    assert utilities.is_inside_bounds((0.5, 0.5, 0.5), bnds)
    assert not utilities.is_inside_bounds((12, 5, 5), bnds)
    assert not utilities.is_inside_bounds((5, 12, 5), bnds)
    assert not utilities.is_inside_bounds((5, 5, 12), bnds)
    assert not utilities.is_inside_bounds((12, 12, 12), bnds)
Esempio n. 8
0
def test_ipy_integrated(qtbot):
    data = examples.load_uniform()
    p = vtki.ScaledPlotter(show=False)
    p.add_mesh(data)
    slicer = vtki.OrthogonalSlicer(data, plotter=p)
    many = vtki.ManySlicesAlongAxis(data, plotter=p)
    thresher = vtki.Threshold(data, plotter=p)
    clipper = vtki.Clip(data, plotter=p)
    p.close()
Esempio n. 9
0
def test_slice_filter():
    """This tests the slice filter on all datatypes avaialble filters"""
    for i, dataset in enumerate(datasets):
        slc = dataset.slice(normal=normals[i])
        assert slc is not None
        assert isinstance(slc, vtki.PolyData)
    dataset = examples.load_uniform()
    with pytest.raises(AssertionError):
        dataset.slice(origin=(10, 15, 15))
Esempio n. 10
0
def test_image_properties():
    mesh = examples.load_uniform()
    p = vtki.Plotter(off_screen=OFF_SCREEN)
    p.add_mesh(mesh)
    p.show(auto_close=False)  # DO NOT close plotter
    # Get RGB image
    img = p.image
    # Get the depth image
    img = np.sum(p.image_depth, axis=2)
    p.close()
Esempio n. 11
0
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)
Esempio n. 12
0
def test_save_uniform(extension, binary, tmpdir):
    filename = str(tmpdir.mkdir("tmpdir").join('tmp.%s' % extension))
    ogrid = examples.load_uniform()
    ogrid.save(filename, binary)

    grid = vtki.UniformGrid(filename)
    assert grid.n_cells == ogrid.n_cells
    assert grid.origin == ogrid.origin
    assert grid.spacing == ogrid.spacing
    assert grid.dimensions == ogrid.dimensions
Esempio n. 13
0
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
Esempio n. 14
0
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,))
Esempio n. 15
0
def test_split_and_connectivity():
    # Load a simple example mesh
    dataset = examples.load_uniform()
    dataset.set_active_scalar('Spatial Cell Data')
    threshed = dataset.threshold_percent([0.15, 0.50], invert=True)

    bodies = threshed.split_bodies()

    volumes = [518.0, 35.0]
    assert len(volumes) == bodies.n_blocks
    for i, body in enumerate(bodies):
        assert np.allclose(body.volume, volumes[i], rtol=0.1)
Esempio n. 16
0
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()
Esempio n. 17
0
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)
Esempio n. 18
0
def test_slice_along_axis():
    """Test the many slices along axis filter """
    axii = ['x', 'y', 'z', 'y', 0]
    ns = [2, 3, 4, 10, 20, 13]
    for i, dataset in enumerate(datasets):
        slices = dataset.slice_along_axis(n=ns[i], axis=axii[i])
        assert slices is not None
        assert isinstance(slices, vtki.MultiBlock)
        assert slices.n_blocks == ns[i]
        for slc in slices:
            assert isinstance(slc, vtki.PolyData)
    dataset = examples.load_uniform()
    with pytest.raises(RuntimeError):
        dataset.slice_along_axis(axis='u')
Esempio n. 19
0
def test_threshold_percent():
    percents = [25, 50, [18.0, 85.0], [19.0, 80.0], 0.70]
    inverts = [False, True, False, True, False]
    # Only test data sets that have arrays
    for i, dataset in enumerate(datasets[0:3]):
        thresh = dataset.threshold_percent(percent=percents[i], invert=inverts[i])
        assert thresh is not None
        assert isinstance(thresh, vtki.UnstructuredGrid)
    dataset = examples.load_uniform()
    result = dataset.threshold_percent(0.75, scalars='Spatial Cell Data')
    with pytest.raises(RuntimeError):
        result = dataset.threshold_percent(20000)
    with pytest.raises(RuntimeError):
        result = dataset.threshold_percent(0.0)
Esempio n. 20
0
def test_camera():
    plotter = vtki.Plotter(off_screen=OFF_SCREEN)
    plotter.add_mesh(sphere)
    plotter.view_isometric()
    plotter.reset_camera()
    plotter.view_xy()
    plotter.view_xz()
    plotter.view_yz()
    plotter.add_mesh(examples.load_uniform(),
                     reset_camera=True,
                     backface_culling=True)
    plotter.view_xy(True)
    plotter.view_xz(True)
    plotter.view_yz(True)
    plotter.show()
    plotter.camera_position = None
Esempio n. 21
0
def test_uniform_grid_filters():
    """This tests all avaialble filters"""
    dataset = examples.load_uniform()
    dataset.set_active_scalar('Spatial Point Data')
    # Threshold
    thresh = dataset.threshold([100, 500])
    assert thresh is not None
    # Slice
    slc = dataset.slice()
    assert slc is not None
    # Clip
    clp = dataset.clip(invert=True)
    assert clp is not None
    # Contour
    iso = dataset.contour()
    assert iso is not None
Esempio n. 22
0
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)
Esempio n. 23
0
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
Esempio n. 24
0
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))
Esempio n. 25
0
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')
Esempio n. 26
0
def test_delaunay_3d():
    data = examples.load_uniform().threshold_percent(30)
    result = data.delaunay_3d()
    assert np.any(result.points)
Esempio n. 27
0
def test_triangulate():
    data = examples.load_uniform()
    tri = data.triangulate()
    assert isinstance(tri, vtki.UnstructuredGrid)
    assert np.any(tri.cells)
Esempio n. 28
0
def test_smooth():
    data = examples.load_uniform()
    vol = data.threshold_percent(30)
    surf = vol.extract_geometry()
    smooth = surf.smooth()
    assert np.any(smooth.points)
Esempio n. 29
0
Calculate mass properties such as the volume or area of datasets
"""
################################################################################
# Computing mass properties such as the volume or area of datasetsin ``vtki``
# is quite easy using the :func:`vtki.DataSetFilters.compute_cell_sizes` filter
# and the :attr:`vtki.Common.volume` property on all ``vtki`` meshes.
#
# Let's get started with a simple gridded mesh:

import numpy as np
import vtki
from vtki import examples

# Load a simple example mesh
dataset = examples.load_uniform()
dataset.set_active_scalar('Spatial Cell Data')

################################################################################
# We can then calculate the volume of every cell in the array using the
# ``.compute_cell_sizes`` filter which will add arrays to the cell data of the
# mesh core the volume and area by default.

# Compute volumes and areas
sized = dataset.compute_cell_sizes()

# Grab volumes for all cells in the mesh
cell_volumes = sized.cell_arrays['Volume']

################################################################################
# We can also compute the total volume of the mesh using the ``.volume`` property:
Esempio n. 30
0
def test_scalars_by_name():
    plotter = vtki.Plotter(off_screen=OFF_SCREEN)
    data = examples.load_uniform()
    plotter.add_mesh(data, scalars='Spatial Cell Data')
    plotter.plot()