No cell data from vtkThreshold in Python plugin

I’m experimenting with a simple Python plugin that uses vtkThreshold but constrains the low and high values to a particular delta. The issue I’m having is that unlike the standard “Threshold” filter in ParaView, my simple plugin only outputs the point data, but not the cell data.

I think the most obvious consequence of this is that with the output from the ParaView built-in filter, I can render a Volume representation, whereas with my plugin, there is no option to render as a Volume.

I Googled around a bit, but wasn’t able to determine what the problem might be. One hypothesis I have is that the built-in filter may convert the point data to cell data after doing the processing.

Here’s my simple script, I used the Contour-Shrink example as my starting point,
and I’ll add property parameters later, once I figure out my problem – or real
ly once with the aid of the ParaView community, the problem is solved.

# Synchronized Threshold plugin (From ContourShrink example)
from vtkmodules.util.vtkAlgorithm import VTKPythonAlgorithmBase
from paraview.util.vtkAlgorithm import smproxy, smproperty, smdomain
import vtk    # Note: added to ContourShrink example to make it work

@smproxy.filter(label="Threshold Sync")
@smproperty.input(name="Input")
@smdomain.datatype(dataTypes=["vtkDataSet"], composite_data_supported=False)
class ThresholdSync(VTKPythonAlgorithmBase):
  def __init__(self):
      VTKPythonAlgorithmBase.__init__(self)
      print "Loading Sync'd Threshold plugin"

  def RequestData(self, request, inInfo, outInfo):
      inp = vtk.vtkDataSet.GetData(inInfo[0])
      opt = vtk.vtkPolyData.GetData(outInfo)

      th = vtk.vtkThreshold()
      th.SetInputData(inp)
      print "number of point arrays " + str(inp.GetPointData().GetNumberOfArrays())
      print "number of cell arrays " + str(inp.GetCellData().GetNumberOfArrays())
      print "point data range: " + str(inp.GetPointData().GetArray(0).GetRange())
      th.ThresholdBetween(130.0, 150.0)
      th.Update()       # Note: Update() not available in the Python Shell

      opt.ShallowCopy(th.GetOutput())
      return 1

I’m using the Wavelet source as the input with all default settings.

Thanks in advance, Bill

Hi Bill,

You may have found the solution to this question already, but I’ll respond in any case. This is almost complete, but the output type needs to be specified to the output type of the vtkThreshold filter. You can do this in the call to VTKPythonAlgorithmBase.__init__ by passing in the named parameter outputType='vtkUnstructuredGrid'.

With that change, your code is

# Synchronized Threshold plugin (From ContourShrink example)
from vtkmodules.util.vtkAlgorithm import VTKPythonAlgorithmBase
from paraview.util.vtkAlgorithm import smproxy, smproperty, smdomain
import vtk    # Note: added to ContourShrink example to make it work

@smproxy.filter(label="Threshold Sync")
@smproperty.input(name="Input")
@smdomain.datatype(dataTypes=["vtkDataSet"], composite_data_supported=False)
class ThresholdSync(VTKPythonAlgorithmBase):
  def __init__(self): 
      VTKPythonAlgorithmBase.__init__(self, outputType='vtkUnstructuredGrid')
      print "Loading Sync'd Threshold plugin"

  def RequestData(self, request, inInfo, outInfo):
      inp = vtk.vtkDataSet.GetData(inInfo[0])
      opt = vtk.vtkUnstructuredGrid.GetData(outInfo)

      th = vtk.vtkThreshold()
      th.SetInputData(inp)
      print "number of point arrays " + str(inp.GetPointData().GetNumberOfArrays())
      print "number of cell arrays " + str(inp.GetCellData().GetNumberOfArrays())
      print "point data range: " + str(inp.GetPointData().GetArray(0).GetRange())
      th.ThresholdBetween(130.0, 150.0)
      th.Update()       # Note: Update() not available in the Python Shell

      opt.ShallowCopy(th.GetOutput())
      return 1

With that change, you can volume render the output from this plugin.

HTH, Cory