# Unable to add scalars to \`vtkMRMLMarkupsCurveNode\`

**URL:** <https://discourse.slicer.org/t/unable-to-add-scalars-to-vtkmrmlmarkupscurvenode/21341>\
**Category:** Development\
**Created:** [January 6, 2022, 2:57am UTC](https://discourse.slicer.org/t/unable-to-add-scalars-to-vtkmrmlmarkupscurvenode/21341 "2022-01-06T02:57:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)\
**Post date:** [January 6, 2022, 2:57am UTC](https://discourse.slicer.org/t/unable-to-add-scalars-to-vtkmrmlmarkupscurvenode/21341/1 "2022-01-06T02:57:44Z")

</div>

Hi,

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:

```python
# 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)

```

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/b/bbc7f0596d855c4ecdbc34767d9b6ae88edf8380.jpeg)

---

<div class="post-metadata">

**Author:** ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)\
**Post date:** [January 29, 2022, 9:10pm UTC](https://discourse.slicer.org/t/unable-to-add-scalars-to-vtkmrmlmarkupscurvenode/21341/2 "2022-01-29T21:10:11Z")

</div>

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 :

```auto
# 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.

---

<div class="post-metadata">

**Author:** ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)\
**Post date:** [February 5, 2022, 3:34pm UTC](https://discourse.slicer.org/t/unable-to-add-scalars-to-vtkmrmlmarkupscurvenode/21341/3 "2022-02-05T15:34:31Z")

</div>

It seems that even this solution doesn’t work anymore.  
If somebody knows a reason please share

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 14, 2022, 11:54pm UTC](https://discourse.slicer.org/t/unable-to-add-scalars-to-vtkmrmlmarkupscurvenode/21341/4 "2022-10-14T23:54:26Z")

</div>

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](https://github.com/Slicer/Slicer/blob/3a6d7b3d9a7e0f649fc6db40b360b798a79dfb57/Modules/Loadable/Markups/Testing/Python/MarkupsCurveMeasurementsTest.py#L130-L135). You need to observe curve modified events and update the scalars in the measurement.

---

<div class="post-metadata">

**Author:** ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)\
**Post date:** [October 15, 2022, 12:45pm UTC](https://discourse.slicer.org/t/unable-to-add-scalars-to-vtkmrmlmarkupscurvenode/21341/5 "2022-10-15T12:45:24Z")

</div>

Thank you very much!  
That should work.
