K3D-tools / K3D-jupyter

K3D lets you create 3D plots backed by WebGL with high-level API (surfaces, isosurfaces, voxels, mesh, cloud points, vtk objects, volume renderer, colormaps, etc). The primary aim of K3D-jupyter is to be easy for use as stand alone package like matplotlib, but also to allow interoperation with existing libraries as VTK.
MIT License
953 stars 121 forks source link

Widget crashes when updating voxels multiple times #456

Open ankardon opened 5 months ago

ankardon commented 5 months ago

Note (please remove it):

Description

Changing the voxels for a voxel plot repeatedly keeps increasing gpu memory usage. After a few iterations (~30), the webview crashes.

What I Did

import k3d
import time
from k3d import matplotlib_color_maps

plot = k3d.plot(axes=["","",""], camera_mode="orbit")
vox = k3d.voxels(np.ones((256,256,32)).transpose(2,0,1), color_map=cmap,compression_level=-1)
plot += vox

plot.display()

import ipywidgets as widgets
text = widgets.IntText()

slider = widgets.IntSlider(min=0, max = scene.sequence_length)

@debounce(0.2)
def on_change(x):
    data = load.Scene(8,5*x.new).voxel_label
    data[data == 255] = 0
    print(id(vox.voxels))
    vox.voxels = data.transpose(2,0,1)

widgets.jslink((text, 'value'), (slider, 'value'))
slider.observe(on_change, "value")
widgets.HBox([text, slider])
artur-trzesiok commented 4 months ago

Hi @ankardon !

Sorry but your example isn't working. Voxels are pretty intensive in terms of cpu and gpu. Crash can happend. To analyse it I need to have proper example and data. Btw outlines are pretty intensive too.