VTK WebAssembly Calling vtkXMLImageDataReader and vtkXMLPolyDataReader with URL's

I have compiled VTK with Emscripten and have gotten the VTK Emscripten/C++ examples working on a demo website. I would like to do a full VTK pipeline in WebAssembly including fetching the imagedata and polydata from a URL resource. I haven’t tried it yet, but I suspect it will not work. Has anybody else tried to fetch data with the VTK C++ readers from a URL resource?

I am going to try to use emscripten fetch with the URL and then convert the result from char* to std::string. I can then set the ReadFromInputString flag to true on the vtkXMLImageDataReader and set the InputString member of the vtkXMLImageDataReader to the std::string. I will update if this works.

2 Likes

Hi,

Is there any progress? I have the same issue just like you have. After compile webassembly, i don’t know how to reader file from a external url.

Have you considered using ITK.wasm to load your VTK dataset ?

As far as I know, ITK.wasm only support vtk image data and polydata, but i need to reader unstructured grid data. So far I can only use C++ Emscripten to compile wasm file.

I try to call vtkXMLUnstructuredGridReader to load a .vtu file, but it prompts “Error opening file **.vtu”. Does anyone know how to read a vtk file with WebAssembly?

Yes, that will not work unless you placed the file in wasm memory file system using memfs from javascript.

For alternative, you can refer to this section of C++ code on how to load .vtu files in vtk.wasm - GeometryViewer.cxx#L211 and the corresponding javscript code to invoke that function - GeometryViewer.vue#L95