What is the best way to send a single and/or a stream of vtkPolyData over a network?


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.

Thank you very much.

Have you considered wslink (low level) or trame (high level) to do vtk networking?

They rely on the render_window_serializer python module.

Alternatively you can consider export_scene_macro (recent PR).

Hi @finetjul :slight_smile:

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()
s = writer.GetOutputString()

Frontend (vtk.js):

const reader = vtkXMLPolyDataReader.newInstance();
const textEncoder = new TextEncoder();
const { mapper } = context.current; // context contains the actor/mapper, etc

At the moment I am not able to see anything yet (which might be related to my incorrect camera settings).

But I would appreciate if you could tell if this is a correct solution for my problem stated above. Different approaches are welcome.

Thank you for your help.

Then you should consider the render_window_serializer script along with SynchronizableRenderWindow

Thanks Julien, sorry for the delayed reply.

Is there an example on how to use them together?
Do I need to use wslink if I use them?

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.

Thank you Sebastien.
I will refer to those two examples to continue my work.