stlReader.MergingOff() gives bad polyData

Hi,

We have a website using VTK.js that calls VTK-python functions in the backend. The problem is that both versions of VTK read STLs in a different way. VTK-python will merge vertices of the STL (good), and VTK.js will keep a copy of each vertex per triangle.

I tried to make python behave like js by calling MergingOff(); but this causes the script to quit without warning.

import vtk

stlReader = vtk.vtkSTLReader()
stlReader.SetFileName("mesh.stl")
stlReader.MergingOff() # gives a silent crash
stlReader.Update()
polyData = stlReader.GetOutput()

pdd = vtk.vtkImplicitPolyDataDistance()
pdd.SetInput(polyData)

print("test") # won't reach this statement

I tested with multiple STLs.
Any idea why it crashes like this? Is there a way I could merge vertices in VTK.js?

Belgian greetings,
Emile Sonneveld

If you need the same version of the mesh why don’t you read it on the Python side (server with merging) and send the generated polydata to the client (vtk.js)?

Otherwise, you could add code to merge points on the JS side as well. But is that computation worth it?

That’s what I do now. I send everything back with vtkXMLPolyDayaWriter. It does however add ~2Mb to the request.
I’dd consider that consistency between VTK-python and VTK.js is more important than performance. For us, it the main selling point to prefer it above three.js, or other mainstream WebGL libraries.

I see do you use the zlib+appended format for the writer? It should be much better than the STL format.

Hey, I stumbled upon this issue again. The STLs we load have 3x or even 4x the amount of vertices compared to the Python version. Is there an option to merge them in the frontend? It could drastically improve performance on some operations for us.

I am not sure what zlib+appended format means in this context. The STL’s we use are binary, and sometimes get gzipped by apache before sending to the browser. But they get unzipped again before JavaScript can acces it.