Can I import PolyData of vtk with python

Can I import this PolyDataFilter of vtk with python.

Yes, that is available via python:

>>> vtk.vtkBooleanOperationPolyDataFilter()
(vtkFiltersGeneralPython.vtkBooleanOperationPolyDataFilter)0x7fae97fa98d8

Boolean operation on meshes are extremely difficult to implement correctly. Most implementation are flawed, including expensive commercial software and various open-source libraries. Unfortunately, VTK’s vtkBooleanOperationPolyDataFilter() is very unreliable, too. It randomly gives incorrect results (typically large artifacts appearing at various places) even for well-behaved, completely valid inputs.

If you need reliable Boolean mesh operations then you can convert meshes to labelmap images, perform Boolean operation in the image domain, then convert the result to mesh. This is of course a somewhat lossy operation, but that’s the only reliable solution that is readily available. You can achieve arbitrarily high fidelity, at the cost of increased memory usage and computation time. This approach is used in Segment Editor / Logical operations effect.

Thanks.
Dear Pieper,
I donnot know how to set the parameters? The follow code I tried seems wrong… and could you help me correct it, thanks.

    input1 = model1.GetOutput()
    sphere1Tri = vtk.vtkTriangleFilter()
    sphere1Tri.SetInputData(input1)

    #model2
    input2 = model2.GetOutput()
    sphere2Tri = vtk.vtkTriangleFilter()
    sphere2Tri.SetInputData(input2)
    #booleanOperation

    booleanOperation = vtk.vtkBooleanOperationPolyDataFilter()
    # booleanOperation.SetOperationToUnion()
    booleanOperation.SetOperationToIntersection()
    # booleanOperation.SetOperationToDifference()

    booleanOperation.SetInputConnection(0, model2)
    booleanOperation.SetInputConnection(1, model1)
    booleanOperation.Update()

Dear Lassoan
Thank you very much.
I just try to run it between two cylinder.

It can randomly fail, even for two simply cylinders, depending on their size and position.

I agree with Andras - booleans on polydata are fragile due to numerical rounding issues.

In any case if you want to try it you need something like:

booleanOperation.SetInputConnection(0, sphere2Tri.GetOutputPort())

because it needs the pipeline, not just the data as input.

Hi Andras,
Why the vtkpolydata has no faces and no face_normals.

I’m not sure what you mean or how it is related to the discussion above. If your question is still relevant then please post it in a new topic, describing in detail what you do, what you expect to happen, and what happens instead.