I was researching the best way to send a vtkPolyData object over a network and came across this GitHub issue:
Where @Sebastien_Jourdain states there is a way of converting it to a vtp format and the use XMLPolyDataReader to read it in vtk.js. I could not find an example of converting vtkPolyData to vtp without writing the result to a file using vtkXMLPolyDataWriter.
Is there an example I can see or a project where it’s being done, I would be very grateful to see how I could achieve this.
Yes, I’ve used wslink to create a stream of images to the frontend.
I am exploring something slightly different as I don’t want to render on the backend (because the vtk objects are small-ish), I am more interested in rendering on the frontend, hence the serialisation of a vtkPolyData object.
My idea is to request the data from the frontend, do some processing, then create a cache on the backend (again the need for serialising).
I think I’ve achieved half of it even though I am not sure if this is the best way.
Backend (VTK Python wrapper):
writer = vtkXMLPolyDataWriter()
writer.SetInputData(data)
writer.WriteToOutputStringOn()
writer.Update()
s = writer.GetOutputString()
You can find a trame example pushing the geometry that is visible in a vtkRenderWindow over the network without the need of rendering capability on the server side.
There is also a second example dealing with the conversion more in a manual fashion.