Exemplo n.º 1
0
def test_vtk_pane_more_complex(document, comm, tmp_path):
    renWin = pyvista_render_window()
    pane = VTK(renWin)

    # Create pane
    model = pane.get_root(document, comm=comm)
    assert isinstance(model, VTKSynchronizedPlot)
    assert pane._models[model.ref['id']][0] is model

    colorbars_infered = pane.construct_colorbars().object

    assert len(colorbars_infered.below) == 2  # infer only actor color bars
    assert all(isinstance(cb, ColorBar) for cb in colorbars_infered.below)

    colorbars_in_scene = pane.construct_colorbars(infer=False).object()
    assert len(colorbars_in_scene.below) == 3
    assert all(isinstance(cb, ColorBar) for cb in colorbars_in_scene.below)
    # add axes
    pane.axes = dict(
        origin=[-5, 5, -2],
        xticker={'ticks': np.linspace(-5, 5, 5)},
        yticker={'ticks': np.linspace(-5, 5, 5)},
        zticker={
            'ticks': np.linspace(-2, 2, 5),
            'labels':
            [''] + [str(int(item)) for item in np.linspace(-2, 2, 5)[1:]]
        },
        fontsize=12,
        digits=1,
        grid_opacity=0.5,
        show_grid=True)
    assert isinstance(model.axes, VTKAxes)

    # test export to file
    tmpfile = os.path.join(*tmp_path.joinpath('scene').parts)
    exported_file = pane.export_scene(filename=tmpfile)
    assert exported_file.endswith('.synch')

    # test import from file
    # (TODO test if the scene imported is identical to the one exported)
    imported_scene = VTK.import_scene(filename=exported_file)
    assert isinstance(imported_scene, VTKRenderWindowSynchronized)

    # Cleanup
    pane._cleanup(model)
    assert pane._contexts == {}
    assert pane._models == {}
Exemplo n.º 2
0
def test_vtk_pane_more_complex(document, comm):
    renWin = pyvista_render_window()
    pane = VTK(renWin)

    # Create pane
    model = pane.get_root(document, comm=comm)
    assert isinstance(model, VTKPlot)
    assert pane._models[model.ref['id']][0] is model

    #test colorbar
    colorbars_plot = pane.construct_colorbars()
    cb_model = colorbars_plot.below[0]
    cb_title = cb_model.title
    assert cb_title == 'test'
    assert cb_model.color_mapper.palette == pane._legend[cb_title]['palette']

    with BytesIO(base64.b64decode(model.data.encode())) as in_memory:
        with ZipFile(in_memory) as zf:
            filenames = zf.namelist()
            assert len(filenames) == 12
            assert 'index.json' in filenames

    # add axes
    pane.axes = dict(
        origin=[-5, 5, -2],
        xticker={'ticks': np.linspace(-5, 5, 5)},
        yticker={'ticks': np.linspace(-5, 5, 5)},
        zticker={
            'ticks': np.linspace(-2, 2, 5),
            'labels':
            [''] + [str(int(item)) for item in np.linspace(-2, 2, 5)[1:]]
        },
        fontsize=12,
        digits=1,
        grid_opacity=0.5,
        show_grid=True)
    assert isinstance(model.axes, VTKAxes)

    # Cleanup
    pane._cleanup(model)
    assert pane._models == {}