I’m playing with vtk.js in order to better understand it, however I’m currently facing some issues and I certainly can benefit from your help. I would like to do something along the file of:
- A vtkDataset is loaded in A. The user wants to apply a certain operation on it
- A sends a request to a given endpoint in backend B via HTTP, along with the vtkDataset that needs to be manipulated
- Backend B applies the transformation of interest to the dataset
- Final vtkDataset is sent back to A, so that it can be shown to the user
In order to do that easily I created a small backend in node.js and I’m using as frontend A paraview-glance just to avoid reimplementing everything from scratch.
In particular I tried to make an HTTP request once the user click on the “Blur image” button, that can be seen in Tools > Median filter after loading an image (I’m currently using the Covid-19 demo data for this test).
Once the button is clicked, the function runBlur()(from line 146) is called and ideally I would like to move most of its logic in a backend.
However I’m facing problems with the serialization of the vtkDataset, as it returns a nearly empty object, as PointData, CellData and FieldData all have an empty array.
This is how I am serializing the dataset, before sending it to the backend:
// Get the vtkDataset const ds = this.targetImage.getDataset(); // Serialize data const serializer = vtkSerializer.getSerializer(ds); const arrayHandler = vtkSerializer.vtkArraySerializer.newInstance(); const serializedImg = serializer.serialize(ds, arrayHandler); //just for debugging console.log(serializedImg);
I also tried to deserialize the serializedImg and logging it fter serializing it, just to exclude issues in the communication between frontend and backend, using the following code:
const deserializer = vtkSerializer.getDeserializer(serializedImg); const deserializedImg = deserializer.deserialize(serializedImg, arrayHandler);
This leads to an error as I get that deserializer is undefined. If I understood correctly this is due to the fact that vtk.js is unable to infer the actual deserializer that is needed based on serializedImg value.
If I try to circumvent this error by using the following code:
const deserializedImg = serializer.deserialize(serializedImg, arrayHandler);
I get as error:
Cannot create vtkDataArray object without: size > 0, values
In case you were wondering I tried to actually see the pointData array, using the following instruction:
const pointData = ds.getPointData().getScalars().getData();
and in the console I can see the actual data, so that the problem seems to be in how data is converted from vtkDataset to JSON.
Do you have any how to accomplish my initial goal of passing vtkDataset from A to B (and viceversa) using Rest APIs? Is the use of serialize and deserialize correct or is there a better way to move data using classing HTTP requests?
Thanks in advance, I wish you all a nice day!