Slice on VTK Volume are unusable

Hi,

I’m using Bokeh with Dash to render 3D Data using VTKVolume.

The bokeh server executed :

#!/usr/bin/python3.8
import os
import sys
import time
import panel as pn
pn.extension('vtk')

def make_vtk_vol(meta, volume_datas):
    DX = float(meta["dx"])
    DY = float(meta["dy"])
    DT = float(meta["dt"])
    print(meta)
    vol = pn.pane.VTKVolume(
        volume_datas,
        spacing=(DX, DY, DT),
        sizing_mode='stretch_both',
        interpolation='fast_linear',
        colormap="Rainbow Blended White",
        render_background="#c0c0c0",
        edge_gradient=1,
        sampling=1.0,
        rescale=True,
        shadow=False,
        orientation_widget=True,
    )
    return vol
def app3d():
    meta, datas = getVisuData() # datas is 3D Numpy array, metas is a dictionnary of property
    vol = make_vtk_vol(meta, datas)
    controls = vol.controls(jslink=True)
    #  print(controls)
    # Select index of interesting controls widget
    good_index = [7, 8, 10, 11, 12, 13, 15, 18, 21, 22, 23]
    subcontrols = [controls[0][i] for i in good_index]
    
    controls[0] = pn.WidgetBox(name='Controls')
    for (i, x) in enumerate(subcontrols):
        controls[0].append(x)
    html_title = pn.pane.HTML(
            """
                <h3>Visualization <h3/>
                <hr>
            """
            )
    controls[0].insert(0, html_title)
    row = pn.Row(controls[0], vol, sizing_mode="stretch_both", scroll=False)
    row.servable()

app3d()

Now the volume rendering works fine, but there is an issue with viewing slices.

Whenever I interact with the Slider to change slice it has a buggy behaviour and jump to numbers that have nothing to do with the range I clicked at on the slider.

If I click on the middle of the slider it will either go down to a very small number or increase to numbers outside volume range. Using slice is simply unusable because I can’t select a correct index on a slider.

What could cause this behaviour ? How can I fix it ?

Your data size must exceed the max_data_size parameter and the data are dowsampled before being sent to javascript side.

Then synchronization between slice on javascript side and python side is wrong since both data on python side and javscript have not the same sampling size.

If you are in a bokeh server don’t use jslink=True for the slices

or you can increase the max_data_size to avoid the downsampling of the datas volume on javascript but depending on your volume size you can hit other limits (transfer through websocket, out of memory because of duplication, transfer time…)

Even if it’s rendered in a browser ?

To start the application I do panel serve --allow-websocket-origin=127.0.0.1:5006 app.py, so since it was in a browser I assumed I needed the jslink = True.

EDIT : Just tested it, it worked without jslink = True. Thanks !

1 Like