Enabling models scalars threshold hides the model

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:

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()

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

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.

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

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

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.

1 Like

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