Extract RAS coordinates by clicking

Hi to everyone :slight_smile:
Today I want to extract RAS coordinates to 3d markups/curves to click.

My goal is interact with 3d view (if is not possible, interact with 2d views would great too). Processing the click I would like to know the ID of the selected point and RAS coordinates.


Is there a way to do it by python code → Run some lines which allows the user to select one point and then he can retrieve the coordinates?

I’m interested in obtain info from centerlines created by extractCenterlines module

Also interested in having a callback function when clicking on a markups. Any solution for this?

Thanks

1 Like

This worked for me for adding new points:

@vtk.calldata_type(vtk.VTK_INT)
def onPointDefined(caller, eventid, callData):
    fiducialNode = caller
    fiducialIndex = callData
    print(f'Defined: {fiducialNode.GetName()}, Fiducial index: {fiducialIndex}')

fiducialsNode.AddObserver(slicer.vtkMRMLMarkupsNode.PointPositionDefinedEvent, onPointDefined)

For clicking this could be the solution:

@vtk.calldata_type(vtk.VTK_OBJECT)
def onPointClicked(caller, eventid):
    fiducialNode = caller
    fiducialIndex = int(fiducialNode.GetAttribute('Markups.MovingMarkupIndex'))
    print(f'Moved: {fiducialNode.GetName()}, Fiducial index: {fiducialIndex}')

fiducialsNode.AddObserver(slicer.vtkMRMLMarkupsNode.PointStartInteractionEvent, onPointClicked)
1 Like