Implement 3D ROI evaluation
Determine a ROI within a 3D array interactively in a headless Jupyter instance.
This should be possible out-of-the-box with itkwidgets
:
import itkwidgets as itkw
iso_view = itkw.view(qspace_avg, select_roi=True)
display(iso_view)
however the iso_view.roi
attribute does not get updated by changing the selection (and vice-versa) - a bug yet to be resolved (having a glance at the JS console suggests it's coming from there). The developer seems to have not looked at such stuff for more than a year, perhaps it's never going to happen.
In pyvista
, this is also in principle straightforward, but does not seem to be possible with a headless server without xvfb
installed (I could try to request this to T. Vincent). Most backends segfault, while pythreejs
works but does not support widgets, so this does not expose the ROI handles:
import pyvista as pv
pl = pv.Plotter()
grid = pv.UniformGrid(
dims=np.array(qspace_avg.shape),
origin=(0,0,0),
spacing=(1,1,1)
)
grid.point_data['values'] = qspace_avg.flatten(order='F')
mesh = grid.contour(
isosurfaces=[50000],
scalars=grid.point_data['values'],
method='marching_cubes'
)
box = pl.add_mesh_clip_box(mesh)
pl.show(jupyter_backend='pythreejs')
Whereas the itkwidgets
backend does not expose the ROI widget at all (works great otherwise).
vedo
similarly appears either to segfault or raise a useless error, even when using the k3d
backend which should be fine.
In principle mayavi
could be an option. It is still being maintained it seems. Example notebook