Obtaining Segmentations for Fiducials

Hi again,
I have a few questions about this :
See this example in the script repository:
https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Get_segments_visible_at_a_selected_position

When I run this script, I got the error:

AttributeError: ‘NoneType’ object has no attribute ‘AddObserver’

(In line: markupsFiducialNode.AddObserver(slicer.vtkMRMLMarkupsPlaneNode.PointModifiedEvent, printSegmentNames)
How can we solve this error ?

  1. Assume that some of the segmentations are visible in the current segment, but are visible in different anterior/posterior positions. Can this script find those segments ? Ie., I need to do this in 3D coordinates, not just in one slice.

Thank you so much.

You need to place a markups fiducial point before you run the script.

I already have them, but I am still getting the same error.

Do you use latest Slicer Preview Release?

I am using Slicer 4.11. Should I switch to 4.10 ?

Latest Slicer-4.11 should work well.

This line sets the first markups fiducial node in the scene in variable markupsFiducialNode:

markupsFiducialNode = slicer.mrmlScene.GetFirstNodeByClass("vtkMRMLMarkupsFiducialNode")

If you get an error that markupsFiducialNode is None then it means that there is no markups fiducial node in your scene, so you need to add one. Can you post a screenshot of your Slicer application window?

I think I found the problem, by your help.
But I have another question : I have several different fiducial files. How can I modify

markupsFiducialNode = slicer.mrmlScene.GetFirstNodeByClass("vtkMRMLMarkupsFiducialNode")

to pick the one that I need to use ?

Thanks.

Complete this programming tutorial to learn about basics of Python scripting in Slicer: https://www.slicer.org/wiki/Documentation/Nightly/Training#PerkLab.27s_Slicer_bootcamp_training_materials

OK I also solved it.

So the last thing : I need to check the segments in all slices, not just in one. It seems like this script is missing the segments which are not visible in the current slice.
Is it possible to loop over all slices so that segments of different slices are also covered ?

Thanks.

If you show the binary labelmap representation in the slice view then you should be able to get all segments.

You can also use vtkMRMLSegmentationsDisplayableManager3D’s Pick3D method, and then get GetPickedNodeID and GetPickedSegmentID to get the picked node and segment, but these only return the first hit.

I have many segments and I don’t think I can make all of them visible in just one slice… Any suggestions about that ?

I couldn’t find an example for using vtkMRMLSegmentationsDisplayableManager3D. I am trying :
sliceViewWidget = slicer.app.layoutManager().sliceWidget(sliceViewLabel)
segmentationsDisplayableManager = sliceViewWidget.sliceView().displayableManagerByClassName(‘vtkMRMLSegmentationsDisplayableManager3D’)

But segmentationsDisplayableManager is returned as None.

Individual segments don’t have to be visible in that slice view, just the segmentation overall. Again, it is important to set the visible representation to binary labelmap.

If you want to try 3D displayable manager then retrieve that from a 3D view.