Closed marcomusy closed 5 years ago
Thanks! I will test vtkplotter today. About volume rendering:
import k3d
import numpy as np
import vtk
from vtk.util import numpy_support
def load_geometry(filename, arrayName=0):
reader = vtk.vtkXMLImageDataReader()
reader.SetFileName(filename)
reader.Update()
imageVTK = reader.GetOutput()
x, y, z = imageVTK.GetDimensions()
return (imageVTK, numpy_support.vtk_to_numpy(
imageVTK.GetPointData().GetArray(arrayName)
).reshape(-1, y, x))
imageVTK, image = load_geometry('./test.vti', 'data')
plot = k3d.plot()
plot += k3d.volume(image.astype(np.float16),
color_map=k3d.colormaps.matplotlib_color_maps.Gist_heat,
bounds = imageVTK.GetBounds(),
color_range=[0,600])
plot.display()
Please be aware about different bounds meaning in k3d and vtk. The strict version should looks:
np.array(imageVTK.GetBounds()) + \
np.repeat(np.array(imageVTK.GetSpacing()) / 2.0, 2) * np.array([-1,1] * 3)
I Hope that will works for you!
@artur-trzesiok
It works great and the rendering quality is truly awesome, I only had to change from np.float16
to np.float32
:
ps: the image is a scan of a mouse embryo after ~12 days development :)
Transfer function for the opacity is a quite critical feature. Have you seen any good Transfer function editor that works in Jupyter environment? I would preffer to reuse a component rather than make a dedicated one in K3D.
ps. Great work! The dataset of mouse embryo is a open and can be downloaded from web via http? I would like to add this volume as a example in K3D like https://k3d-jupyter.readthedocs.io/en/latest/examples/volume.html
Hi @artur-trzesiok I don't know of any transfer function for jupyter.., I see that now the transparency is goes linearly (if i'm not wrong) with the scalar. But i must say the outcome is visually good now already..
You can pick the volumes here: https://github.com/marcomusy/vtkplotter/blob/master/vtkplotter/data/embryo.slc (higher res) https://github.com/marcomusy/vtkplotter/blob/master/vtkplotter/data/embryo.tif (low res)
@marcinofulus @marcomusy I used embryo as example in volume and transfer function editor. Look at devel branch
looks great!
@artur-trzesiok Thanks for this amazing module! I've added it as a dependency to the vtkplotter module. I will now try to manage how to do the volumetric visualization..