# How to join two or more fiducials by a line?

**URL:** https://discourse.slicer.org/t/how-to-join-two-or-more-fiducials-by-a-line/18443
**Category:** Support
**Created:** [June 30, 2021, 8:26pm UTC](https://discourse.slicer.org/t/how-to-join-two-or-more-fiducials-by-a-line/18443 "2021-06-30T20:26:26Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Rahulsabharwal](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rahulsabharwal/32/9035_2.png) [@Rahulsabharwal](https://discourse.slicer.org/u/Rahulsabharwal)
#### Post date: [June 30, 2021, 8:26pm UTC](https://discourse.slicer.org/t/how-to-join-two-or-more-fiducials-by-a-line/18443/1 "2021-06-30T20:26:27Z")

</div>

How can we pass a line through two mark up fiducials ?  
Or even three of them. Like making an axis to join them.

---

<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: [June 30, 2021, 9:31pm UTC](https://discourse.slicer.org/t/how-to-join-two-or-more-fiducials-by-a-line/18443/2 "2021-06-30T21:31:44Z")

</div>

If you have two points in a markups fiducial node ‘F’, you can create a new markups line node using the snippet:

```auto
F=getNode('F')
L=slicer.mrmlScene.AddNewNodeByClass('vtkMRMLMarkupsLineNode')
firstPoint = F.GetNthControlPointPositionVector(0)
L.AddControlPoint(firstPoint)
secondPoint = F.GetNthControlPointPositionVector(1)
L.AddControlPoint(secondPoint)

```

A line will only work with two points, if you have more than that you would need to use a markups curve node.

---

<div class="post-metadata">

### Author: ![esomjai](https://avatars.discourse-cdn.com/v4/letter/e/e274bd/32.png) [@esomjai](https://discourse.slicer.org/u/esomjai)
#### Post date: [May 4, 2023, 11:09am UTC](https://discourse.slicer.org/t/how-to-join-two-or-more-fiducials-by-a-line/18443/3 "2023-05-04T11:09:26Z")

</div>

> [@smrolfe](#):
>
> ```auto
> F=getNode('F')
> L=slicer.mrmlScene.AddNewNodeByClass('vtkMRMLMarkupsLineNode')
> firstPoint = F.GetNthControlPointPositionVector(0)
> L.AddControlPoint(firstPoint)
> secondPoint = F.GetNthControlPointPositionVector(1)
> L.AddControlPoint(secondPoint)
> 
> ```

Hi @smrolfe,

I was wondering how to modify the code snippet if my landmarks (control points) are in different markups fiducial nodes. How can I just specify the names of my control points that would be the endpoints of my linear distances?

---

<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: [May 4, 2023, 6:26pm UTC](https://discourse.slicer.org/t/how-to-join-two-or-more-fiducials-by-a-line/18443/4 "2023-05-04T18:26:48Z")

</div>

Do you know the index of the control point in each node? If so, you can use the same method but select the second control point from a different node.

If you need to do this by control point name, you can loop through the points in each node, use `c1.GetNthControlPointLabel()` to get the point name, and match to the name you are looking for.

---

<div class="post-metadata">

### Author: ![esomjai](https://avatars.discourse-cdn.com/v4/letter/e/e274bd/32.png) [@esomjai](https://discourse.slicer.org/u/esomjai)
#### Post date: [May 5, 2023, 11:06am UTC](https://discourse.slicer.org/t/how-to-join-two-or-more-fiducials-by-a-line/18443/6 "2023-05-05T11:06:33Z")

</div>

Thank you for the quick reply @smrolfe !  
I am quite unfamiliar with python scripting - can you point me to a guide on how to apply the c1.GetNthControlPointLabel() function?  
I tried replacing the initial code with your suggestion like this:  
`L=slicer.mrmlScene.AddNewNodeByClass('vtkMRMLMarkupsLineNode') firstPoint = c1.GetNthControlPointLabel('praR') L.AddControlPoint(firstPoint) secondPoint = c1.GetNthControlPointLabel('paR') L.AddControlPoint(secondPoint)`

However, I keep getting the error message: NameError: name ‘c1’ is not defined

My goal with this would be that the linear measurements are defined by their name and not the position and each time I can run the script after I placed the landmarks by hand e.g I have my endpoints as node names (e.g. prn-porion, se-sellion) and would like to compute the lines using the node names (e.g. prn-se).  
I would also like to name the newly generated line in the script (e.g. ear width R).

---

<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: [May 5, 2023, 5:01pm UTC](https://discourse.slicer.org/t/how-to-join-two-or-more-fiducials-by-a-line/18443/7 "2023-05-05T17:01:49Z")

</div>

If you are collecting landmark points, I strongly recommend that you use the same order every time, i.e. “prn-porion” has the same landmark number for each subject. If some subjects are missing points, these can be included with the position set to missing. Please see our tutorials on the [control point position status](https://github.com/SlicerMorph/Tutorials/tree/main/Markups_1#the-control-points-menu) and [landmark template creation](https://github.com/SlicerMorph/Tutorials/tree/main/Markups_3) for more information.

For two point lists, named “F” and “G”, the following snippet will create a line measurement between landmark 0 in each list and name the line “myMeasurement”. To run, replace “F” and “G” with your point list names and “0” with the point number of the landmark in each list.

```auto
F=getNode('F')
G=getNode('G')
L=slicer.mrmlScene.AddNewNodeByClass('vtkMRMLMarkupsLineNode')
firstPoint = F.GetNthControlPointPositionVector(0)
L.AddControlPoint(firstPoint)
secondPoint = G.GetNthControlPointPositionVector(0)
L.AddControlPoint(secondPoint)
L.SetName("myMeasurement")

```

---

<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: [May 5, 2023, 5:09pm UTC](https://discourse.slicer.org/t/how-to-join-two-or-more-fiducials-by-a-line/18443/8 "2023-05-05T17:09:21Z")

</div>

> [@esomjai](#):
>
> However, I keep getting the error message: NameError: name ‘c1’ is not defined

For the example above, replace `c1` with `F`. The function `GetNthControlPointLabel()` takes an integer point number and returns a string with the point name. So to check the name at point 0, you can use:

```auto
labelName = F.GetNthControlPointLabel(0)

```

---

<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: [May 6, 2023, 6:03pm UTC](https://discourse.slicer.org/t/how-to-join-two-or-more-fiducials-by-a-line/18443/9 "2023-05-06T18:03:43Z")

</div>

> [@smrolfe](#):
>
> If you are collecting landmark points, I strongly recommend that you use the same order every time, i.e. “prn-porion” has the same landmark number for each subject

You can also find a control point by label. I’ve just tried and bing chat provides a perfect answer:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/9/b9aae2ff4f37f82d4edcaed71a7a12f237f552de.jpeg)

I’ll add a `GetControlPointIndexByLabel()` method to markups node to be able to find a control point by a simple call.

---

<div class="post-metadata">

### Author: ![esomjai](https://avatars.discourse-cdn.com/v4/letter/e/e274bd/32.png) [@esomjai](https://discourse.slicer.org/u/esomjai)
#### Post date: [May 8, 2023, 10:00pm UTC](https://discourse.slicer.org/t/how-to-join-two-or-more-fiducials-by-a-line/18443/10 "2023-05-08T22:00:29Z")

</div>

Thank you @lassoan!  
I realise it is a quite simple question, thank you for taking the time to answer it. My Bing search was less successful (although having asked the same question) - would you mind providing me with the full code you got?

---

<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: [September 10, 2023, 12:40pm UTC](https://discourse.slicer.org/t/how-to-join-two-or-more-fiducials-by-a-line/18443/11 "2023-09-10T12:40:06Z")

</div>

A post was split to a new topic: [How to set colors of markups?](https://discourse.slicer.org/t/how-to-set-colors-of-markups/31636)
