# cylinder with varying radius

**URL:** https://discourse.paraview.org/t/cylinder-with-varying-radius/1212
**Category:** ParaView Support
**Created:** [January 31, 2019, 10:52am UTC](https://discourse.paraview.org/t/cylinder-with-varying-radius/1212 "2019-01-31T10:52:25Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![gbug](https://discourse.paraview.org/user_avatar/discourse.paraview.org/gbug/32/2220_2.png) [@gbug](https://discourse.paraview.org/u/gbug)
#### Post date: [January 31, 2019, 10:52am UTC](https://discourse.paraview.org/t/cylinder-with-varying-radius/1212/1 "2019-01-31T10:52:25Z")

</div>

Hi!

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

```auto
"z, cm","w, um"
0.00000000e+00,7.92667177e+01
1.00000000e-01,7.92601798e+01
2.00000000e-01,7.92410225e+01
3.00000000e-01,7.92099535e+01
...

```

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?

---

<div class="post-metadata">

### Author: ![Kenichiro-Yoshimi](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@Kenichiro-Yoshimi](https://discourse.paraview.org/u/Kenichiro-Yoshimi)
#### Post date: [February 1, 2019, 3:21am UTC](https://discourse.paraview.org/t/cylinder-with-varying-radius/1212/2 "2019-02-01T03:21:02Z")

</div>

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:

```python
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)

```

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.  
[varying\_radius.zip](https://discourse.paraview.org/uploads/default/original/2X/f/f70c5a9bdfa596ad420f373236a4ae1232591bde.zip) (22.1 KB)

---

<div class="post-metadata">

### Author: ![gbug](https://discourse.paraview.org/user_avatar/discourse.paraview.org/gbug/32/2220_2.png) [@gbug](https://discourse.paraview.org/u/gbug)
#### Post date: [February 1, 2019, 7:14am UTC](https://discourse.paraview.org/t/cylinder-with-varying-radius/1212/3 "2019-02-01T07:14:11Z")

</div>

Works like a charm! Thanks!

---

<div class="post-metadata">

### Author: ![R\_C](https://discourse.paraview.org/user_avatar/discourse.paraview.org/r_c/32/5998_2.png) [@R\_C](https://discourse.paraview.org/u/R_C)
#### Post date: [February 28, 2021, 4:07pm UTC](https://discourse.paraview.org/t/cylinder-with-varying-radius/1212/4 "2021-02-28T16:07:45Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Kenichiro-Yoshimi](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@Kenichiro-Yoshimi](https://discourse.paraview.org/u/Kenichiro-Yoshimi)
#### Post date: [March 1, 2021, 8:17am UTC](https://discourse.paraview.org/t/cylinder-with-varying-radius/1212/5 "2021-03-01T08:17:04Z")

</div>

Hello,

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 “varying\_radius.zip” 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.

---

<div class="post-metadata">

### Author: ![R\_C](https://discourse.paraview.org/user_avatar/discourse.paraview.org/r_c/32/5998_2.png) [@R\_C](https://discourse.paraview.org/u/R_C)
#### Post date: [March 1, 2021, 12:26pm UTC](https://discourse.paraview.org/t/cylinder-with-varying-radius/1212/6 "2021-03-01T12:26:28Z")

</div>

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’

---

<div class="post-metadata">

### Author: ![Kenichiro-Yoshimi](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@Kenichiro-Yoshimi](https://discourse.paraview.org/u/Kenichiro-Yoshimi)
#### Post date: [March 1, 2021, 2:27pm UTC](https://discourse.paraview.org/t/cylinder-with-varying-radius/1212/7 "2021-03-01T14:27:48Z")

</div>

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.
