SegmentMesher in Slicer 5.2 and 5.3 fail: Error: 'vtkmodules.vtkFiltersCore.vtkThreshold' object has no attribute 'ThresholdByUpper'

Operating system: Windows 11
Slicer version: 5.3
Expected behavior: complete successfully
Actual behavior: fails

I’m trying to create a volume mesh using segmentMesher and it keeps failing:

Generating volumetric mesh…

Error: ‘vtkmodules.vtkFiltersCore.vtkThreshold’ object has no attribute ‘ThresholdByUpper’

Is there something I’m missing out?

Thanks!

Mathieu

This is due to an incorrect API change in VTK (they removed a very widely used method). The fix should be really simple. I’ll try to get to it within a few days.

Thanks Andras, let me know when it is ready, I’ll give it a try! The goal is to import the geometry in COMSOL software for CFD modelling.

Thanks again!

Mat

Hello Iassoan, I was wondering if you had the chance to look at my issue? Your sure are a busy man with all the requests from users :wink:

Thanks!

Mathieu

This post is quite Old, I am using Slicer 5.8.1 and I have a similar problem :frowning:
AttributeError: ‘vtkmodules.vtkFiltersCore.vtkThreshold’ object has no attribute ‘ThresholdBetween’
Is there a solution for that?
I wanted to split my mesh created by Segmented mesher into two meshes.

Edit: My workaround right now:

meshNode = getNode('200µm_Wuerfel')
mesh = meshNode.GetMesh()
cellData = mesh.GetCellData()
labelsRange = cellData.GetArray("labels").GetRange()

for labelValue in range(int(labelsRange[0]), int(labelsRange[1]) + 1):
    threshold = vtk.vtkThreshold()
    threshold.SetInputData(mesh)
    threshold.SetInputArrayToProcess(
        0, 0, 0,
        vtk.vtkDataObject.FIELD_ASSOCIATION_CELLS,
        "labels"
    )
    # untere & obere Schwelle gleich setzen
    threshold.SetLowerThreshold(labelValue)
    threshold.SetUpperThreshold(labelValue)
    threshold.SetThresholdFunction(vtk.vtkThreshold.THRESHOLD_BETWEEN)

    threshold.Update()

    if threshold.GetOutput().GetNumberOfPoints() > 0:
        modelNode = slicer.mrmlScene.AddNewNodeByClass(
            "vtkMRMLModelNode",
            f"{meshNode.GetName()}_{labelValue}"
        )
        modelNode.SetAndObserveMesh(threshold.GetOutput())
        modelNode.CreateDefaultDisplayNodes()