vtkFillHolesFilter produces hole filling triangles that have a bad orientation
The vtkFillHolesFilter seems to produces hole filling triangles that have a normal orientation which is inconsistent with the input mesh. I observed this issue in the vtk python wrappers version 8.1.2.
Looking at the vtkFillHolesFilter example, a vtkPolyDataNormals filter is applied after the vtkFillHolesFilter with the comment:
// Make the triangle winding order consistent
This means that at least some people are aware of this issue.
Can anyone explain why the vtkFillHolesFilter behaves in this way? Also, is there a better way to fill the holes correctly without just trying to fix the normals after filling the holes.
Thank you for the help.
A minimal example showing the inconsistent orientation of hole filling triangles.
import vtk
# create a sphere
sphere = vtk.vtkSphereSource()
sphere.SetCenter(0., 0., 0.)
sphere.SetRadius(1.0)
sphere.Update()
# create a clipping plane
plane = vtk.vtkPlane()
plane.SetNormal(0., 0., 1.)
plane.SetOrigin(0., 0., 0.)
# clip the sphere with the plane
clipper = vtk.vtkClipPolyData()
clipper.SetInputData(sphere.GetOutput())
clipper.SetClipFunction(plane)
clipper.Update()
# fill the holes of the clipped result
filler = vtk.vtkFillHolesFilter()
filler.SetInputData(clipper.GetOutput())
filler.SetHoleSize(float(1e10))
filler.Update()
# Create an actor to visualize the result
# front faces will be grey
# back faces will be red
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(filler.GetOutput())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetColor(0.9, 0.9, 0.9)
actor.GetProperty().SetEdgeVisibility(True)
actor.GetProperty().SetInterpolationToFlat()
backprop = vtk.vtkProperty()
backprop.SetColor(1., 0., 0.)
backprop.SetEdgeVisibility(True)
backprop.SetLighting(False)
backprop.SetInterpolationToFlat()
actor.SetBackfaceProperty(backprop)
# Create a window to render the actor
renderer = vtk.vtkRenderer()
win = vtk.vtkRenderWindow()
win.SetSize(512, 512)
win.AddRenderer(renderer)
inter = vtk.vtkRenderWindowInteractor()
inter.SetRenderWindow(win)
renderer.AddActor(actor)
renderer.ResetCamera()
inter.Render()
inter.Start()