How to programmatically add control points in slicer from a numpy array

In slicer documentation following example

curveNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLMarkupsCurveNode")
slicer.util.updateMarkupsControlPointsFromArray(curveNode, pointPositions)

where pointPositions is a numpy array but this gives a open markup curve ,what I want to do is just add markup points so I did this

markup_node = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLMarkupsNode")
slicer.util.updateMarkupsControlPointsFromArray(markup_node, pointPositions)

But this is not adding any points as markup points

vtkMRMLMarkupsNode is an abstract base class. You cannot instantiate it, but only a concrete child class. See the list of child classes in the inheritance diagram.

1 Like

Thanks ,solution to this problem is to use vtkMRMLMarkupsFiducialNode class

@lassoan i am now able to put markup points programmatically but since the number of points I am displaying is too large I have to rename them manually from eg Markuppoint_1 to 1 for better visibility,is there a way to show the points without their names?

@mukund_shah I haven’t found a way to turn off the label completely with fiducials but you can set the text scale to zero with markup_node.GetDisplayNode().SetTextScale(0). Example:

import numpy as np
markup_node = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLMarkupsFiducialNode")
slicer.util.updateMarkupsControlPointsFromArray(markup_node, np.random.rand(10,3))
markup_node.GetDisplayNode().SetTextScale(0)

This can be done using:
markup_node.GetDisplayNode().SetPointLabelsVisibility(False)

2 Likes