"Solidification algorithm" with fill holes filter issue -- Python

Hello everyone,

I’m new to VTK, I want to create a “Solidification Algorithm” to close a surface using Fill Holes Filter.
My problem is that the filter seems to be apply only on each polydata even after the merge.

I’ve try to play with SetHoleSize but it only close the inner radius. Am I missing something ?

Here is simple code to show what I want to do.

import vtk

# create a rendering window and renderer

ren = vtk.vtkRenderer()

renWin = vtk.vtkRenderWindow()

renWin.AddRenderer(ren)

# create a renderwindowinteractor

iren = vtk.vtkRenderWindowInteractor()

iren.SetRenderWindow(renWin)

# create source

source = vtk.vtkDiskSource()

source.SetInnerRadius(1)

source.SetOuterRadius(2)

source.SetRadialResolution(100)

source.SetCircumferentialResolution(100)

source.Update()

#Same second source

source_2 = vtk.vtkDiskSource()

source_2.SetInnerRadius(1)

source_2.SetOuterRadius(2)

source_2.SetRadialResolution(100)

source_2.SetCircumferentialResolution(100)

source_2.Update()

#Define transform

transform = vtk.vtkTransform()

transform.Translate(0,0,1)

#Apply Filter

transform_filter = vtk.vtkTransformPolyDataFilter()

transform_filter.SetInputConnection(source_2.GetOutputPort())

transform_filter.SetTransform(transform)

transform_filter.Update()

#Merge polydata

mergepolydata = vtk.vtkAppendPolyData()

mergepolydata.AddInputData(source.GetOutput())

mergepolydata.AddInputData(transform_filter.GetOutput())

mergepolydata.Update()

#Clean Polydata

clean = vtk.vtkCleanPolyData()

clean.SetInputConnection(mergepolydata.GetOutputPort())

clean.Update()

#Apply fill holes filter to close surface

fill = vtk.vtkFillHolesFilter()

fill.SetInputConnection(clean.GetOutputPort())

fill.SetHoleSize(1)

fill.Update()

# mapper

mapper = vtk.vtkPolyDataMapper()

mapper.SetInputData(fill.GetOutput())

# actor

actor = vtk.vtkActor()

actor.SetMapper(mapper)

# assign actor to the renderer

ren.AddActor(actor)

# enable user interface interactor

iren.Initialize()

renWin.Render()

iren.Start()

Thanks in advance,

Pierre.

Hole filling is not a solidifer algorithm - it does not guarantee that it creates watertight mesh. VTK-based shrink-wrap solidifer algorithm implementation has been recently added to 3D Slicer. If you find that it works well for you then you can either use it within 3D Slicer (if you are developing a medical application) or take the source code and copy-paste and maintain it in your own application.

It would be nice to have a cleaned-up and generalized shrink-wrap filter natively in VTK (in C++) it could be more accessible and discoverable than a custom Python script.

The code that you included above is very hard to read. Please enclose python code in triple-backtick to preserve original formatting. For example:

```python
my code
some more code
```
1 Like

Thanks for your reply and the enclose python code tips !
I will try to use this shrink-wrap solidifier algorithm in my own application and let you know.

1 Like