Select vtkMRMLModelNode on mouse click

Hello,

I am trying to implement a mouse interaction wherein the user clicks on a model from the 3D viewer and the model which was clicked is made available so that it can be modified in some way (such as colour change, etc.). I was able to find a similar example here from the VTK examples page but have not been able to reproduce the behaviour with vtkMRMLModelNodes within Slicer.

Any help is appreciated.

1 Like

We plan to add a feature like this within a couple of months, but until then you can use something like what is implemented here.

1 Like

Hi Andras,
Is the modelnode selection function available.

I have a model and selected nodes with using fiducials. Is there a way to left mouse click the fiducial and save that fiducial coordinates. For example if the user has model and selected nodes but the user needs the location of only few control points. is it possible to get the location by only left mouse click on the fiducial.

This example could be a starting point:
https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#get-a-notification-if-a-markup-control-point-position-is-modified

I’d probably try to use the PointEndInteractionEvent event to get notified about the click, and by getting the active control point index you know which one was clicked.

Hi,
I am having trouble with connecting mouse click.

How can I attach the mouse click event with this method or may be I am understanding it wrong.

in main process code I have
markupsNode = slicer.util.getNode(inputFiducial.GetID())
print(markupsNode)
markupsNode.AddObserver(slicer.vtkMRMLMarkupsNode.PointEndInteractionEvent, self.onMarkupEndInteraction)

and the method

def onMarkupEndInteraction(self, caller, event):
markupsNode = caller
sliceView = markupsNode.GetAttribute(“Markups.MovingInSliceView”)
movingMarkupIndex = markupsNode.GetDisplayNode().GetActiveControlPoint()
logging.info(“End interaction: point ID = {0}, slice view = {1}”.format(movingMarkupIndex, sliceView))

regards,
saima

You didn’t say anything about what the problem was, but from the code you pasted (which is identical to what we can see in the script repository) the problem I see is that you added an argument self to the onMarkupEndInteraction function, which won’t work outside of a class. Of course I can make assumptions all day but it would be easier if you told us what is the problem. Thanks.

Hi Pinter,
I have the markup control points already defined for the model nodes. I want a program where user can click on the markup point and can get the node number along with the x,y,z coordinates.

regards,
Saima

Hi,
I got the control point I am clicking but why it is printing it multiple times. here are the lines of code.

In the main def process:
markupsNode = slicer.util.getNode(inputFiducial.GetID())
markupsNode.AddObserver(slicer.vtkMRMLMarkupsNode.PointEndInteractionEvent, self.onMarkupEndInteraction)

in the method within the class, def
def onMarkupEndInteraction(self, caller, event):
#print(“inside”)
markupsNode = caller
sliceView = markupsNode.GetAttribute(“Markups.MovingInSliceView”)
movingMarkupIndex = markupsNode.GetDisplayNode().GetActiveControlPoint()
print(movingMarkupIndex)

the output is like below in the console.

Reloading module: SurfaceModelNodesSelector


inside

inside

inside

inside

inside

inside

2667

[-83.58309173583984, -56.84154510498047, 108.15825653076172]

2667

2667

2667

2667

2667

2667

Hi,
I am getting the index and the control point position with the following lines.

def onMarkupEndInteraction(self, caller, event):
markupsNode = caller
markupsNodeindex = int(caller.GetAttribute(‘Markups.MovingMarkupIndex’))
pos = [0,0,0]
markupsNode.GetNthControlPointPosition(markupsNodeindex, pos)

I am having problem with the slicer everytime I reload the application is not reloading properly to show the changes in the code i have to restart the slicer every time i do changes in the code so that it reflects inside the slicer application.
Any thing how i can fix this?

regards,
saima

If I understand correctly you successfully solved the problem in this topic. Correct?

Your next question is unrelated, but as a quick advice, you can use the Reload button on the top of your module UI, or add some code to your .slicerrc.py so that Slicer sets up your scene correctly before continuing with testing/development. If you have more questions about this please do a search in the forum first then open a new topic if you don’t find an answer.

A post was split to a new topic: Select locked control points in markuo