Vtk-js: Directly add data to Standalone Web Viewer

Created on 20 Jan 2019  路  10Comments  路  Source: Kitware/vtk-js

Hi! I'm curious if it would be possible to implement something like the code snippet found here for the vtkjs standalone webviewer HTML file.

Why?

I've successfully set up a script that will export a vtkRenderWindow's scene to a .vtkjs file archive in Python (see https://github.com/akaszynski/vtki/pull/57) and I'd like to send the .vtkjs data archive to the standalone viewer so that it could be rendered in the output of a Jupyter/IPython notebook cell.

I have everything set up to handle this, I just can't figure out how to send the data directly to the viewer.

Most helpful comment

Hello, just FYI I'm working on a PR for pyviz/panel to embed vtkjs in notebook. pyviz/panel#312

All 10 comments

It will be possible once I add a similar function within that viewer. Although there might be a better way to do what you are looking for. The base64 embedding is really to save a standalone HTML viewer with its data.

If your iPython cell is basically an iFrame, you could use the ?fileURL=... argument to provide a url to your generated vtkjs file assuming you can serve it.

But maybe @thewtex may have better idea on how to push data to the web client with iPython since he's done a pretty nice integration with itk and vtk.js.

Thanks for the swift response, @jourdain!

assuming you can serve it.

Hm... maybe I could hack together a localhost to serve the .vtkjs archive and pass that URL to the fileURL argument?

Ideally, I'd like to not do a ton of file IO on every call (writing out the .vtkjs archive) but rather send the vtkjs data straight to the standalone viewer then render the HTML string in the IPython cell

I see, I mean I was planning to add such support in the basic viewer but I've been side tracked by other work. If you want you can create a MR on vtk.js for that SceneViewer based on what I did for Glance. It should be fairly easy to do.

Let me know if you need links to point you in the right direction.

Oo yes, could you post some links? I'm not sure where the code is for the Glance viewer to do this...

The importBase64 is here then once you have the file in hand, you should call that function with that option.

Normally you should be able to do so by adding something like SceneExplorer.load(document.querySelector('.content'), { file });

HTH

Thank you! I'll see what I can do

@banesullivan for interfacing with Jupyter, we have itk-jupyter-widgets, which uses vtk.js for rendering.

Data transfer is a major barrier to interactivity, so base64 encoding should be avoided if at all possible. In itk-jupyter-widgets, we use fast compression / decompression, data reduction, and binary data transfer to minimize transfer. We use binary NumPy arrays along with ipydatawidgets serialization / deserialization for working with binary data.

Next up for itk-jupyter-widgets is mesh support. As with images, we would like to support meshes stored as NumPy arrays. Do you think we should support vtki formatted meshes directly?

Hi @thewtex, itk-jupyter-widgets is pretty awesome! I've been eager to see support for general meshes from this library.

Do you think we should support vtki formatted meshes directly?

I'd love to see this happen!! Since all the vtki data objects are just VTK data objects with a few extra methods wrapped on for "Pythonic" access, I think vtki meshes would be perfect for this.

I'm eager to see vtkPolyData (vtki.PolyData) be supported by itk-jupyter-widgets; as for most cases, I'm comfortable applying a vtkExtractGeometry filter and displaying that in the VTKjs rendering rather than an entire mesh dataset. From the description you provided on how you transfer the data, I think vtki objects would provide a major benefit! vtki has much (if not all) the needed infrastructure for direct NumPy interfacing with the VTK objects.

Hello, just FYI I'm working on a PR for pyviz/panel to embed vtkjs in notebook. pyviz/panel#312

Rich visualization in jupyter incorporating vtk.js exists via https://github.com/InsightSoftwareConsortium/itkwidgets

Was this page helpful?
0 / 5 - 0 ratings