Hi,
I’m working on a Python plugin for ParaView.
I’m using the ResampleWithDataset filter and i need to deal with invalid nodes, where the field vtkValidPointMask is set to 0.
I’m trying to use vtkSelectionNode to extract these nodes, but I can’t get it to work.
Here is a simple test case:
import numpy as np
import vtk
import vtk.numpy_interface.dataset_adapter as dsa
# ------------------------------------------
# *** This part create a simple dataset ***
# Create a simple sphere
sphereSource = vtk.vtkSphereSource()
sphereSource.SetPhiResolution(48)
sphereSource.SetThetaResolution(32)
sphereSource.Update()
obj_sphere = sphereSource.GetOutput()
# Get points coordinate
Coords = dsa.vtkDataArrayToVTKArray(obj_sphere.GetPoints().GetData())
# A a test field named vtkValidPointMask
aval = np.arctan2(Coords[:, 0], Coords[:, 1])
tval = (2+np.cos(8*np.pi*Coords[:, 2]) - np.sin(3*aval))/4
obj_sphere.GetPointData().AddArray( dsa.numpyTovtkDataArray(tval, "vtkValidPointMask"))
## Write as vtp file
vf = vtk.vtkXMLPolyDataWriter()
vf.SetFileName("shere.vtp")
vf.SetInputDataObject(obj_sphere)
vf.Write()
## ---------------------------------------------
## *** Here start the test ***
## lecture des fichiers
#vf = vtk.vtkXMLPolyDataReader()
#vf.SetFileName("sphere.vtp")
#vf.Update()
#obj_sphere = vf.GetOutput()
selectionNode = vtk.vtkSelectionNode()
selectionNode.SetFieldType(vtk.vtkSelectionNode.VALUES)
selectionNode.SetContentType(vtk.vtkSelectionNode.QUERY)
selectionNode.SetQueryString("vtkValidPointMask >= 0.5")
selection = vtk.vtkSelection()
selection.AddNode(selectionNode)
extractSelection = vtk.vtkExtractSelection()
extractSelection.SetInputData(0, obj_sphere)
extractSelection.SetInputData(1, selection)
extractSelection.Update()
obj_extract = extractSelection.GetOutput()
print('Sphere : {} points'.format(obj_sphere.GetNumberOfPoints()))
print('Extract : {} points'.format(obj_extract.GetNumberOfPoints()))
Have you got any hint to make this work?
Thanks a lot!
Best regards,
Loic