# How to show a polyline with arbitrary width and nice joins between the nodes?

**URL:** https://discourse.vtk.org/t/how-to-show-a-polyline-with-arbitrary-width-and-nice-joins-between-the-nodes/3316
**Category:** Support
**Created:** [May 15, 2020, 2:36pm UTC](https://discourse.vtk.org/t/how-to-show-a-polyline-with-arbitrary-width-and-nice-joins-between-the-nodes/3316 "2020-05-15T14:36:26Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![normanius](https://discourse.vtk.org/user_avatar/discourse.vtk.org/normanius/32/611_2.png) [@normanius](https://discourse.vtk.org/u/normanius)
#### Post date: [May 15, 2020, 2:36pm UTC](https://discourse.vtk.org/t/how-to-show-a-polyline-with-arbitrary-width-and-nice-joins-between-the-nodes/3316/1 "2020-05-15T14:36:26Z")

</div>

Hi

Have a look at the sample below. I’ve got a polyline and want to show that line with an arbitrary width.

 ![image](https://discourse.vtk.org/uploads/default/original/2X/a/a3f893e40cf38237abc704f38eb3ceb506465f8d.png)

In the sample, I essentially follow [this](https://lorensen.github.io/VTKExamples/site/Cxx/Visualization/LineWidth/) example to achieve this, for a polyline that I extracted with [vtkFeatureEdges](https://lorensen.github.io/VTKExamples/site/Cxx/Meshes/BoundaryEdges/). It appears that the line is drawn using quads per line-segment, however the result doesn’t look satisfactory.

Is it possible to create a polyline with nice joins? I found the [ribbon filter](https://lorensen.github.io/VTKExamples/site/Java/PolyData/RibbonFilter/), but it requires me to set a normal. Instead, I would rather like to see a tube that goes along that line.

I could possibly use [vmtkcenterlinemodeller](http://www.vmtk.org/vmtkscripts/vmtkcenterlinemodeller.html), but wondered if there is a pure VTK option. I need this just for visualization.

Thanks

* * *

**Update** : I found [vtkTubeFilter](https://vtk.org/doc/nightly/html/classvtkTubeFilter.html#details) that does the job much better. But still, it lacks the possibility to create nice joins.

```python
def polylineToTube(edges, radius, resolution=10):
    tube = vtk.vtkTubeFilter()
    tube.SetInputData(edges)
    tube.SetRadius(radius)
    tube.SetNumberOfSides(resolution)
    tube.SidesShareVerticesOff()
    tube.Update()
    return tube

```

 ![image](https://discourse.vtk.org/uploads/default/original/2X/7/7b3e2fcec7fd8511fe5ba1a7ce0911139c8656ce.png)

 ![image](https://discourse.vtk.org/uploads/default/original/2X/6/656102f199033fef7c1861e3675b02dbb4b2bb84.png)

* * *

**Update 2** : If really desperate, one could use implicit functions to compute the tube. It’s super slow, but it works 🙂

```python
def polylineToTube(edges, radius, resolution=10, sampling=400):
    modeller = vtk.vtkImplicitModeller()
    modeller.SetSampleDimensions(sampling, sampling, sampling)
    modeller.SetInputData(edges)
    contours = vtk.vtkContourFilter()
    contours.SetInputConnection(modeller.GetOutputPort())
    contours.SetValue(0, radius) # generate iso-surface at radius
    contours.Update()
    return contours

```

 ![image](https://discourse.vtk.org/uploads/default/original/2X/f/fd7355cf41a9062018f5d440358ee30a6fdb2a75.png)

---

<div class="post-metadata">

### Author: ![normanius](https://discourse.vtk.org/user_avatar/discourse.vtk.org/normanius/32/611_2.png) [@normanius](https://discourse.vtk.org/u/normanius)
#### Post date: [May 15, 2020, 5:19pm UTC](https://discourse.vtk.org/t/how-to-show-a-polyline-with-arbitrary-width-and-nice-joins-between-the-nodes/3316/2 "2020-05-15T17:19:47Z")

</div>

Okay. I finally figured out what was wrong. 🤦‍♂️

`vtkTubeFilter` is perfectly able to join the segments. But the issue was with `vtkFeatureEdges`, which was returning a multi-line (that is a `vtkPolyData` containing multiple line-segments, instead of one single polyline. Flattening this polyline fixed the problem for me.

This is how I did it:

```python
    edges = vtk.vtkFeatureEdges()
    edges.SetInputData(source)
    edges.BoundaryEdgesOn()
    edges.ManifoldEdgesOff()
    edges.NonManifoldEdgesOff()
    edges.FeatureEdgesOff()
    edges.Update()

    stripped = vtk.vtkStripper()
    stripped.SetInputData(edges.GetOutput())
    stripped.Update()

    tube = vtk.vtkTubeFilter()
    tube.SetInputData(stripped.GetOutput())
    tube.SetRadius(radius)
    tube.SetNumberOfSides(resolution)
    tube.Update()

```

 ![image](https://discourse.vtk.org/uploads/default/original/2X/f/fef5919e364c46a634e610d5a1e744c668a485ac.png)

---

<div class="post-metadata">

### Author: ![\_11](https://discourse.vtk.org/user_avatar/discourse.vtk.org/_11/32/4710_2.png) [@\_11](https://discourse.vtk.org/u/_11)
#### Post date: [February 17, 2022, 1:30pm UTC](https://discourse.vtk.org/t/how-to-show-a-polyline-with-arbitrary-width-and-nice-joins-between-the-nodes/3316/3 "2022-02-17T13:30:34Z")

</div>

> [@normanius](#):
>
> `polylineToTube`

Hi, what is the input of edge? Could you repost the link for the example because the original one is down.

Thanks!

---

<div class="post-metadata">

### Author: ![normanius](https://discourse.vtk.org/user_avatar/discourse.vtk.org/normanius/32/611_2.png) [@normanius](https://discourse.vtk.org/u/normanius)
#### Post date: [March 3, 2022, 11:28am UTC](https://discourse.vtk.org/t/how-to-show-a-polyline-with-arbitrary-width-and-nice-joins-between-the-nodes/3316/4 "2022-03-03T11:28:52Z")

</div>

What do you mean by “What is the input of edge”?

The LineWidth example is now [here](https://kitware.github.io/vtk-examples/site/Cxx/Visualization/LineWidth/).

---

<div class="post-metadata">

### Author: ![\_11](https://discourse.vtk.org/user_avatar/discourse.vtk.org/_11/32/4710_2.png) [@\_11](https://discourse.vtk.org/u/_11)
#### Post date: [March 3, 2022, 12:00pm UTC](https://discourse.vtk.org/t/how-to-show-a-polyline-with-arbitrary-width-and-nice-joins-between-the-nodes/3316/5 "2022-03-03T12:00:14Z")

</div>

Hi, thanks a lot for your reply! I mean the input parameter for the function `polylineToTube ` . Is radius just a list of float number? But what is the `edges` ?

---

<div class="post-metadata">

### Author: ![normanius](https://discourse.vtk.org/user_avatar/discourse.vtk.org/normanius/32/611_2.png) [@normanius](https://discourse.vtk.org/u/normanius)
#### Post date: [March 3, 2022, 12:07pm UTC](https://discourse.vtk.org/t/how-to-show-a-polyline-with-arbitrary-width-and-nice-joins-between-the-nodes/3316/6 "2022-03-03T12:07:38Z")

</div>

Hi Padix

`edges` is a vtkPolyData object representing a line. As I wrote in the OP, I extracted `edges` with `vtkFeatureEdges`. See here for an [example](https://kitware.github.io/vtk-examples/site/Python/Meshes/BoundaryEdges/).

Yes, radius is a float representing the radius of the line to “draw”.

HTH
