# Plotting 2D line segments

**URL:** <https://discourse.slicer.org/t/plotting-2d-line-segments/5663>\
**Category:** Development\
**Tags:** plots\
**Created:** [February 6, 2019, 8:10pm UTC](https://discourse.slicer.org/t/plotting-2d-line-segments/5663 "2019-02-06T20:10:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![smrolfe](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/smrolfe/32/3659_2.png) [@smrolfe](https://discourse.slicer.org/u/smrolfe)\
**Post date:** [February 6, 2019, 8:10pm UTC](https://discourse.slicer.org/t/plotting-2d-line-segments/5663/1 "2019-02-06T20:10:47Z")

</div>

Hello,  
We need to plot a series of line segments in 2D. The number of line segments is variable and can be large, so using a node to represent each line segment is not practical. This is not currently supported in Slicer or VTK plots. There are standard functions available in R and MATLAB to create line segment plots from pairs of endpoints that could be used as a model for this function.

We’ve started a [lab page](https://www.slicer.org/wiki/Documentation/Labs/Plotting2DLineSegments) for this topic and have included an example using the R function segments. We’d appreciate feedback and ideas.

Thanks!

---

<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:** [February 6, 2019, 8:52pm UTC](https://discourse.slicer.org/t/plotting-2d-line-segments/5663/2 "2019-02-06T20:52:39Z")

</div>

We already have such plots! It may be not obvious, but 3D view is actually a very sophisticated 3D plot. We can plot displacements defined by transforms. You can choose to show displacement only at markup positions:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/e/be84d6f320f74595ccbdfea36cbac47347bc2e59.png)

We just need a bit fancier axis actors. The current axis actor is always just a centered horizontal line, but there are several 2D and 3D box axes to choose from in VTK.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/1/01db2e86cafb27faab794c91e4d66f5ab0d3b1ee.png)

The same view looks like a plot if you change the background to white and show a nicer axis actor, see for example in ParaView:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/c/6c3fcf7cca91ed1a60048cd3f1f3ae4e6a6fc84f.png)

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [February 6, 2019, 9:31pm UTC](https://discourse.slicer.org/t/plotting-2d-line-segments/5663/3 "2019-02-06T21:31:52Z")

</div>

Hi Andras,  
Yes, we do use the 3D. But for various reasons, we need to be able to their 2D plane projections using the Plot infrastructure. That’s where got stuck.

---

<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:** [February 6, 2019, 9:45pm UTC](https://discourse.slicer.org/t/plotting-2d-line-segments/5663/4 "2019-02-06T21:45:51Z")

</div>

Transform displacement in 2D views is already projected to 2D. See slice views in the first screenshot above.

---

<div class="post-metadata">

**Author:** ![smrolfe](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/smrolfe/32/3659_2.png) [@smrolfe](https://discourse.slicer.org/u/smrolfe)\
**Post date:** [February 6, 2019, 11:08pm UTC](https://discourse.slicer.org/t/plotting-2d-line-segments/5663/5 "2019-02-06T23:08:45Z")

</div>

Thanks @lassoan, this approach should work for us!

I have one more question on setting up the view. I need to get the 3D vectors projected onto a single plane, which it looks like you’ve done in the red slice view. My slice view looks like a cross section. Can you tell me if there is an option to set this? I recall seeing a projection setting in the models module, but don’t see something similar in the transform module.  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/9/6937b91c688e67fa98cb59eff25f09e0c3a9ed57.png)

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [February 7, 2019, 5:45pm UTC](https://discourse.slicer.org/t/plotting-2d-line-segments/5663/6 "2019-02-07T17:45:16Z")

</div>

I did a fiducial registration of these two sets. When I visualize it, either I get this if I choose the entire region  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/7/7/77605a017a9f4795cee80eb73c52ad58698f2410.png)

or this if I choose the moving set under transform visualization options

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/a/5/a5246d3dda79529f83e36103c8487673e2ee5fd6.png)

---

<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:** [February 7, 2019, 7:06pm UTC](https://discourse.slicer.org/t/plotting-2d-line-segments/5663/7 "2019-02-07T19:06:47Z")

</div>

If you use a thin-plate spline transform then you should see the arrows connecting each pair of corresponding fiducials.

Note Fiducial registration wizard determines “Transform _from_ parent” transform from the landmarks and “Transform to parent” transform is computed on-the-fly. If the displacement field is irregular then the inverse may not be accurate and you may get something like the image above. To make sure the arrows show the exact displacements defined by the fiducial point pairs, go to Transforms module, flip To/From fiducial list and click “Invert” after computing the transformation in Fiducial registration wizard (then “Transform _to_ parent” displacement is visualized, which does not require inversion).

Regular field, transform to parent (accurate):

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/4/84f0f498d13c2545308c9428985987e859a052c1.png)

Irregular field, transform to parent (some inaccuracies):

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/5/4548118ed9911f4a3bd21191ef62af5b0053572b.png)

Irregular field, transform from parent (accurate):

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/c/7/c72dbf8397312e123faa2c351a52895f2157aeba.png)
