I am trying to clip a 2d slice polydata by scalar within a programmable filter. I want to do this within the programmable filter to wrap up a number of different steps together. I think this should be fairly simple, but for some reason struggling to find a good example of the vtk syntax similar to how the clip by scalar is handled in the paraview GUI.
Can someone help provide a simple example? Input is a single 2d slice polydata object, then also want to define scalar variable and value.
Thanks,
I was able to put together a simple conceptual example that seems to almost work…
To set up the test case:
- I set up a simple plane source,
- Ran teh plane through an Elevation filter to give it Scalar data to clip,
- Added 2nd scalar with a Calculator Filter where [elev2] = [Elevation]*2
The Calculator Filter is then input to the programmable filter with this code to clip a defined Scalar array by a defined value.
import vtk
inputs0=inputs[0].VTKObject
clipper = vtk.vtkClipPolyData()
clipper.SetInputDataObject(inputs0) # Use the output with scalars
clipper.SetInputArrayToProcess(0,0,0,vtk.vtkDataObject.FIELD_ASSOCIATION_POINTS,'Elevation')
clipper.SetValue(.75)
clipper.Update()
outData = clipper.GetOutput(0)
output.ShallowCopy(outData)
This is the result that I get in Paraview
The problem is that it appears to continue using the Scalar “elev2” to do the clipping instead of the defined “Elevation” scalar.
Can someone tell me what is going wrong here in order to specify which Scalar array that I want to clip?
import vtk
inputs0=inputs[0].VTKObject
inputs0.GetPointData().SetActiveScalars(“Elevation”)
clipper = vtk.vtkClipPolyData()
clipper.SetInputDataObject(inputs0) # Use the output with scalars
#clipper.SetInputArrayToProcess(0,0,0,vtk.vtkDataObject.FIELD_ASSOCIATION_POINTS,‘Elevation’)
clipper.SetValue(.75) # Clip all cells where the scalar value is less than this
clipper.Update()
outData = clipper.GetOutput(0)
output.ShallowCopy(outData)
Things seem to be working now if I just SetActiveScalars of the the desired scalar variable. Note I commented out the the line for “SetInputArrayToProcess”
Is defining the “SetActiveScalar” the way this clip filter is supposed to work for scalars?