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
916 stars 123 forks source link

Does k3d-jupyter support to render a time series of 3D volume? #444

Closed tfunatomi closed 6 months ago

tfunatomi commented 6 months ago

Description

I want to render a time series of a 3D volume. It seems that the animation for the time series works, but the rendering result looks strange.

What I Did

When I try to render a time series of a 3D volume by passing a dictionary to k3d.mip or k3d.volume, there is no error but the rendering result becomes very different from the one when rendering a time step.

import k3d
import numpy as np
import SimpleITK as sitk

im_sitk = sitk.ReadImage('./heart.mhd')
img = sitk.GetArrayFromImage(im_sitk)

plot = k3d.plot()
plt_mip_o = k3d.mip(img.astype(np.float32), name='MIP of one timestep')
plt_mip_o.visible = False # Just for comparison
plot += plt_mip_o
plt_mip_t = k3d.mip({0:img.astype(np.float32)}, name='MIP of a time series')
plot += plt_mip_t
plot.display()

I would be grateful if you could help me.

artur-trzesiok commented 6 months ago

Hi @tfunatomi !

k3d.volume and k3d.mip have important parameter called "color_range". For static data it is calculated authomatically if user will not pass it. For time series data that automation is disabled. So if you will pass color_range like that:

plt_mip_t = k3d.mip({0:img.astype(np.float32)}, 
                    color_range = [0.0, 1000.0], 
                    name='MIP of a time series')

everything will be fine. Thanks for spoting that problem. I should either add infomation about that constraint to docs or implement feature to calculate color_range for timeseries data.

btw. Please remember that in animation parameters are interpolated using js. So in your case you will try to interpolate 317x 512 x 512 floats number in pure js. That will be slow. Animation in k3d have special rule that if time == exactly a keypoint interpolation will be avoided.

btw. I have in my mind idea to do interpolation for k3d.volume and k3d.mip on shader level.

artur-trzesiok commented 6 months ago

Thanks @tfunatomi . Fix is on devel

artur-trzesiok commented 6 months ago

Hi! Please check https://pypi.org/project/k3d/2.16.1/ :)

tfunatomi commented 6 months ago

I appreciate your quick response! It's so helpful :)