Select contour from the mrml scene

Hello everyone,

I’m using the 3D slicer version 4.10.0 and I want to select a specific contour in my module:

image

However, in the mrml scene I can’t get any ID for the contours:

image

So, the following code doesn’t work:

image

Any idea how to fix this?

Thank you in advance.

There is a specific widget for segment selection: qMRMLSegmentSelectorWidget.

Thanks a lot!

I used the connection: self.inputSegmentationSelector.connect(“currentSegmentChanged(QString)”, self.onContourChange)

And now I want to calculate the center of mass of the selected contour. So I used the following code:

modelNode = slicer.mrmlScene.GetNodesByName((str(targetContour)))
pointCoordinates = slicer.util.arrayFromModelPoints(modelNode) # point coordinates of targetContour

but I’m having the error:

File “C:\Program Files\Slicer 4.10.0\bin\Python\slicer\util.py”, line 795, in arrayFromModelPoints
pointData = modelNode.GetPolyData().GetPoints().GetData()
AttributeError: ‘vtkCommonCorePython.vtkCollection’ object has no attribute ‘GetPolyData’

You get the error because you pass a segmentation node to a function that requires a model node.

What you are tryibg to achieve? Jumping to selected fiducial feature is already implemented. See for example in segment list widget (https://github.com/Slicer/Slicer/blob/a4017472d6220903f7f85c5e49b547f1f6830f39/Modules/Loadable/Segmentations/Widgets/qMRMLSegmentsTableView.h#L65).

I would like to select a specific segment in 3D slicer like this:

image

And then I want to calculate the center of mass of the CTV1. So in order to use the function: getCenterOfMass(contour)

what I need to do?