def plot_partial_3D(mg, idx, scenes, sim_file, mesh_config, cpos, interactive=False): if interactive: p = pv.PlotterITK() else: p = pv.Plotter(off_screen=True, notebook=False) max_val = -np.inf min_val = np.inf data_dict = {} for scene in scenes: var = scene["var"] parts = scene["mesh_parts"] data = extract_and_interpolate(mg, var, parts, idx, sim_file, mesh_config) if "clip" in scene.keys(): try: data = data.clip(*scene["clip"]) except: data = data.clip(**scene["clip"]) if "slice" in scene.keys(): try: data = data.slice(*scene["slice"]) except: data = data.slice(**scene["slice"]) data_dict[var] = data if "arrow" in scene.keys(): continue max_val = max(max_val, data[var].max()) min_val = min(min_val, data[var].min()) for i, scene in enumerate(scenes): var = scene["var"] parts = scene["mesh_parts"] data = data_dict[var] if "warp" in scene.keys(): data = data.warp_by_vector(var, scene["warp_fac"]) if interactive: options = scene["interactive"] else: options = scene["static"] if "clim" not in options.keys() or options["clim"] is None: pass #options["clim"] = (min_val, max_val) if "arrow" in scene.keys(): vec_scale = scene["vec_scale"] arrows = data.glyph(scale=var, factor=vec_scale, orient=var) p.add_mesh( arrows, **options) #, lighting=False) #stitle=f"{var} Magnitude", else: p.add_mesh(data, scalars=var, **options) #camera position, focal point, and view up. p.camera_position = cpos return p, (min_val, max_val)
def test_itk_plotting_class_no_scalars(): pl = pyvista.PlotterITK() pl.add_mesh(SPHERE, color='w') pl.camera_position = [[1, 0, 0], [1, 0, 0], [1, 0, 0]] assert isinstance(pl.camera_position, list) pl.background_color = 'k' assert pl.background_color == (0.0, 0.0, 0.0) viewer = pl.show() assert isinstance(viewer, itkwidgets.Viewer)
def test_itk_plotting_points_polydata(): points = pyvista.PolyData(np.random.random((100, 3))) pl = pyvista.PlotterITK() pl.add_points(points) with pytest.raises(TypeError): viewer = pl.add_points([1, 2, 3], point_size='foo') viewer = pl.show() assert isinstance(viewer, itkwidgets.Viewer)
def plot_itk(mesh, color=None, scalars=None, opacity=1.0, smooth_shading=False): """Plot a PyVista/VTK mesh or dataset. Adds any PyVista/VTK mesh that itkwidgets can wrap to the scene. Parameters ---------- mesh : pyvista.Common or pyvista.MultiBlock Any PyVista or VTK mesh is supported. Also, any dataset that :func:`pyvista.wrap` can handle including NumPy arrays of XYZ points. color : string or 3 item list, optional, defaults to white Use to make the entire mesh have a single solid color. Either a string, RGB list, or hex color string. For example: ``color='white'``, ``color='w'``, ``color=[1, 1, 1]``, or ``color='#FFFFFF'``. Color will be overridden if scalars are specified. scalars : str or numpy.ndarray, optional Scalars used to "color" the mesh. Accepts a string name of an array that is present on the mesh or an array equal to the number of cells or the number of points in the mesh. Array should be sized as a single vector. If both ``color`` and ``scalars`` are ``None``, then the active scalars are used. opacity : float, optional Opacity of the mesh. If a single float value is given, it will be the global opacity of the mesh and uniformly applied everywhere - should be between 0 and 1. Default 1.0 smooth_shading : bool, optional Smooth mesh surface mesh by taking into account surface normals. Surface will appear smoother while sharp edges will still look sharp. Default False. Returns -------- plotter : itkwidgets.Viewer ITKwidgets viewer. """ pl = pyvista.PlotterITK() if isinstance(mesh, np.ndarray): pl.add_points(mesh, color) else: pl.add_mesh(mesh, color, scalars, opacity, smooth_shading) return pl.show()
def test_itk_plotting_class_npndarray_scalars(): pl = pyvista.PlotterITK() pl.add_mesh(SPHERE, scalars=SPHERE.points[:, 0]) viewer = pl.show() assert isinstance(viewer, itkwidgets.Viewer)
def test_itk_plotting_class_no_scalars(): pl = pyvista.PlotterITK() pl.add_mesh(SPHERE, color='w') viewer = pl.show() assert isinstance(viewer, itkwidgets.Viewer)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Jun 15 15:49:52 2020 @author: rahul pyvista 3d plotting """ from numpy import cos, pi, mgrid import pyvista as pv from pyvistaqt import BackgroundPlotter #%% Data x, y, z = pi*mgrid[-1:1:31j, -1:1:31j, -1:1:31j] vol = cos(x) + cos(y) + cos(z) grid = pv.StructuredGrid(x, y, z) grid["vol"] = vol.flatten() contours = grid.contour([0]) #%% Visualization pv.set_plot_theme('document') p = pv.PlotterITK() p.add_mesh(contours, scalars=contours.points[:, 2])#, show_scalar_bar=False) p.show()
def __init__(self, phaseObj): super(nbInteractPlotter, self).__init__(phaseObj) self.canvas = pyvista.PlotterITK()
def test_itk_plotting_class_unstructured(hexbeam): hexbeam.clear_data() pl = pyvista.PlotterITK() pl.add_mesh(hexbeam, smooth_shading=True) viewer = pl.show() assert isinstance(viewer, itkwidgets.Viewer)
def interactive_vizualize_ITK(filename): data = pv.read(filename) plotter = pv.PlotterITK() plotter.add_mesh(data) return plotter.show()
def interactive_clip_ITK(filename): data = pv.read(filename) clipped_data = data.clip() plotter = pv.PlotterITK() plotter.add_mesh(clipped_data) return plotter.show()