vtkImplicitSelectionLoop does not work as expected

I implemented a function that clips a polydata from another polydata. The clip operation is fine for polys that don’t have sharp corners, but it gives weird results for those with sharp corners. How do I get about this?
def clip(pd1: vtk.vtkPolyData, pd2: vtk.vtkPolyData, inside_out=False) -> vtk.vtkPolyData:
“”"
Clips out regions of pd1 from pd2. The result is a difference pd1 - pd2
Set inside_out = True; if the end result is required to be an intersection of pd1, pd2
:param pd1: a polydata object. This is the one you want to clip.
:type pd1: vtk.vtkPolyData
:param pd2: a polydata object. This is the one you want to use to clip pd1.
:type pd2: vtk.vtkPolyData
:return: a clipped polydata pd1 - pd2 or pd1 \cap pd2
:rtype: None
“”"
inout = vtk.vtkImplicitSelectionLoop()
inout.SetLoop(pd2.GetPoints())
clip = vtk.vtkClipPolyData()
clip.SetInsideOut(inside_out)
clip.SetClipFunction(inout)
clip.SetInputData(pd1)
clip.Update()
return clip.GetOutput()

t-polygon


I applied vtkLoopSubdivisionFilter to
the base polydata and got massive improvements.
subdiv = vtk.vtkLoopSubdivisionFilter()
subdiv.SetInputData(pd1)
subdiv.SetNumberOfSubdivisions(2)
subdiv.Update()
withsubdivs