# Is there a way to add a vector for the fiducials?

**URL:** <https://discourse.slicer.org/t/is-there-a-way-to-add-a-vector-for-the-fiducials/20574>\
**Category:** Development\
**Created:** [November 11, 2021, 3:17am UTC](https://discourse.slicer.org/t/is-there-a-way-to-add-a-vector-for-the-fiducials/20574 "2021-11-11T03:17:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [November 11, 2021, 3:17am UTC](https://discourse.slicer.org/t/is-there-a-way-to-add-a-vector-for-the-fiducials/20574/1 "2021-11-11T03:17:38Z")

</div>

Hi,  
Is there a way to add a vector for the fiducial.

Regards,  
Saima Safdar

---

<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:** [November 11, 2021, 4:28am UTC](https://discourse.slicer.org/t/is-there-a-way-to-add-a-vector-for-the-fiducials/20574/2 "2021-11-11T04:28:33Z")

</div>

Each fiducial point has a position and orientation. If the vector defines an orientation then that would be a convenient place to store it. If the vector stores an RGB value or any other signal or other property then you can add store it in the markups fiducials as a static measurement. This is used for example for storing curvatures in curves.

Example for storing a 4-component vector for each control point:

```python
pointListNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLMarkupsFiducialNode')

myVector = vtk.vtkDoubleArray()
myVector.SetName('SomeVector')
myVector.SetNumberOfComponents(4)

pointListNode.AddControlPointWorld(vtk.vtkVector3d(40, 50, -10.2))
myVector.InsertNextTuple4(1,1,4,2)

pointListNode.AddControlPointWorld(vtk.vtkVector3d(-20, -20, -10.2))
myVector.InsertNextTuple4(1,2,4,5)

pointListNode.AddControlPointWorld(vtk.vtkVector3d(-50, -60, -10.2))
myVector.InsertNextTuple4(3,3,4,1)

pointListNode.AddControlPointWorld(vtk.vtkVector3d(90, 40, -10.2))
myVector.InsertNextTuple4(4,4,4,7)

pointListNode.AddControlPointWorld(vtk.vtkVector3d(140, 70, -10.2))
myVector.InsertNextTuple4(5,5,4,3)

someMeasurement = slicer.vtkMRMLStaticMeasurement()
someMeasurement.SetName('SomeMeasurement')
someMeasurement.SetUnits('mm')
someMeasurement.SetPrintFormat('') # Prevent from showing up in SH Description
someMeasurement.SetControlPointValues(myVector)
pointListNode.AddMeasurement(someMeasurement)

```

The points can be accessed using VTK array interface as shown above but can also be accessed (read and written) as a numpy array:

```python
print(slicer.util.arrayFromMarkupsControlPointData(pointListNode, 'SomeVector'))

```

The data is stored in the .mrk.json file:

```auto
{
...
    "markups": [
        {
            "type": "Fiducial",
...
            "controlPoints": [
                {
                    "id": "1",
                    "label": "MarkupsFiducial-1",
                    "position": [-40.0, -50.0, -10.2],
                    "orientation": [-1.0, -0.0, 0.0, -0.0, -1.0, 0.0, -0.0, -0.0, 1.0],
...
                },
                {
                    "id": "2",
                    "label": "MarkupsFiducial-2",
                    "description": "",
                    "position": [20.0, 20.0, -10.2],
                    "orientation": [-1.0, -0.0, 0.0, -0.0, -1.0, 0.0, -0.0, -0.0, 1.0],
...
                },
...
            ],
            "measurements": [
                {
                    "name": "SomeMeasurement",
                    "enabled": true,
                    "units": "mm",
                    "controlPointValues": [[1.0, 1.0, 4.0, 2.0], [1.0, 2.0, 4.0, 5.0], [3.0, 3.0, 4.0, 1.0], [4.0, 4.0, 4.0, 7.0], [5.0, 5.0, 4.0, 3.0]
                    ]
                }
            ],
   ...
     }
    ]
}

```

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [November 11, 2021, 5:38am UTC](https://discourse.slicer.org/t/is-there-a-way-to-add-a-vector-for-the-fiducials/20574/3 "2021-11-11T05:38:50Z")

</div>

Hi Andras,  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/0/e01f36972dbbf567d0dbb95804a7b7c4f4e82dc3.png)

is there a way to change the orientation using user interaction with the fiducial instead of adding the values to the orientation array.

does the pointing of arrow fiducial changes with the change in the orientation matrix?

Thank you

Regards,  
Saima Safdar

---

<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:** [November 11, 2021, 5:50am UTC](https://discourse.slicer.org/t/is-there-a-way-to-add-a-vector-for-the-fiducials/20574/4 "2021-11-11T05:50:44Z")

</div>

In the future we’ll probably have an option to orient the markups control point glyphs using the point’s orientation, but there are no concrete plans. There are many alternative options, though.

Option A: You can get the point positions and orientations from the markups node and use those as inputs for a vtkgGlyph3D filter to generate a model of oriented glyphs.

Option B: Use [transform visualization features](https://slicer.readthedocs.io/en/latest/user_guide/modules/transforms.html#visualization-modes) (oriented glyphs in 2D and 3D, contours, deformed grids, etc.). You can choose to display the vector field at fiducial positions only. If the vectors are already defined with a dense displacement field (bspline or grid) then those can be loaded directly as a transform. If you have the vectors computed for each fiducial only, then you can generate the displacement field using Fiducial registration wizard module (in SlicerIGT extension).

There are many other options, but to be able to give an informed advice, we would need to know what your end goal is. What would you like to visualize for what purpose?
