# Implement variable radius curve

**URL:** https://discourse.slicer.org/t/implement-variable-radius-curve/21334
**Category:** Development
**Created:** [January 5, 2022, 12:43am UTC](https://discourse.slicer.org/t/implement-variable-radius-curve/21334 "2022-01-05T00:43:48Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)
#### Post date: [January 5, 2022, 12:43am UTC](https://discourse.slicer.org/t/implement-variable-radius-curve/21334/1 "2022-01-05T00:43:48Z")

</div>

Hi,

In SlicerCAT I’m implementing a module to work with curves and scalar values that may be displayed as a radius of the curve or as its color. Thus I need `vtkTubeFilter`.  
There should be an opportunity to interactively change coefficient that multiplies scalar values and thus changing variant radius (for example by QSliderWidget).

I find `vtkMRMLMarkupsCurveNode` is pretty attractive but I don’t understand how interactively manage such parameters like variant radius i.e. what to connect `QSliderWidget` to? I suspect I need to have access to the `vtkTubeFilter` instance wich is stored in `vtkSlicerCurveRepresentation`. Is it controlled by `vtkMRMLMarkupsDisplayNode`?

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [January 5, 2022, 6:00am UTC](https://discourse.slicer.org/t/implement-variable-radius-curve/21334/2 "2022-01-05T06:00:42Z")

</div>

Currently point scalars (radius, curvature, etc.) can only be used for coloring of the tube, but not for adjusting the tube radius. We anticipated that this will emerge as a need, so we designed markup curves so that with a few little changes this sizing mode can be added:

- In vtkMRMLMarkupsDisplayNode: add a new `UseActiveScalar` to CurveLineSizeMode
- In vtkSlicerCurveRepresentation2D and vtkSlicerCurveRepresentation3D if you find that `CurveLineSizeMode` == `UseActiveScalar` set the `TubeFilter` to use the active scalar (see [example](https://github.com/Kitware/VTK/blob/b9f028db9f801258d4c1c0c97716ea7a3c14c289/Filters/Core/Testing/Cxx/TestVaryRadiusTubeFilter.cxx#L68-L73))
- Expose the new feature on the GUI: probably changing the “Line thickness” `absolute` toggle button to a combobox (with the options: absolute, relative, active scalar) would be sufficient.

---

<div class="post-metadata">

### Author: ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)
#### Post date: [January 5, 2022, 8:08pm UTC](https://discourse.slicer.org/t/implement-variable-radius-curve/21334/3 "2022-01-05T20:08:42Z")

</div>

Thank you, I did as you said and I just got first results, seems pretty good. May I implement this in PR?

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/7/67b9fc06b83641494a3039ca741742f8697affa5.jpeg)

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [January 5, 2022, 8:29pm UTC](https://discourse.slicer.org/t/implement-variable-radius-curve/21334/4 "2022-01-05T20:29:43Z")

</div>

This looks very promising! Yes, please submit a pull request with the proposed changes.

---

<div class="post-metadata">

### Author: ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)
#### Post date: [January 6, 2022, 6:01pm UTC](https://discourse.slicer.org/t/implement-variable-radius-curve/21334/5 "2022-01-06T18:01:25Z")

</div>

The PR is [here](https://github.com/Slicer/Slicer/pull/6104).

As `vtkTubeFilter` 's variant radius is controlled not only by scalars but also by `SetRadius(double)` and `SetFactorRadius(double)` I decided not to edit `CurveLineSizeMode`so the user can control both these parameters in `VariableRadius` mode.

Also in my case I expect that scalar values will have both negative and positive values. Using such scalars as radius lead to some unwanted results.  
So I would like to have a possibility to translate all scalars to positive range by adding scalar value that is equal to something like `abs(min(scalars))`.

If someone has ideas how to do that I could probably try to implement that.

---

<div class="post-metadata">

### Author: ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)
#### Post date: [January 22, 2022, 7:19pm UTC](https://discourse.slicer.org/t/implement-variable-radius-curve/21334/6 "2022-01-22T19:19:19Z")

</div>

Hi,

How do you think how to fix the [issue with incorrect diameter and color in slice view](https://github.com/Slicer/Slicer/pull/6104)? I think I should look in `vtkSlicerCurveRepresentation2D` implementation but can’t find anything appropriate.
