VTK and WebAssembly

I am excited about the possibility of using VTK on the client browser via WebAssembly. I know there has been some work done to get the non-rendering part of VTK to compile to WebAssembly. I am a little confused why ITK is necessary for this to work. I am still trying to wrap my head around how this all fits together with WebAssembly, ITK, and VTK, so apologies to the ITK people if I sound like I don’t appreciate their work on this. It would be nice to have a VTK only WebAssembly solution.

I am also looking for examples on how to pass the non-rendering VTK WebAssembly pipeline to vtk.js for rendering.

1 Like

You can look at the VTKSrc/Examples/Emscripten/Cxx/* for more details. The ITK part is mostly for leveraging the docker image that allow you to compile your VTK/C++ code into WebAssembly. The ITK community did a tremendous job setting up tools and infrastructure to build itk.js using ITK/C++ to WebAssembly. Here we are simply using their tools and infrastructure. In other words, you do not need ITK/C++ in your VTK/C++ application if you don’t need/want it.

Also, VTK WebAssembly now support rendering but only for geometry not for volume rendering.

Regarding your question between a WebAssembly processing backend and a vtk.js rendering pipeline, I was aiming to create such example but I ran out of time. You need to have a way to pass some typed array that live in the webassembly part to the JS and then transform them so they are part of a vtkImageData or vtkPolyData on the js world.

HTH,

Seb

1 Like

Thanks Sebastien! That clears things up with the ITK/VTK question. I really appreciate the work the ITK folks have put in to make this work.

Are there examples for rendering geometry with VTK/WebAssembly?

I assume there are plans to incorporate volume rendering into WebAssembly at some point. Wish I could help with this effort, but it is a little beyond my skill level at this point. If I can find time I am going to look into pairing the WebAssembly pipeline to vtk.js and will contribute code/examples if I can.

Yes in VTKSrc/Examples/Emscripten/Cxx/*

The readme should help you building and running them yourself.

It seems that C++ code using a vtkMultiThreader, such as vtkImageMapper3D::MakeTextureData() does not work with WebAssembly easily, but how is it possible to turn off threads for emscripten?

In VTK’s core CMakeLists.txt, vtk_module_find_package(PACKAGE Threads) is used to determine availability of threads, and it seems that emscripten still finds posix threads even though they cause problems during runtime (if the wasm is built without threads, the posix functions are missing, and it is built with threads, things get complicated due to SharedArrayBuffer etc.).

Thanks, Sophonet