[vtkusers] Issue getting vtkIntersectionPolyDataFilter working using Python
Eric Petersen
peer9802 at gmail.com
Wed Feb 15 15:30:23 EST 2017
Hello,
I'm new to VTK and am trying to find the intersection of a plane and tube,
using Python 3.5 and VTK 7.1, by following the "IntersectionPolyDataFilter"
example. My goal for this exercise is to obtain where the tube centerline
intersects the plane though ultimately would like to determine where the
tube intersects with an imported STL file (or where multiple STL files
intersect).
My Python code is located below. I don't get any errors when I run the
script; however, the filter does not report any intersecting points or
lines. I also don't see an intersection line in the rendering window (just
the plane and tube/cylinder). I'm likely missing something obvious here.
Can anyone help me out?
import vtk
from vtk.util.colors import *
#create a plane source
planeSource = vtk.vtkPlaneSource()
planeSource.SetOrigin((-1,-1,-1))
planeSource.SetPoint1((1,-1,-1))
planeSource.SetPoint2((-1,1,-1))
planeSource.Update()
polygonMapper = vtk.vtkPolyDataMapper()
polygonMapper.SetInputConnection(planeSource.GetOutputPort())
polygonMapper.Update()
actor = vtk.vtkActor()
actor.SetMapper(polygonMapper)
actor.GetProperty().SetColor(white)
actor.GetProperty().SetOpacity(.5)
#create a tube using two points. Simplified example of what trying to do.
centerlinePoints = []
centerlinePoints.append((0,0,-5))
centerlinePoints.append((0,0,5))
points = vtk.vtkPoints()
for i in range(0,len(centerlinePoints)):
p = centerlinePoints[i]
points.InsertPoint(i, p[0], p[1], p[2])
spline = vtk.vtkParametricSpline()
spline.SetPoints(points)
functionSource = vtk.vtkParametricFunctionSource()
functionSource.SetParametricFunction(spline)
functionSource.SetUResolution(20)
functionSource.Update()
#tubePolyData = functionSource.GetOutput()
# Create the tubes
tuber = vtk.vtkTubeFilter()
tuber.SetInputConnection(functionSource.GetOutputPort())
tuber.SetNumberOfSides(20)
tuber.SetVaryRadiusToVaryRadiusOff()
tuber.SetRadius(.5)
tuber.CappingOn()
tuber.Update()
tubeMapper = vtk.vtkPolyDataMapper()
tubeMapper.SetInputConnection(tuber.GetOutputPort())
tubeMapper.Update()
tubeActor = vtk.vtkActor()
tubeActor.SetMapper(tubeMapper)
tubeActor.GetProperty().SetColor(blue)
tubeActor.GetProperty().SetOpacity(.5)
isect = vtk.vtkIntersectionPolyDataFilter()
isect.ComputeIntersectionPointArrayOn()
isect.SetInputConnection(0,tuber.GetOutputPort())
isect.SetInputConnection(1,planeSource.GetOutputPort())
isect.Update()
print(isect.GetNumberOfIntersectionPoints())
print(isect.GetNumberOfIntersectionLines())
intersectMapper = vtk.vtkPolyDataMapper()
intersectMapper.SetInputConnection(isect.GetOutputPort())
intersectMapper.ScalarVisibilityOn()
intersectActor = vtk.vtkActor()
intersectActor.GetProperty().SetColor(red)
intersectActor.GetProperty().SetOpacity(1)
intersectActor.SetMapper(intersectMapper)
renderer = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(renderer)
#renderer.AddActor(tubeActor)
#renderer.AddActor(actor)
#renderer.AddActor(intersectActor)
renderer.AddViewProp(tubeActor)
renderer.AddViewProp(actor)
renderer.AddViewProp(intersectActor)
# Create a renderwindowinteractor
iren = vtk.vtkRenderWindowInteractor()
iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
iren.SetRenderWindow(renWin)
# Enable user interface interactor
iren.Initialize()
renWin.Render()
iren.Start()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170215/3a36bdde/attachment.html>
More information about the vtkusers
mailing list