How to create a fiducial though the pixel not the mouse event

I went creat fiducial in the 3d view just give the x,y coordinate, and I found some information maybe help for me. But I don’t know how to use it.

virtual int vtkSlicerMarkupsWidget::AddNodeOnWidget ( const int *displayPos* [2] ) virtual

Given a specific X, Y pixel location, add a new node on the widget at this location.

This operation is called point picking. Model displayable manager has a point picker that you can use:

displayPosition = [100,120]

# Get model displayable manager
modelDisplayableManager = None
threeDViewWidget = slicer.app.layoutManager().threeDWidget(0)
managers = vtk.vtkCollection()
threeDViewWidget.getDisplayableManagers(managers)
for i in range(managers.GetNumberOfItems()):
  obj = managers.GetItemAsObject(i)
  if obj.IsA('vtkMRMLModelDisplayableManager'):
    modelDisplayableManager = obj
    break

# Use model displayable manager's point picker
pickedPosition = []
if modelDisplayableManager.Pick(displayPosition[0], displayPosition[1]):
    rasPositionArray = vtk.vtkDoubleArray()
    rasPositionArray.SetVoidArray(modelDisplayableManager.GetPickedRAS(),3,1)
    rasPosition = [rasPositionArray.GetValue(i) for i in range(3)]

print(rasPosition)
1 Like

In current Slicer version, the code snippet is much simpler - see in the script repository.