I'm trying to make a plotter class based on the itkwidgets.Viewer class and I need ways to append datasets and their properties to the scene.
import pyvista as pv
from pyvista import examples
from itkwidgets import view, Viewer
class PlotterITK():
def __init__(self, **kwargs):
self.plotter = Viewer()
def add_mesh(self, mesh, color=None, scalars=None, clim=None,
opacity=1.0, n_colors=256, cmap='viridis',
**kwargs):
"""Adds mesh to the scene"""
if not pv.is_pyvista_obj(mesh):
mesh = pv.wrap(mesh)
if not isinstance(mesh, pv.PolyData):
mesh = mesh.extract_geometry()
if self.plotter.geometries is None:
self.plotter.geometries = [mesh,]
# if color:
# # how do I set the color????? this doesn't work
# self.plotter.geometry_colors = [np.array(pv.parse_color(color)).reshape(-1, 3),]
else:
self.plotter.geometries = self.plotter.geometries.append(mesh)
# if color:
# self.plotter.geometry_colors = self.plotter.geometry_colors.append(pv.parse_color(color))
if scalars is not None:
mesh.active_scalars = scalars
return
def show(self, **kwargs):
"""Show in cell output"""
return self.plotter
mesh = examples.download_st_helens().warp_by_scalar()
# sample usage
plotter = PlotterITK()
plotter.add_mesh(mesh.wireframe(), scalars='Elevation') # pass args for coloring too
plotter.add_mesh(mesh.contour(), color='k') # pass args for coloring too
plotter.show()
This doesn't really work though... @thewtex proposed a solution in #154 (comment) but I cannot get any of this to work because self.plotter.geometries.append(mesh) returns None.
Can we implement a feature to append datasets and their display properties (color/colormap, style, etc.) on the fly?
I'm trying to make a plotter class based on the
itkwidgets.Viewerclass and I need ways to append datasets and their properties to the scene.This doesn't really work though... @thewtex proposed a solution in #154 (comment) but I cannot get any of this to work because
self.plotter.geometries.append(mesh)returns None.Can we implement a feature to append datasets and their display properties (color/colormap, style, etc.) on the fly?