cylinder with varying radius


I have a distribution of channel width along its axis (in a csv-file), smth like this:

"z, cm","w, um"

I’d like to visualize it using cylinder with varying radius according to the width distribution. Is is possible? If yes how can I do this?

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:

  1. When opening csv file, a table source is created.
  2. 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()]
    w.InsertNextValue(table.GetValueByName(row, 'w, um').ToDouble())

lines = vtk.vtkPolyLine()
for i in range(num_points):
    lines.GetPointIds().SetId(i, i)

cells = vtk.vtkCellArray()

  1. 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. (22.1 KB)

Works like a charm! Thanks!

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?


It may be possible in the sense that the programable filter can be embedded in scripting with paraview.simple.

You can confirm that by doing the following:

  1. Load a state file contained in “” in my earlier post.
  2. Save State as a Python state file. (File > Save State… and choose Python state file (*.py) on the “Files of type” list)

However, I don’t know any other way.

Thanks for your reply,

I did the test you mention.

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.