Cleaning Function Surface Toolbox does not handle 0 rea faces/duplicate edges

Hello,

I noticed that the clean function in the Surface Toolbox does not handle duplicate edges ie 0 area faces.
Therefore it does not completely fix non manifold meshes.

Here you can see a mesh that I cleaned with the surface toolbox and checked in Blender. The highlighted edges are duplicated:

If I move them you can see the issue:

Would there be a way of adding a fix for this?
Previously I have done a lot of semiautomatic mesh cleaning for FE meshes and 3D printing in Blender but would like to migrate everything to Slicer.

Also, I noticed a possible typo in the logic, should line 575 in SurfaceToolbox.py be

SurfaceToolboxLogic.clean(inputModel, outputModel)

instead of

SurfaceToolboxLogic.clean(outputModel, outputModel) ?

Internally the code uses the vtk class with the default parameters.

But there are lots of options that could address what you are seeing:

https://vtk.org/doc/nightly/html/classvtkCleanPolyData.html

If you change to developer mode you can use the edit and reload options to change the settings and see what works. If you find settings that should be exposed they can be added to the module’s gui.

No, I think the code is correct. The code above what you referenced creates a new polydata if needed and the successive steps in the toolbox operate on that outputModel.

Thanks @pieper

Great, I will look into that vtk class!
I have not tried developer mode yet, that will be a good test case.

And ok, I was mistaken about the typo then, thanks for clarifying.

@pieper the developer mode works well.

I tried adding

cleaner = vtk.vtkCleanPolyData()
cleaner.ConvertLinesToPointsOn()
cleaner.ConvertPolysToLinesOn()
cleaner.ConvertStripsToPolysOn()
cleaner.SetInputData(inputModel.GetPolyData())

However, this does not fix the non manifold issues, since it only covers some, not all, mesh issues.

Would it be possible to incorporate the mesh cleaning functionality from the 3D print add-on in Blender? It is written in Python and would enhance the Surface Toolbox cleaning function.

Here is the mesh that was giving me issues. I generated it by upsampling and remeshing and smoothing, all in Slicer. However, the non manifoldness remains (6 vertices, 2 edges, 2 faces): O45_003_SlicerClean_updatedNormals.stl - Google Drive

Thanks again!
Eva

There are other mesh cleanup options in vtk (see links below - I’m sure there are more if you search). They would be easy to add to the Surface Toolbox or as a separate module if there are lots of options.

But if the blender code works well you should also be able wrap and call a blender-python script as a subprocess. I looked a the code you linked and yes it’s in python, but it relies on the blender libraries to do the work. There is a bpy package, but it didn’t install for me in slicer.

Maybe it’s possible to compile blender and bpy expose its python libraries in slicer’s python, and that could open interesting possibilities, but it would be easier as a start to just run blender in a separate process with its own python and pass meshes as files.

Thank you @pieper !
Seems like the codes in that forum post did not fully work for others but it is a great starting point.

Would be great to make it work with vtk but I will also think about running Blender separately.