using cell data for vtkThreshold

Hi. I am trying to use vtkThreshold to extract cells from a polydata set. I would like the threshold to be based on the cell label (from the data array of cells) instead of on the point labels. I have tried the following:



def threshold(polydata, thresh_low:int, thresh_high:int):

    threshold_filter = vtk.vtkThreshold()
    threshold_filter.SetInputData(polydata)


    threshold_filter.SetInputArrayToProcess(0, 0, 0, vtk.vtkDataObject.FIELD_ASSOCIATION_CELLS, 'scalars')
    threshold_filter.SetUpperThreshold(thresh_high)  
    threshold_filter.SetLowerThreshold(thresh_low) 
    
    threshold_filter.Update()
    
    unstructured_grid = threshold_filter.GetOutput()
    geometry_filter = vtk.vtkGeometryFilter()
    geometry_filter.SetInputData(unstructured_grid)
    geometry_filter.Update()
    poly_select = geometry_filter.GetOutput()
   
    
    return poly_select

but the thresholding was still placed on the point data array.

I also tried SetAttributeModeToUseCellData(), but the function seems to be deprecated in vtk 9.2.

Any comment would be helpful!

Hi @jsesse and welcome to VTK discourse !

Your code looks correct maybe the problem lies somewhere else ? Bellow a self-contained example that works as expected

from vtkmodules.vtkImagingCore import vtkRTAnalyticSource
from vtkmodules.vtkCommonDataModel import vtkDataObject
from vtkmodules.vtkFiltersCore import vtkThreshold,vtkPointDataToCellData

wavelet = vtkRTAnalyticSource()
pcfilter = vtkPointDataToCellData()
pcfilter.SetInputConnection(wavelet.GetOutputPort())
#pcfilter.PassPointDataOn()

tfilter = vtkThreshold()
tfilter.SetInputConnection(pcfilter.GetOutputPort())
tfilter.SetInputArrayToProcess(0, 0, 0, vtkDataObject.FIELD_ASSOCIATION_CELLS , 'RTData')
tfilter.SetUpperThreshold(200)
tfilter.SetLowerThreshold(150)
tfilter.Update()
info = tfilter.GetOutput()
print(wavelet.GetOutput().GetNumberOfCells())
print(info.GetNumberOfCells())