[Python] Convert STL object to VTK geometry in python

Discussão em 'Python' iniciado por Stack, Março 10, 2025.

  1. Stack

    Stack Membro Participativo

    I am wanting to do Boolean operations on STL files with geometric primitives from the VTK library.

    My problem is converting the STL geometry to something that the VTK Boolean objects will except.

    I tried the following...

    import vtk

    filename = 'gyroid.stl'
    reader = vtk.vtkSTLReader()
    reader.SetFileName(filename)
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(reader.GetOutputPort())
    gyroid = vtk.vtkActor()
    gyroid.SetMapper(mapper)

    sphere = vtk.vtkSphere()
    sphere.SetRadius(30)
    sphere.SetCenter(0, 0, 0)

    boolean = vtk.vtkImplicitBoolean()
    boolean.SetOperationTypeToIntersection()
    boolean.AddFunction(gyroid)
    boolean.AddFunction(sphere)


    But get the following error...

    File "D:\Python codes\VTK\untitled8.py", line 29, in <module>
    boolean.AddFunction(gyroid)

    TypeError: AddFunction argument %Id: %V


    It throws the same error if I replace gyroid with mapper

    How do I convert the STL mesh into something useable by VTK? Or cant I do this & need to look elsewhere?

    Continue reading...

Compartilhe esta Página