def test_vtk_sync_helpers(document, comm): renWin1 = make_render_window() renWin2 = make_render_window() # Create 2 panes to compare each other pane1 = VTK(renWin1) pane2 = VTK(renWin2) assert isinstance(pane1, VTKRenderWindowSynchronized) assert isinstance(pane2, VTKRenderWindowSynchronized) # Create get models model1 = pane1.get_root(document, comm=comm) model2 = pane2.get_root(document, comm=comm) assert isinstance(model1, VTKSynchronizedPlot) assert isinstance(model2, VTKSynchronizedPlot) # Actors getter assert len(pane1.actors) == 2 assert len(pane2.actors) == 2 assert pane1.actors[0] is not pane2.actors[0] # Actors add pane1.add_actors(pane2.actors) assert len(pane1.actors) == 4 assert pane1.actors[3] is pane2.actors[1] # Actors remove save_actor = pane1.actors[0] pane1.remove_actors([pane1.actors[0]]) assert pane1.actors[2] is pane2.actors[1] # Actors remove all pane1.add_actors([save_actor]) assert len(pane1.actors) == 4 pane1.remove_all_actors() assert len(pane1.actors) == 0 # Connect camera save_vtk_camera2 = pane2.vtk_camera assert pane1.vtk_camera is not save_vtk_camera2 pane1.link_camera(pane2) assert pane1.vtk_camera is save_vtk_camera2 # Unconnect camera pane2.unlink_camera() assert pane2.vtk_camera is not save_vtk_camera2 # SetBackground pane1.set_background(0, 0, 0) assert list(renWin1.GetRenderers())[0].GetBackground() == (0, 0, 0) # Cleanup pane1._cleanup(model1) pane2._cleanup(model2)
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 == {}
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 == {}
def test_vtk_pane_from_renwin(document, comm): renWin = make_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 # Check array release when actor are removed from scene ctx = pane._contexts[model.id] assert len(ctx.dataArrayCache.keys()) == 5 pane.remove_all_actors() # Default : 20s before removing arrays assert len(ctx.dataArrayCache.keys()) == 5 # Force 0s for removing arrays ctx.checkForArraysToRelease(0) assert len(ctx.dataArrayCache.keys()) == 0 # Cleanup pane._cleanup(model) assert pane._contexts == {} assert pane._models == {}
def test_vtk_pane_from_renwin(document, comm, tmp_path): renWin = make_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 with BytesIO(base64.b64decode(model.data.encode())) as in_memory: with ZipFile(in_memory) as zf: filenames = zf.namelist() assert len(filenames) == 4 assert 'index.json' in filenames # Export Update and Read tmpfile = os.path.join(*tmp_path.joinpath('export.vtkjs').parts) pane.export_vtkjs(filename=tmpfile) with open(tmpfile, 'rb') as file_exported: pane.object = file_exported # Cleanup pane._cleanup(model) assert pane._models == {}