# Scaling tube radius by distance to camera

**URL:** https://discourse.vtk.org/t/scaling-tube-radius-by-distance-to-camera/95
**Category:** Support
**Created:** [January 22, 2019, 7:20pm UTC](https://discourse.vtk.org/t/scaling-tube-radius-by-distance-to-camera/95 "2019-01-22T19:20:34Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![TravStu22](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/t/439d5e/32.png) [@TravStu22](https://discourse.vtk.org/u/TravStu22)
#### Post date: [January 22, 2019, 7:20pm UTC](https://discourse.vtk.org/t/scaling-tube-radius-by-distance-to-camera/95/1 "2019-01-22T19:20:34Z")

</div>

Hi,  
I would like to scale the radius of vtkTubeFilter in my vtkPolyDataMapper the same way I’m able to scale the radius of vtkSphereSource in my vtkGlyph3DMapper, with respect to vtkDistanceToCamera.

In the [TubesWithVaryingRadiusAndColors](https://vtk.org/Wiki/VTK/Examples/Cxx/VisualizationAlgorithms/TubesWithVaryingRadiusAndColors) example I see how a scalar array gets added to the polydata. But how can I do this with the ‘DistanceToCamera’ array generated by vtkDistanceToCamera since this connection occurs at the mapper level?

---

<div class="post-metadata">

### Author: ![banesullivan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/banesullivan/32/7143_2.png) [@banesullivan](https://discourse.vtk.org/u/banesullivan)
#### Post date: [February 27, 2019, 2:28am UTC](https://discourse.vtk.org/t/scaling-tube-radius-by-distance-to-camera/95/2 "2019-02-27T02:28:13Z")

</div>

This is really easy in python… particularly easy with [`vtki`](http://docs.vtki.org/en/latest/):

```python
import vtki
from vtki import examples
import vtk

# Create a line to use
alg = vtk.vtkLineSource()
alg.SetPoint1(0,0,0)
alg.SetPoint2(10,10,5)
alg.Update()
line = vtki.wrap(alg.GetOutput())

# Create a scene
p = vtki.Plotter()

# Add the line
p.add_mesh(line, line_width=10)

# Set the camera location
p.isometric_view()
p.camera_set = True

# Use the vtkDistanceToCamera filter
alg = vtk.vtkDistanceToCamera()
alg.SetRenderer(p.renderer)
alg.SetInputDataObject(line)
alg.Update()
# Make a tube with warped radius
updated = vtki.wrap(alg.GetOutput())
updated.set_active_scalar('DistanceToCamera')
tube = updated.tube(scalars='DistanceToCamera')

# Render the tube!
p.add_mesh(tube)

# display it all
p.show()

```

 ![download](https://discourse.vtk.org/uploads/default/original/1X/c878acd562b4a1ba4cf925b719cb59454eeefc2f.png)
