The web version of STLReader getNumberOfPoints results are different from the python version

The same stl file.
in the web, I got the following result

  const STLReader = vtkSTLReader.newInstance();
  await STLReader.setUrl("/stl/a_Cup.stl");
  const pointNum = STLReader.getOutputData().getNumberOfPoints();
  const CellsNum = STLReader.getOutputData().getNumberOfCells();
  console.log(pointNum); // 34848
  console.log(CellsNum); // 11616

in the python, I got the following result

    reader = vtkSTLReader()
    reader.SetFileName("a_Cup.stl")
    reader.Update()
    polyData = reader.GetOutput()
    print(polyData.GetNumberOfPoints())  #5802
    print(polyData.GetNumberOfCells())   #11616

As you can see, the Cells numbers are the same, but the Points numbers are different,Did the web version of STLReader do something special with stl files.
I wanted to use some C++ libraries for vtkPolydata on the web via WebAssembly, but the PointsData I got in web was different from the C++ PointsData

The C++/Python implementation of the STL reader merge duplicated points by default. This is not the case in Javascript.

We would need to bring to VTK.js the “cleanPolyData” filter that can merge points afterwards.

Hth,
Julien.

1 Like

@Sebastien_Jourdain, @will.schroeder I feel this is precisely where drop-in VTK-wasm components could improve feature parity on the web. PolyData inputs from vtk.js can be mapped to a wasm vtkPolyData object without memory transfers - because of similar data model concepts. The public-facing typescript definition of cleanPolyData can mirror existing filters. The underlying js code will forward function calls to vtkCleanPolyData filter.

1 Like