Quiet late for @NorthySP, I'm afraid, but may be useful for someone who want to build line (vtkPolyline
) from points in ParaView now:
- Open data file with points coordinates (txt, csv and other formats ParaView can read and parse).
- Apply
Programmable Filter
on loaded table.
- In
Programmable Filter
settings in Script
field input
# the single input table this filter is applied to
table = inputs[0]
# print table properties and metrics just for sure
print("table: ", table)
print("table.GetNumberOfRows() = ", table.GetNumberOfRows())
num_rows = table.GetNumberOfRows()
# usual vtk workflow: fill vtkPoints first
vtkpoints = vtk.vtkPoints()
for i in range(0, num_rows):
vtkpoints.InsertPoint(i,
table.GetValue(i,0).ToFloat(), #x column
table.GetValue(i,1).ToFloat(), #y column
table.GetValue(i,2).ToFloat() #z column
)
output.SetPoints(vtkpoints)
# allocate vtkCell, representing single line
# if more lines, use output.Allocate(N_OF_LINES, 1)
output.Allocate(1, 1)
vtkpolyline = vtk.vtkPolyLine()
vtkpolyline.GetPointIds().SetNumberOfIds(num_rows)
# enumerate points to include in polyline
for i in range(0,num_rows):
vtkpolyline.GetPointIds().SetId(i, i)
# assign vtkPolyLine graphical object to created vtkCell
output.InsertNextCell(vtkpolyline.GetCellType(),
vtkpolyline.GetPointIds())
Alternatively you can use Programmable Source
only instead of Table
-Programmable Filter
chain: create Programmable Source
item, open data file in it's python code, get XYZ from there, and the rest workflow (vtkPoints
→ vtkPolyline
→ vtkCell
) is just the same as in filter in my example above.
Also my repository with examples of use Programmable Source
and Programmable Filter
for lines https://github.com/Ornstein89/paraview_orbit.
