# using cell data for vtkThreshold

**URL:** https://discourse.vtk.org/t/using-cell-data-for-vtkthreshold/11195
**Category:** Support
**Tags:** python
**Created:** [April 12, 2023, 5:14pm UTC](https://discourse.vtk.org/t/using-cell-data-for-vtkthreshold/11195 "2023-04-12T17:14:40Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![jsesse](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jsesse/32/6880_2.png) [@jsesse](https://discourse.vtk.org/u/jsesse)
#### Post date: [April 12, 2023, 5:14pm UTC](https://discourse.vtk.org/t/using-cell-data-for-vtkthreshold/11195/1 "2023-04-12T17:14:40Z")

</div>

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:

```auto

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!

---

<div class="post-metadata">

### Author: ![Christos\_Tsolakis](https://discourse.vtk.org/user_avatar/discourse.vtk.org/christos_tsolakis/32/2076_2.png) [@Christos\_Tsolakis](https://discourse.vtk.org/u/Christos_Tsolakis)
#### Post date: [April 12, 2023, 6:34pm UTC](https://discourse.vtk.org/t/using-cell-data-for-vtkthreshold/11195/2 "2023-04-12T18:34:01Z")

</div>

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

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

```
