For what you want, firstly you need to create a polyline according to csv data and then to apply the tube filter on it. The concrete steps of this are as follows:
When opening csv file, a table source is created.
Programmable Filter allows you to create a polyline from the above table. Here set the Script argument to in the Programmable Filter to:
table = self.GetTableInput()
output = self.GetPolyDataOutput()
num_points = table.GetNumberOfRows()
points = vtk.vtkPoints()
w = vtk.vtkDoubleArray()
w.SetName('w, um')
for row in range(num_points):
pnt = [0.0,0.0,table.GetValueByName(row, 'z, cm').ToDouble()]
points.InsertNextPoint(pnt)
w.InsertNextValue(table.GetValueByName(row, 'w, um').ToDouble())
lines = vtk.vtkPolyLine()
lines.GetPointIds().SetNumberOfIds(num_points)
for i in range(num_points):
lines.GetPointIds().SetId(i, i)
cells = vtk.vtkCellArray()
cells.InsertNextCell(lines)
output.SetPoints(points)
output.SetLines(cells)
output.GetPointData().AddArray(w)
Tube filter generates a cylinder with varying radius where you just have to select “Vary radius: By Absolute Scalar”.
Here are the state file and input csv data. varying_radius.zip (22.1 KB)
Would it be possible to achieve the same using scripting with paraview.simple?
I managed to create a PolyLineSource and apply a Tube filter. But how can I add a Scalar to PolyLineSource so the Tube filter can vary the radius with respect to the variable I want?
I had similar results when I used the tracing tool. Once the Tube filter is created there’s this line that assigns a list of strings to the Scalars attribute of the filter
tube.Scalars = [‘POINTS’, ‘w, um’]
So I though it was possible to do something simpler like:
from paraview.simple import *
#Create a PolyLine Source
pl = PolyLineSource(Points=xyz_numpy_array.flatten(), registrationName=‘a_polyline’)
#Add some scalar property to the PolyLineSource
???
#Create a Tube filter
tube = Tube(registrationName=‘Tube’, Input=pl)
#Vary the radius by the above defined scalar
tube.VaryRadius = ‘By Scalar’
As usual, the way to add a scalar array to a dataset would be to use the Calculator filter/Python calculator/Programmable filter etc. (Notice there would be limited ways to move data from the client side to the server side.) And they all can be embedded into a script with paraview.simple, as you can see when using the tracing tool or saving Python state file.