InsightSoftwareConsortium / ITK-Wasm

High performance spatial analysis in a web browser and across programming languages and hardware architectures
https://wasm.itk.org
Apache License 2.0
194 stars 49 forks source link

vtk unstructureddata (vtu file) file type can be loaded? #693

Open zhangcl-163 opened 1 year ago

zhangcl-163 commented 1 year ago

since vtk.js -itk, unstructureddata file (vtu) can be loaded. in itk-wasm, does it support vtu file type to be loaded? or it is supported in seperate itk-wasm io module?

any suggestions are appreciated!

thewtex commented 1 year ago

Hi @zhangcl-163 ,

vtu is not planned in the current future as far as I am aware; however, .vtk unstructured data is planned around December.

jord1e commented 1 month ago

Hey Matt, did UNSTRUCTURED_DATA get implemented?

My models are working fine with itk.js but itk-wasm is crashing without any usefull error codes so this might be the problem

I don't think I need it, but maybe it would help people in the future

For now I am just doing an extra postprocessing step of converting to XML PolyData:

import vtk

# Step 1: Read the unstructured grid data
reader = vtk.vtkUnstructuredGridReader()
reader.SetFileName("x.vtk")
reader.Update()

# Step 2: Convert the unstructured grid to polydata
geometryFilter = vtk.vtkGeometryFilter()
geometryFilter.SetInputData(reader.GetOutput())
geometryFilter.Update()

# Step 3: Write the polydata to a new VTK file
polydata = geometryFilter.GetOutput()
writer = vtk.vtkXMLPolyDataWriter()
writer.SetFileName("x.vtk")
writer.SetInputData(polydata)
writer.Write()

Than using the https://kitware.github.io/vtk-js/examples/XMLPolyDataWriter.html But it did take some time to figure out that that is possible :)

thewtex commented 1 month ago

@jord1e thanks for sharing the workaround!

I currently do not have plans to add VTU support, but contributions are welcome.

jord1e commented 1 month ago

Thank you for the update!

The workaround is working perfectly, and I am getting WAY better performance as compared to using the vtk.js IO/Legacy vtkITKPolyDataReader/ITKPolyDataReader + itk.js+ setReadPolyDataArrayBufferFromITK

Hoping Google guides people to it ;)