Skip to content

Instantly share code, notes, and snippets.

@ottadini
Created April 30, 2015 11:33
Show Gist options
  • Save ottadini/d62736fd8e35132c87f7 to your computer and use it in GitHub Desktop.
Save ottadini/d62736fd8e35132c87f7 to your computer and use it in GitHub Desktop.
Paraview Programmable Filter example
# Get a vtk.PolyData object for the input
pdi = self.GetPolyDataInput()
# Get a vtk.PolyData object for the output
pdo = self.GetPolyDataOutput()
numPoints = pdi.GetNumberOfPoints()
# Points for the line:
newPoints = vtk.vtkPoints()
for i in range(0, numPoints):
# Generate the new points from the input
coord = pdi.GetPoint(i)
x, y, z = coord[:3]
newPoints.InsertPoint(i, x, y, z)
# Add the new points to the PolyData object:
pdo.SetPoints(newPoints)
# Make a line from the new points:
aPolyLine = vtk.vtkPolyLine()
#Indicate the number of points along the line
aPolyLine.GetPointIds().SetNumberOfIds(numPoints)
for i in range(0,numPoints):
#Add the points to the line. The first value indicates
#the order of the point on the line. The second value
#is a reference to a point in a vtkPoints object. Depends
#on the order that Points were added to vtkPoints object.
#Note that this will not be associated with actual points
#until it is added to a vtkPolyData object which holds a
#vtkPoints object.
aPolyLine.GetPointIds().SetId(i, i)
#Allocate the number of 'cells' that will be added. We are just
#adding one vtkPolyLine 'cell' to the vtkPolyData object.
pdo.Allocate(1, 1)
#Add the poly line 'cell' to the vtkPolyData object.
pdo.InsertNextCell(aPolyLine.GetCellType(), aPolyLine.GetPointIds())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment