Feature request: Mesh smoothing filter in vtkjs

In normal vtk we have the Laplace filter and many other mesh smoothing filters. However none of these are available for vtkjs. It would be good to have at least one simple filter for this.

My current project generates a mesh programatically in javascript, I just need to smooth it.

To expand:

I have tried the Marching cubes filter but is not working as it expects a 3D image data, not a mesh

vtkPolyData=...; // the data

// This doesn't work
let meshSmoother = vtk.Filters.General.vtkImageMarchingCubes.newInstance({computeNormals: true, mergePoints: true});
meshSmoother.setInputData(vtkPolyData);
globalScene.mapper.setInputConnection(meshSmoother.getOutputPort());

// However, this works fine (unsmoothed)
globalScene.mapper.setInputData(vtkPolyData);

The first part launch an exception at reset camera function saying getOrigin is not a function

Uncaught TypeError: a.getOrigin is not a function
    at Vf.e.requestData (vtk.js:2:1014101)
    at Se.e.update (vtk.js:2:749747)
    at s (vtk.js:2:748117)
    at Array.n (vtk.js:2:749576)
    at Se.e.getInputData (vtk.js:2:749300)
    at e.getBounds (vtk.js:2:1279332)
    at vtk.js:2:1290265
    at Array.forEach (<anonymous>)
    at o (vtk.js:2:1289818)
    at e.pick (vtk.js:2:1292360)

I didn’t realized the vtkPolyDataNormals were already available

Solution

const smoother = vtk.Filters.Core.vtkPolyDataNormals.newInstance();
smoother.setInputData(vtkPolyData); // Smooth
mapper.setInputConnection(smoother.getOutputPort());

Then to add scalars, add them to the vtkPolyDataNormals directly, not to the original vtkPolyData

smoother.getOutputData().getPointData().setScalars(PDscalars);

1 Like