# Feature request: Mesh smoothing filter in vtkjs

**URL:** https://discourse.vtk.org/t/feature-request-mesh-smoothing-filter-in-vtkjs/14714
**Category:** vtk.js
**Tags:** proposal, vtkjs
**Created:** [October 15, 2024, 10:07am UTC](https://discourse.vtk.org/t/feature-request-mesh-smoothing-filter-in-vtkjs/14714 "2024-10-15T10:07:10Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Alex\_Vergara](https://discourse.vtk.org/user_avatar/discourse.vtk.org/alex_vergara/32/7082_2.png) [@Alex\_Vergara](https://discourse.vtk.org/u/Alex_Vergara)
#### Post date: [October 15, 2024, 10:07am UTC](https://discourse.vtk.org/t/feature-request-mesh-smoothing-filter-in-vtkjs/14714/1 "2024-10-15T10:07:10Z")

</div>

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.

 ![image](https://discourse.vtk.org/uploads/default/original/2X/7/7ee432a73625740a0690310d3456543ff3d300ff.jpeg)

---

<div class="post-metadata">

### Author: ![Alex\_Vergara](https://discourse.vtk.org/user_avatar/discourse.vtk.org/alex_vergara/32/7082_2.png) [@Alex\_Vergara](https://discourse.vtk.org/u/Alex_Vergara)
#### Post date: [October 15, 2024, 12:31pm UTC](https://discourse.vtk.org/t/feature-request-mesh-smoothing-filter-in-vtkjs/14714/2 "2024-10-15T12:31:48Z")

</div>

To expand:

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

```JavaScript
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

```auto
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)

```

---

<div class="post-metadata">

### Author: ![Alex\_Vergara](https://discourse.vtk.org/user_avatar/discourse.vtk.org/alex_vergara/32/7082_2.png) [@Alex\_Vergara](https://discourse.vtk.org/u/Alex_Vergara)
#### Post date: [October 15, 2024, 2:28pm UTC](https://discourse.vtk.org/t/feature-request-mesh-smoothing-filter-in-vtkjs/14714/3 "2024-10-15T14:28:51Z")

</div>

I didn’t realized the vtkPolyDataNormals were already available

Solution

```auto
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

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

```

 ![image](https://discourse.vtk.org/uploads/default/original/2X/e/e4beaba57227945cbbd2a2acdae720fcfd82926b.jpeg)
