# Enabling models scalars threshold hides the model

**URL:** <https://discourse.slicer.org/t/enabling-models-scalars-threshold-hides-the-model/3396>\
**Category:** Support\
**Created:** [July 6, 2018, 11:11am UTC](https://discourse.slicer.org/t/enabling-models-scalars-threshold-hides-the-model/3396 "2018-07-06T11:11:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)\
**Post date:** [July 6, 2018, 11:11am UTC](https://discourse.slicer.org/t/enabling-models-scalars-threshold-hides-the-model/3396/1 "2018-07-06T11:11:23Z")

</div>

Hi all,

I’m trying to use the scalars threshold of the Models module for the first time, but when I enable it, the model disappears. I might be doing something wrong. Can you please give me some advice? If you confirm that it’s a bug, I can report it in the issue tracker.

Here’s some code you can paste in the console to create some poly data with associated scalars:

```python
import numpy as np

points = vtk.vtkPoints()
vertices = vtk.vtkCellArray()

sizes = vtk.vtkFloatArray()
sizes.SetName('Sizes')

zMin, zMax = -50, 50
N = 1000
N += 1
b = 2
aMax = 20
z = np.linspace(zMin, zMax, N)
a = (zMax - z)/zMax * aMax
x = a * np.sin(z / b)
y = a * np.cos(z / b)
pointsArray = np.vstack((x, y, z)).T
indices = (z - zMin) / (zMax - zMin) * 300
indices = indices.clip(0, 255).astype(np.uint8)

for i in range(len(pointsArray - 1)):
    point = pointsArray[i]
    pointID = points.InsertNextPoint(point)
    cellID = vertices.InsertNextCell(1)
    vertices.InsertCellPoint(pointID)
    size = a[i]/20
    _ = sizes.InsertNextValue(size)

pointsPolyData = vtk.vtkPolyData()
pointsPolyData.SetPoints(points)
pointsPolyData.SetVerts(vertices)
pointsData = pointsPolyData.GetPointData()
_ = pointsData.SetScalars(sizes)

modelNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLModelNode')
modelNode.CreateDefaultDisplayNodes()
modelNode.SetAndObservePolyData(pointsPolyData)

modelDisplay = modelNode.GetDisplayNode()
modelDisplay.SetAndObserveColorNodeID('vtkMRMLColorTableNodeFileViridis.txt')
modelDisplay.SetScalarVisibility(True)
modelDisplay.SetActiveScalarName('Sizes')
modelDisplay.SetPointSize(3)

layoutManager = slicer.app.layoutManager()
layoutManager.setLayout(slicer.vtkMRMLLayoutNode.SlicerLayoutOneUp3DView)

threeDWidget = layoutManager.threeDWidget(0)
threeDView = threeDWidget.threeDView()
threeDView.resetFocalPoint()

```

---

<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:** [July 6, 2018, 6:30pm UTC](https://discourse.slicer.org/t/enabling-models-scalars-threshold-hides-the-model/3396/2 "2018-07-06T18:30:12Z")

</div>

Before going into the details, could you explain what you would like to achieve?

---

<div class="post-metadata">

**Author:** ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)\
**Post date:** [July 7, 2018, 9:50am UTC](https://discourse.slicer.org/t/enabling-models-scalars-threshold-hides-the-model/3396/3 "2018-07-07T09:50:54Z")

</div>

I have a vessel network generated with VMTK, which has associated scalars representing vessel diameter. I want to use a threshold to interactively show vessels of a specific range of diameters.

---

<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:** [July 7, 2018, 2:58pm UTC](https://discourse.slicer.org/t/enabling-models-scalars-threshold-hides-the-model/3396/4 "2018-07-07T14:58:07Z")

</div>

You can very easily and accurately cut polydata based on associated point or cell scalar values by using VTK thresholding filters, such as vtkThreshold.

---

<div class="post-metadata">

**Author:** ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)\
**Post date:** [July 7, 2018, 5:03pm UTC](https://discourse.slicer.org/t/enabling-models-scalars-threshold-hides-the-model/3396/5 "2018-07-07T17:03:51Z")

</div>

I know, but my understanding is that this feature is currently included in the Slicer core, and I think it doesn’t work.

> <https://github.com/Slicer/Slicer/blob/6e7af66c1567b05a05249dd149872568161a9e58/Libs/MRML/Core/vtkMRMLModelDisplayNode.cxx#L276-L284>

---

<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:** [July 9, 2018, 4:43pm UTC](https://discourse.slicer.org/t/enabling-models-scalars-threshold-hides-the-model/3396/6 "2018-07-09T16:43:15Z")

</div>

Settings in the display node are for display only (does not change the data stored in the model node), so you cannot use that to trim the data set.

However, if you only need to hide parts of your data set for display then you are right, model display settings should be usable.

Thresholding only worked correctly for unstructured grid models and point scalars. I’ve fixed this in r27270. It should be available in tomorrow’s nightly build.

---

<div class="post-metadata">

**Author:** ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)\
**Post date:** [July 9, 2018, 4:54pm UTC](https://discourse.slicer.org/t/enabling-models-scalars-threshold-hides-the-model/3396/7 "2018-07-09T16:54:54Z")

</div>

> [@lassoan](#):
>
> if you only need to hide parts of your data set for display

Yes, this is what I wanted. I’ll try tomorrow and let you know. Thanks!
