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