Using C++ code in VTK.js

Hi,
I am trying to use my existing C++ code in VTK.js. I saw Emscripten related examples.
However, it uses the docker. I simply wanted to C++ code in VTK.js and on Windows platform. is there any other way to accomplish it.

Shrikant

The docker is only meant to compile the code to emscripten/wasm. Docker aims to simplify the setup of the dev tools. But nothing prevent you to build everything yourself.

Also we don’t have any existing path to blend emscripten VTK with vtk.js.

1 Like

Use VTK instead of VTK.js ?

I have converted my VTK C++ desktop app completely to WebAssembly without much effort. I use the docker to compile my wasm and create the counterpart javascript file. I link to those two files in an ASP.NET web project and it is working great. I only have to run the docker when I need to re-compile my wasm and javascript counterpart file. The docker makes life so much easier since the environment is all set up for compiling out of the box.

@Donny_Zimmerman this sounds very interesting. Can you send a link to your project to get an idea of how complex applications and what parts of VTK can be easily compiled to WebAssembly? A link to a live demo would be great, too.

@lassoan here is a link to the live demo. Just click on “Apply Site” after the WebAssembly loads.

http://www.weatherinfosystem.com/WebAssembly/SwisWebRadarViewer/SwisWebRadarViewer.aspx

I am currently building the vtkPolyData and vtkTexture manually in C++ utilizing the radar data from an emscripten_fetch call. All of the callbacks are in C++ for my custom interactor. As you interact, notice how the county lines and the radar data switch places to give better perspective. I am calling the “SetLayer” on the renderers to get this effect.

I am I am currently working on a volume viewer for the full scan radar data. I am unable to tell you if the volume rendering is working or not as I am currently working on the algorithm to interpolate the elevation scans.

1 Like

@lassoan Probably the biggest issue is that OpenGL ES (which WebAssembly uses) doesn’t support TextureBuffers. I had to make some modifications to the VTK code to use point scalars instead of cell scalars to get around the issue. See below thread:

Thank you, your demo works very nicely! Lack of texture buffer seems to be a quite significant limitation. I guess WebGPU supports texture buffers - could WebAssembly be used with WebGPU instead of OpenGL ES?

Yes, WebAssembly can use webgpu with chromium based browser. Emscripten has the headers in include/webgpu However, VTK C++ doesn’t yet implement WebGPU rendering.

There is ongoing work to emulate texture buffers with 2D textures in vtkTextureObject. However, that will be limited by the maximum dimensions of a 2D texture ~ typically 32768x32768