Trying to find points that intersect a plane Python

Hi,

I have an .obj file and I’m trying to find points on the file that intersect a given plane.

I did try to use vtkIntersectionPolyDataFilter. I did this by trying to create a plane using

import object

reader = vtk.vtkOBJReader()

reader.SetFileName(fpath)

reader.Update()

mapper = vtk.vtkPolyDataMapper()

if vtk.VTK_MAJOR_VERSION <= 5:
mapper.SetInput(reader.GetOutput())
else:
mapper.SetInputConnection(reader.GetOutputPort())

actor = vtk.vtkActor()

actor.SetMapper(mapper)

plane1

center1= [x,y,z]
plane1 = vtk.vtkPlaneSource()

plane1.SetCenter(centre1)

plane1.SetNormal(0.0, 0.0, 1.0)

mapper1 = vtk.vtkPolyDataMapper()

mapper1.SetInput(plane1.GetOutput())

actor1 = vtk.vtkActor()

actor1.SetMapper(mapper)

intersection_operation = vtk.vtkIntersectionPolyDataFilter()
intersection_operation.SetInputData(1, actor)
intersection_operation.SetInputData(0, actor1)
intersection_operation.Update()

print("# of crosses: " + str(intersection_operation.GetNumberOfIntersectionPoints()))

However when I run this I get:

AttributeError: ‘vtkmodules.vtkRenderingOpenGL2.vtkOpenGLPolyDataMa’ object has no attribute ‘SetInput’

I’m not sure if there is an easier way to do what I’m trying to do, but I’m pretty lost as to why this is happening. I’m pretty new to python and to vtk. Any help would be greatly appreciated.

Update:

I managed to get VTK cutter working, which has allowed me to cut the object at a given plane. However, I don’t really understand how to extract the coordinate locations of the surface object. This follows on from the original script, but replaces the code from plane1:

create first plane using face1

plane1 = vtk.vtkPlane()

plane1.SetOrigin(centre1)

plane1.SetNormal(0.0, 0.0, 1.0)

create first plane using face2

plane2 = vtk.vtkPlane()

plane2.SetOrigin(centre2)

plane2.SetNormal(0.0, 0.0, 1.0)

create cutter

cutter = vtkCutter()

cutter.SetCutFunction(plane1)

cutter.SetInputConnection(reader.GetOutputPort())

cutter.Update()

cutterMapper = vtkPolyDataMapper()

cutterMapper.SetInputConnection(cutter.GetOutputPort())

extract = vtkExtractGeometry()

extract.SetInputConnection(cutter.GetOutputPort())

create plane actor

planeActor = vtkActor()

planeActor.GetProperty().SetColor(colors.GetColor3d(‘Black’))

planeActor.GetProperty().SetLineWidth(100)

planeActor.GetProperty().SetAmbient(1.0)

planeActor.GetProperty().SetDiffuse(0.0)

planeActor.SetMapper(cutterMapper)

create renderers and add actors of plane and object

ren = vtkRenderer()

ren.AddActor(planeActor)

ren.AddActor(actor)

ren.SetBackground(colors.GetColor3d(‘Silver’))

Add renderer to renderwindow and render

renWin = vtkRenderWindow()

renWin.AddRenderer(ren)

renWin.SetSize(600, 600)

renWin.SetWindowName(‘Cutter’)

renWin.Render()

iren = vtkRenderWindowInteractor()

iren.SetRenderWindow(renWin)

camera = ren.GetActiveCamera()

camera.SetPosition(-37.2611, -86.2155, 44.841)

camera.SetFocalPoint(0.569422, -1.65124, -2.49482)

camera.SetViewUp(0.160129, 0.42663, 0.890138)

camera.SetDistance(104.033)

camera.SetClippingRange(55.2019, 165.753)

renWin.Render()

iren.Start()