holoviz / panel

Panel: The powerful data exploration & web app framework for Python
https://panel.holoviz.org
BSD 3-Clause "New" or "Revised" License
4.73k stars 516 forks source link

[VTK] Scalar bar enhancement on synchronization #1946

Open petr-henys opened 3 years ago

petr-henys commented 3 years ago

Hello, i want to update the vtk scene with new cell data in mesh object, here is my approach, which does not work:

pl_surface = pv.Plotter(notebook=True)
mesh_actor = pl_surface.add_mesh(mesh)
vtkpan = pn.panel(pl_surface.ren_win, height=500, width=500)

@pn.depends(submit_button)
def draw_realisation():
    mesh.cell_arrays['BMD'] = new_data_array
    pl_surface.update_style()
    pl_surface.update()
    vtkpan.synchronize()

Please, what is the correct way?

Thanks,

philippjfr commented 3 years ago

@ea42gh Any ideas?

xavArtley commented 3 years ago
import numpy as np
import pyvista as pv
import panel as pn
from pyvista.examples import load_ant
pn.extension('vtk')

mesh = load_ant()
pl_surface = pv.Plotter()
mesh_actor = pl_surface.add_mesh(mesh)
vtkpan = pn.panel(pl_surface.ren_win, height=500, width=500)

submit_button = pn.widgets.Button(name="Submit")
@pn.depends(submit_button.param.clicks)
def draw_realisation(clicks):
    if clicks > 0:
        mesh.cell_arrays['BMD'] = np.random.rand(mesh.n_cells)
        mesh_actor.GetMapper().SetScalarMode(2)
        vtkpan.synchronize()

pn.Column(submit_button, vtkpan, draw_realisation)

update_scene

petr-henys commented 3 years ago

Thank you, but according to VTK.js doc here, the cell data is used if point data is not available by default-so why should this method be called?

Now the cell data is updated, but the scalar bar not, see my attempt:

import numpy as np
import pyvista as pv
import panel as pn
from pyvista.examples import load_ant
pn.extension('vtk')

mesh = load_ant()
pl_surface = pv.Plotter()
# initialise cell data here
mesh.cell_arrays['BMD'] = np.random.rand(mesh.n_cells)
mesh_actor = pl_surface.add_mesh(mesh, cmap='rainbow', stitle='BMD')
vtkpan = pn.panel(pl_surface.ren_win, height=500, width=500)

submit_button = pn.widgets.Button(name="Submit")
@pn.depends(submit_button.param.clicks)

def draw_realisation(clicks):
    if clicks > 0:
        new_data = np.random.rand(mesh.n_cells)
        mesh.cell_arrays['BMD'] = new_data
        mesh_actor.GetMapper().SetScalarMode(2)
        pl_surface.update_scalar_bar_range([new_data.min(), new_data.max()], name='BMD') # no effect
        vtkpan.synchronize()

pn.Column(submit_button, vtkpan, draw_realisation)

test1_scalarbarupdate

xavArtley commented 3 years ago

In my example I need to update the mapper because I initialize without setting scalar data. If in your initialisation you already set a scalar array to the cell the SetScalarMode is not required anymore.

For the scalar bar the object does not exist on vtkjs and its a custom panel implementation. Indeed the update is not implemented.

I don't know when I'll have time to look at it.

Le mar. 2 févr. 2021 à 09:33, Petr Henyš notifications@github.com a écrit :

Thank you, but according to VTK.js doc here https://kitware.github.io/vtk-js/api/Rendering_Core_Mapper.html, the cell data is used if point data is not available by default-so why should this method be called?

Now the cell data is updated, but the scalar bar not, see my attempt:

import numpy as np import pyvista as pv import panel as pn from pyvista.examples import load_ant pn.extension('vtk')

mesh = load_ant() pl_surface = pv.Plotter()

initialise cell data here

mesh.cell_arrays['BMD'] = np.random.rand(mesh.n_cells) mesh_actor = pl_surface.add_mesh(mesh, cmap='rainbow', stitle='BMD') vtkpan = pn.panel(pl_surface.ren_win, height=500, width=500)

submit_button = pn.widgets.Button(name="Submit") @pn.depends(submit_button.param.clicks) test1_scalarbarupdate

def draw_realisation(clicks): if clicks > 0: new_data = np.random.rand(mesh.n_cells) mesh.cell_arrays['BMD'] = new_data mesh_actor.GetMapper().SetScalarMode(2) pl_surface.update_scalar_bar_range([new_data.min(), new_data.max()], name='BMD') # no effect vtkpan.synchronize()

pn.Column(submit_button, vtkpan, draw_realisation)

[image: test1_scalarbarupdate] https://user-images.githubusercontent.com/22882861/106573060-78410380-6539-11eb-956f-5a62bd6794e6.gif

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/holoviz/panel/issues/1946#issuecomment-771463274, or unsubscribe https://github.com/notifications/unsubscribe-auth/AENMGS7NR3776M4OSAKPW5LS462EHANCNFSM4WVIBJXA .

xavArtley commented 3 years ago

We can let the issue open for the colorbar update

MarcSkovMadsen commented 3 years ago

@xavArtley . During triaging we kept his open. But it would help if the issue had a more specific title. We don't understand what it should be. Could you update?