Hi, Andras
I have a numpy array that contains some points. I want to create a vtkMRMLMarkupsCurveNode. So, I call the function curveNode.AddControlPoint() to add every point coordinate. But that’s too slow. What’s the better way to do this?
Thank you.

for pointIndex in range(len(centerlinePoints)):
centerlineCurveNode.AddControlPoint(vtk.vtkVector3d(centerlinePoints[pointIndex][0], centerlinePoints[pointIndex][1], centerlinePoints[pointIndex][2]))

You may speed up node updates if you call wasModify=centerlineCurveNode.StartModify() before starting to add points and call centerlineCurveNode.EndModify(wasModify) when you are done.

If you have hundreds or thousands of points then you can update them all at once using SetControlPointPositionsWorld (if you have your inputs as a numpy array then you need to convert the array to vtkPoints object first).

If you have thousands of points then probably you also want to reduce number of interpolated points using SetNumberOfPointsPerInterpolatingSegment().

Hello! When I input your code in the python interrupter , I get “name ‘centerlineCurveNode’ is not defined”. Can you tell me how to import centerlineCurveNode? Thank you in advance.

Here is a complete example that works fine in recent Slicer versions:

# Create random numpy array to use as input
import numpy as np
pointPositions = np.random.uniform(-50,50,size=[15,3])
# Create curve from numpy array
curveNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLMarkupsCurveNode")
slicer.util.updateMarkupsControlPointsFromArray(curveNode, pointPositions)