Trying to view vtu or vtk file in the web

If I wasn’t clear before, afaik, the readers you’re looking for are not available in vtk.js and itk.

The readers for *.vtk and *.vtu files are in VTK which is a C++ library, different from vtk.js.

In case you haven’t heard about wasm. WebAssembly is a technology that lets web browsers natively execute C++ code (instead of JavaScript). Some VTK users choose this path to benefit from the performance and full functionality of the VTK C++ library in a web browser.

Coming back to your question, the relevant classes are vtkUnstructuredGridReader and vtkXMLUnstructuredGridReader. This example code
https://examples.vtk.org/site/Cxx/IO/ReadAllUnstructuredGridTypes/ shows how to use the reader and view it’s output in a renderer.

You have three potential paths:

  1. Forget about wasm and implement a vtk/vtu reader in vtk.js. You’d have to look at the C++ implementation for the readers and translate them to javascript.
  2. Leverage VTK C++/wasm through trame-vtklocal. This will involve writing mostly Python code and you will have to rethink your existing vtk.js application. There are a number of examples inside that repository.
  3. Leverage VTK C++/wasm directly. Again, there are many examples in https://gitlab.kitware.com/vtk/vtk/-/tree/master/Examples/Emscripten/Cxx?ref_type=heads. Review the code to understand how it is possible to instantiate C++ classes from JavaScript, then restructure it to use a vtu/vtk reader.