Dear Andras,
Thank you very much for your help and the detailed answer, it’s the function I needed!
Still I found some interesting issues regarding which I would like to ask your opinion.
When I first used the shortcut-code, the position of the cursor was out of the volume:
My colleague - who is more expert in programming - found that there is a difference in the qform/sform space, which causes this alteration. I share here the links he sent me in this topic:
- Inconsistent qform / sform on image write · Issue #1318 · MRtrix3/mrtrix3 · GitHub
- Inconsistent qform /sform on nifti image - MRtrix3 Community
- Nifti file sform and Slicer image origin seem to disagree
Finally he found that if he runs this code below in FSL, then afterwards the shortcut works well on the new volume:
fslorient -copysform2qform sample_file.nii
.
A question: Is there a way that this modification (qform/sform reset) can be done in the Slicer (without having FSL and the required Linux environment)?
Also to share with the community - maybe some could have the same question - Adam made a little modification in the script you’ve sent (as for some reason an error message was received on its initial run), and now everything displayed correctly just as you have said:
def onMouseMoved(observer,eventid):
mniToWorldTransformNode = getNode('LinearTransform_3') # replace this by the name of your actual transform
worldToMniTransform = vtk.vtkGeneralTransform()
mniToWorldTransformNode.GetTransformToWorld(worldToMniTransform)
ras=[0,0,0]
mni=[0,0,0]
crosshairNode.GetCursorPositionRAS(ras)
worldToMniTransform.TransformPoint(ras, mni)
_ras = "; ".join([str(k) for k in ras])
_mni = "; ".join([str(k) for k in mni])
slicer.util.showStatusMessage(f"RAS={_ras} MNI={_mni}")
crosshairNode=slicer.util.getNode('Crosshair')
observationId = crosshairNode.AddObserver(slicer.vtkMRMLCrosshairNode.CursorPositionModifiedEvent, onMouseMoved)
I will try the transformations, and if any question rises, I’ll let you know.