I’m trying to create scalars and add it to the vtkMRMLMarkupsCurveNode. Then I go to the Markups module and I cant find any scalars except PedigreeIDs. Probably I do something wrong… here is the script I use:

# Create random numpy array to use as input
import numpy as np
pointPositions = np.random.uniform(-10,10,size=[4,3])
# Create curve from numpy array
curveNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLMarkupsCurveNode")
slicer.util.updateMarkupsControlPointsFromArray(curveNode, pointPositions)
# Create scalars
scalars = vtk.vtkDoubleArray()
scalars.SetName('MyScalars')
scalars.InsertNextValue(0)
scalars.InsertNextValue(1)
scalars.InsertNextValue(-1)
scalars.InsertNextValue(3)
# Add scalars to curve node
curveNode.GetCurve().GetPointData().SetScalars(scalars)

It seems that scalars in markups are prette tricky.

First of all the number of ControlPoints in markups doesn’t match the number of points of inner poly data object. For example in my case if I have only 4 ControlPoints then I can see that poly data has 31 points.

The next thing is that I was able to add scalars only after copying PedigreeIDs array to my array (using ShallowCopy or DeepCopy) and then adding my array to the polyData’s points data :

# Create random numpy array to use as input
import numpy as np
pointPositions = np.random.uniform(-10,10,size=[4,3])
# Create curve from numpy array
curveNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLMarkupsCurveNode")
slicer.util.updateMarkupsControlPointsFromArray(curveNode, pointPositions)
# Get pedigree array
p=curveNode.GetCurve().GetPointData().GetArray('PedigreeIDs')
# Create scalars
np_scalars = np.random.uniform(-10,10,size=curveNode.GetCurve().GetNumberOfPoints())
scalars = vtk.vtkDoubleArray()
scalars.SetName('MyScalars')
scalars.SetVoidArray(np_scalars, np_scalars.size, 1)
# Copy from pedigree to scalars
p.ShallowCopy(scalars) # or use DeppCopy()
# Add scalars to curve node
curveNode.GetCurve().GetPointData().SetScalars(scalars)

And the last thing is that my scalars are gone right after I do some manipulations with ControlPoints for example moving a single point. The PedigreeIDs array replaces my scalars then.

Curve scalars are managed by measurements (because in general you must update the scalars when the curve is modified). If you just add a scalar array then it will be automatically removed when the curve is updated.

If you don’t want to implement a new measurement then you can use the vtkMRMLStaticMeasurement class (see example here. You need to observe curve modified events and update the scalars in the measurement.