Apply transform to a given fiducial in Python script

Hi all,

I have a vtkMRMLMarkupsFiducialNode that contains multiple fiducials corresponding to distinct labels and I would like to apply a specific vtkMRMLTransform to each given fiducial depending on its label.
I have found how to apply a given transform to the vtkMRMLMarkupsFiducialNode using
FiducialsNode.SetAndObserveTransformNodeID(localTransformNode.GetID()) but I don’t know how to do it for each fiducial independently.

Can someone point me in the right direction? Thanks!

If you need to apply a different transform to each point then you need to iterate through the points, get the point position, compute transformed position, and set the modified value.

If you only have linear transforms then you can use GetMatrixTransformToWorld method to get the transformation matrix and use its MultiplyPoint method to get the transformed coordinates (input and output are homogeneous coordinates: [x, y, z, 1.0])

1 Like

Hi,

I’m re-opening the question. The solution works perfectly when I only have linear transforms, then, what can I do when vtkMRMLTransform is a composite of Bspline and linear transforms, since I cannot get the transformation matrix (GetMatrixTransformToWorld returns 0) ?
Thanks for your help!

For general (non-linear, potentially composite) transforms you can get it using slicer.vtkMRMLTransformNode.GetTransformBetweenNodes and use its TransformPoint method to transform point coordinates. See complete example in the script repository.