Real-time distance measurement between the needle tip and target with PlusToolkit and 3D Slicer

Operating system:
Slicer version:
Expected behavior:
Actual behavior:

I’m a newbie in 3d Slicer and amazed its functionality. Great work!

I’m looking for the solution to dynamically measure the distance between the needle tip and the target by using the electromagnetic tracking device in 3d space. Within the PlusServer, I can track the needle in Slicer. Would be possible to make the measurement in real-time by using the PlusToolkit within the Slicer? If so, can you suggest, what should be done?
Thank you!

You can put two Markups Fiducials in the two coordinate systems (under the NeedleTipToReference and TargetToReference transforms), manually set their position to (0,0,0), then calculate their position when either of the parent transforms are modified (connect to the Modified event). Where would you like to display that distance? It sounds to me like you’d want a very simple module. A few lines of python code should do the trick. Unless there is already a module that can do it that I’m not aware of…

Thank you for the quick response! Actually I want to display the distance in 3d viewer. You’re right - i would like to use a very simple module. Could you suggest, what should be written in python?

Once you reached this state for markups and transforms (this shows the Data module)
(make sure the markups each have one fiducial at origin)
then you can get the distance between them like this:

import math
d=math.sqrt((f1p[0]-fp[0])**2 + (f1p[1]-fp[1])**2 + (f1p[2]-fp[2])**2)

This works if you paste it in the python interactor. However if you want to have a module, then you need to start from a module template, add data selectors, and use a considerably cleaned up version of this code (no herdcoded node names, proper variable names, error checks, etc.) in it.

1 Like

I think Breach Warning module in SlierIGT does exactly what you need: it shows distance of the needle tip from a selected model, in 3D view.


1 Like

Andras and Csaba, thank you for your help! Yes, these are exactly two things what i’m looking for: (1) the python solution and (2) the simple measurement visualization in 3d view.
Quick question: how to assign NeedleToRAS? This was somewhere in the tutorial. However, I can’t find it now.

NeedleToRAS is the transform that defines the needle tip position and orientation in the RAS (world) coordinate system. You can create a transform and just move it using sliders in Transforms module, or you can get the transform from a tracker through OpenIGTLink. The transform name in tutorials would be probably StylusTipTo… or NeedleTipTo… (Needle coordinate system is usually the coordinate system of the sensor that is attached to the needle, which is not exactly located at the needle tip).

Yes! I created a transform (NeedleToRAS) in Transforms module and it works just fine. Thank you very much for the tremendous help! It saved a lot of time.

1 Like

I’d like to calculate the distance between AC and PC on a AC-PC aligned T1. I only got as far as displaying the connecting line between AC and PC using the Markups to Model module. For the Breach Warning Module, I do not know what transform to use. Also, I’d like to use the Python Interactor to do a similar calculation. Thanks for your help.


You can very easily compute distance between two fiducial points in Python, but if you want to display distance between two points in the viewer, like a ruler, then it is probably better to use the annotation ruler. Click on the small down-arrow button next to the fiducial place icon on the toolbar and select placement of ruler, then click on the two points in the image.