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

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)
    size = a[i]/20
    _ = sizes.InsertNextValue(size)

pointsPolyData = vtk.vtkPolyData()
pointsData = pointsPolyData.GetPointData()
_ = pointsData.SetScalars(sizes)

modelNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLModelNode')

modelDisplay = modelNode.GetDisplayNode()

layoutManager = slicer.app.layoutManager()

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

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!