# Mesh internal surface smoothing behavior changed in vtkWindowedSincPolyDataFilter

**URL:** https://discourse.vtk.org/t/mesh-internal-surface-smoothing-behavior-changed-in-vtkwindowedsincpolydatafilter/8446
**Category:** Support
**Created:** [May 8, 2022, 10:44pm UTC](https://discourse.vtk.org/t/mesh-internal-surface-smoothing-behavior-changed-in-vtkwindowedsincpolydatafilter/8446 "2022-05-08T22:44:14Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [May 8, 2022, 10:44pm UTC](https://discourse.vtk.org/t/mesh-internal-surface-smoothing-behavior-changed-in-vtkwindowedsincpolydatafilter/8446/1 "2022-05-08T22:44:14Z")

</div>

It seems that the [rewrite of vtkWindowedSincPolyDataFilter (that amazingly improved its performance)](https://discourse.vtk.org/t/vtkwindowedsincpolydatafilter-performance-improvement/3262) also changed how internal surfaces are smoothed. Smoothing of internal surfaces are important because when we segment a medical image we usually annotate many adjacent structures that have common surfaces and when we apply smoothing then we want to smooth surface of each structure and not just the outer surface of the entire segmented region.

The old version (VTK8) smoothed the internal surfaces, while the new version (VTK9) does not seem to smooth internal edges at all.

 ![image](https://discourse.vtk.org/uploads/default/original/2X/a/a6609463fa083082648046345fffa4dbc0f3e28e.png)

I’ve tried to adjust all parameters (BoundarySmoothingOn/Off, FeatureEdgeSmoothingOn/Off, NonManifoldSmoothingOn/Off, FeatureAngle, EdgeAngle, NormalizeCoordinatesOn/Off) but I could not find any settings that would smooth the internal surfaces.

@will.schroeder Is this difference expected? Could there be any preprocessing or filter parameter combination that would allow smoothing internal surfaces?

## Example

### Input surface

 ![image](https://discourse.vtk.org/uploads/default/original/2X/0/0b925596e2daf4acbb2bfcc062e8f0f14720c868.png)

### Smoothed surface using **old** vtkWindowedSincPolyDataFilter

Boundary between segments are smoothed. There is some bubbling due to the strong smoothing factor (we used somewhat stronger smoothing as usual to make all differences easier to see).

 ![image](https://discourse.vtk.org/uploads/default/original/2X/8/86f82ca0218d60fca3654ddfd74a28361e32be14.png)

### Smoothed surface using **new** vtkWindowedSincPolyDataFilter

Outer surface is smoothed - good. There is no bubbling (outer surface remains smooth) - good (better than the old version). However, internal edges remain sharp and jagged - not good, they are not smoothed at all.

 ![image](https://discourse.vtk.org/uploads/default/original/2X/5/5e7a529fe0078b2fae4eac8c870c6bbc83aa7d19.png)

### How to reproduce

Run the Python script below on [this data set](https://github.com/lassoan/PublicTestingData/releases/download/data/20220508-WindowedSincInternalEdgeSmoothing.zip), using the old and new version of vtkWindowedSincPolyDataFilter (in the zip file I’ve included both outputs, so the results can be compared without running the script).

```python
# WindowedSyncPolyDataFilter internal edge smoothing test

reader = vtk.vtkXMLPolyDataReader()
reader.SetFileName("c:/tmp/smootherinput.vtp")

smoother = vtk.vtkWindowedSincPolyDataFilter()
smoother.SetInputConnection(reader.GetOutputPort())
smoother.SetNumberOfIterations(100)
smoother.SetPassBand(0.0001)
smoother.NormalizeCoordinatesOn()
smoother.FeatureEdgeSmoothingOff()
smoother.SetFeatureAngle(90.0)
smoother.SetEdgeAngle(15.0)
smoother.BoundarySmoothingOff()
smoother.NonManifoldSmoothingOn()

smoother.Update()
writer = vtk.vtkXMLPolyDataWriter()
writer.SetInputConnection(smoother.GetOutputPort())
writer.SetFileName("c:/tmp/smootheroutput.vtp")
writer.Update()
writer.Write()

```

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [May 9, 2022, 9:30am UTC](https://discourse.vtk.org/t/mesh-internal-surface-smoothing-behavior-changed-in-vtkwindowedsincpolydatafilter/8446/2 "2022-05-09T09:30:51Z")

</div>

Thanks Andras for bringing this to our attention. The filters should produce the same results so this needs to be fixed.

By internal edges, are you using vtkDiscreteMarchingCubes (or equivalent) to produce non-manifold edges (i.e., edges used by more than two triangles/polygons)?

Unfortunately I’ve got some heavy deliverables this month, but as soon as I can I will look into this. I suspect that it may be related to the smoothing network as it relates to non-manifold edges.

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [May 9, 2022, 11:28am UTC](https://discourse.vtk.org/t/mesh-internal-surface-smoothing-behavior-changed-in-vtkwindowedsincpolydatafilter/8446/3 "2022-05-09T11:28:01Z")

</div>

> [@will.schroeder](#):
>
> By internal edges, are you using vtkDiscreteMarchingCubes

Yes, we use vtkDiscreteMarchingCubes, to generate the input mesh from a label volume (see [here](https://github.com/Slicer/Slicer/blob/master/Modules/Loadable/Segmentations/EditorEffects/Python/SegmentEditorSmoothingEffect.py#L367:L422).

> [@will.schroeder](#):
>
> as soon as I can I will look into this

Sounds great, thank you.

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [May 10, 2022, 8:42am UTC](https://discourse.vtk.org/t/mesh-internal-surface-smoothing-behavior-changed-in-vtkwindowedsincpolydatafilter/8446/4 "2022-05-10T08:42:12Z")

</div>

@lassoan something like this may also make a good example.

If you’re really busy, I’m happy to do both a Python & C++ example form what you have provided once the internal edge smoothing is fixed…

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [May 10, 2022, 9:16am UTC](https://discourse.vtk.org/t/mesh-internal-surface-smoothing-behavior-changed-in-vtkwindowedsincpolydatafilter/8446/5 "2022-05-10T09:16:29Z")

</div>

Andrew this would be good. Part of the reason is that I hope to complete Surface Nets 3D in June, which (should be) a superior version of vtkDiscreteMarchingCubes. It would be good to have an example for that as well.

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [May 10, 2022, 9:45am UTC](https://discourse.vtk.org/t/mesh-internal-surface-smoothing-behavior-changed-in-vtkwindowedsincpolydatafilter/8446/6 "2022-05-10T09:45:12Z")

</div>

Excellent! Keep me in the loop … please.

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [June 26, 2022, 9:13am UTC](https://discourse.vtk.org/t/mesh-internal-surface-smoothing-behavior-changed-in-vtkwindowedsincpolydatafilter/8446/7 "2022-06-26T09:13:39Z")

</div>

Andras, I’ve tracked this down. I’m scratching my head a little bit because there’s an argument to be made that the previous incarnation of vtkWindowedSincPolyDataFilter had incorrect behavior. If nothing else the documentation was confusing. Basically what happened is that if NonManifoldSmoothing was on, the filter ignored non-manifold edges, i.e., treated them as simple edges, and ignored everything else (feature edges, edge angle, etc.)

I don’t think it’ll be hard to replicate the old behavior, I’ll poke at this and let you know where we are. I’ll need you to approve the MR if we get to that point.

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [June 26, 2022, 7:20pm UTC](https://discourse.vtk.org/t/mesh-internal-surface-smoothing-behavior-changed-in-vtkwindowedsincpolydatafilter/8446/8 "2022-06-26T19:20:52Z")

</div>

Thanks a lot in advance!

If the current behavior is useful, too, then maybe new flag(s) could be added to allow choosing between the old and the new behavior.

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [July 1, 2022, 11:01am UTC](https://discourse.vtk.org/t/mesh-internal-surface-smoothing-behavior-changed-in-vtkwindowedsincpolydatafilter/8446/9 "2022-07-01T11:01:38Z")

</div>

Andras, an update.

Now that I’ve dug into this the old filter, in combination with vtkDiscreteMarchingCubes, IMO it is pretty ugly when it comes to dealing with non-manifold smoothing (i.e., multiple labels).

- First of all, the smoothing stencil is incorrect, each non-manifold edge is added to the smoothing stencil N times, where N is the number of cells sharing the non-manifold edge. So for example (from the data you gave me), the newer version of vtkWIndowedSincPolyDataFilter will typically have 7 edge connections in the stencil, while the older version has 16 (3 nonmanifold edges used by four cells each adds an additional 3 repeated edges per nonmanifold edge adding a total of 9 additional edges). This has the unexpected side effect of heavily weighting the nonmanifold edges during the smoothing process, which miraculously produces better smoothing results in many cases. (Whether this is intentional or not I can’t tell - there are no comments in the code to this effect - it looks like a bug to me.)

- Second, if you really look at a smoothed mesh containing lots of nonmanifold contact edges, it is quite bad IMO to the point that I’d be worried about using it in analysis. Visually yes, it often looks better, but wow the resulting mesh self intersects all over the place (along the interface between two different segmented objects).

So what to do? Here are some thoughts; I’d like to hear yours as well.

1. I believe that I can reproduce the old behavior by adding an additional flag something like “WeightNonManifoldEdgesOn/Off()” to the current incarnation of vtkWIndowedSincPolyDataFilter.
2. In the long run, I think that a Surface Nets algorithm is going to give superior results (and I am working on that now although it’s going to take some time to get it tested and ready for production).

Is it important to reproduce the old behavior? Or should we just shoot for an improved discrete isocontouring algorithm (i.e., surface nets)? Or both?

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [July 1, 2022, 8:08pm UTC](https://discourse.vtk.org/t/mesh-internal-surface-smoothing-behavior-changed-in-vtkwindowedsincpolydatafilter/8446/10 "2022-07-01T20:08:36Z")

</div>

Thanks a lot for your continued effort on this.

> [@will.schroeder](#):
>
> This has the unexpected side effect of heavily weighting the nonmanifold edges during the smoothing process, which miraculously produces better smoothing results in many cases.

It was always kind of a mystery why or how it all worked (it was mainly developed by Bill Lorensen about 15 years ago, maybe he knew), but the results were good - smoothed internal boundaries with very little or no overlap between structures.

> [@will.schroeder](#):
>
> it is quite bad IMO to the point that I’d be worried about using it in analysis

Maybe we were not bothered by mesh quality problems because we most often used it for visualization; for analysis we usually rasterized it back to binary images.

> [@will.schroeder](#):
>
> I believe that I can reproduce the old behavior by adding an additional flag something like “WeightNonManifoldEdgesOn/Off()” to the current incarnation of vtkWIndowedSincPolyDataFilter.

This would be great. Both because of timing (there would be no time pressure for the new Surface Nets algorithm development) and also to have a baseline to compare the Surface Nets algorithm to. Also, if the Surface Nets algorithm works in a completely different way then there is a chance that for some problems some users will still prefer using the previous method.

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [July 14, 2022, 3:18pm UTC](https://discourse.vtk.org/t/mesh-internal-surface-smoothing-behavior-changed-in-vtkwindowedsincpolydatafilter/8446/11 "2022-07-14T15:18:38Z")

</div>

@will.schroeder We have found out today that this change in behavior caused a regression in our heart leaflet analysis workflow (leaflets are pulled away from each other now when the segmentation is smoothed). If we need to revert to a several-year-old software version where joint smoothing worked then we would need to redo a _lot_ of validation work. So, it would save us a lot of time if you could add that flag to the filter to restore the old behavior.

We have a pressing deadline for this (we need to resubmit a revision for a journal paper within a few weeks that requires this fix). When do you think you could add the flag to reproduce the old behavior?

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [July 15, 2022, 6:35am UTC](https://discourse.vtk.org/t/mesh-internal-surface-smoothing-behavior-changed-in-vtkwindowedsincpolydatafilter/8446/12 "2022-07-15T06:35:10Z")

</div>

Andras I am on vacation through the 21st of July. It’s top of my list when I return; I’m hoping that the fix will be made quickly soon after that.

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [July 15, 2022, 8:48am UTC](https://discourse.vtk.org/t/mesh-internal-surface-smoothing-behavior-changed-in-vtkwindowedsincpolydatafilter/8446/13 "2022-07-15T08:48:54Z")

</div>

Sounds good, thanks a lot!

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [July 27, 2022, 12:24pm UTC](https://discourse.vtk.org/t/mesh-internal-surface-smoothing-behavior-changed-in-vtkwindowedsincpolydatafilter/8446/14 "2022-07-27T12:24:54Z")

</div>

@will.schroeder Have you been able to make progress in this?

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [July 28, 2022, 10:57am UTC](https://discourse.vtk.org/t/mesh-internal-surface-smoothing-behavior-changed-in-vtkwindowedsincpolydatafilter/8446/15 "2022-07-28T10:57:25Z")

</div>

I’ve blocked out time tomorrow to knock this out. Hopefully I’ll have good news then - I’ll let you know one way or the other tomorrow.

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [July 29, 2022, 8:38pm UTC](https://discourse.vtk.org/t/mesh-internal-surface-smoothing-behavior-changed-in-vtkwindowedsincpolydatafilter/8446/16 "2022-07-29T20:38:53Z")

</div>

Andras FYI I am definitely seeing improvement, the results aren’t quite the same. I’m going to continue tomorrow morning…
