vtkPolyDataConnectivityFilter() doesn't filter data when passed to out using vtk_to_numpy
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
I'm not sure whether this is a vtkPolyDataConnectivityFilter() or a vtk_to_numpy issue, I assume the latter. vtkPolyDataConnectivityFilter() succesfully filters the data when rendering the data or writing the data to an stl. However when I use vtk_to_numpy the surronding regions are passed as well. The odd thing is that some of the regions are filtered. I can tell this by running size. In the example below SetExtractionModeToLargestRegion() eliminates some of the data (size(ar) shrinks from 618 to 597)
Using a standardized dataset the code is below
import vtk import vtk.util.numpy_support as VN from pylab import *
reader = vtk.vtkRectilinearGridReader() reader.SetFileName('.\RectGrid2.vtk')
skinExtractor = vtk.vtkContourFilter() skinExtractor.SetInputConnection(reader.GetOutputPort()) skinExtractor.SetValue(0, 5.2)
skinConnect=vtk.vtkPolyDataConnectivityFilter() skinConnect.SetInputConnection(skinExtractor.GetOutputPort()) skinConnect.SetExtractionModeToLargestRegion()
skinNormals = vtk.vtkPolyDataNormals() skinNormals.SetInputConnection(skinConnect.GetOutputPort()) skinNormals.SetFeatureAngle(60.0)
skinMapper = vtk.vtkPolyDataMapper() skinMapper.SetInputConnection(skinNormals.GetOutputPort()) skinMapper.ScalarVisibilityOn() skinMapper.SetColorModeToMapScalars() skinMapper.SelectColorArray('scalars')
skinActor = vtk.vtkActor() skinActor.SetMapper(skinMapper)
skinu = skinNormals.GetOutput()
Force the pipeline to execute
skinu.Update()
ar = VN.vtk_to_numpy(skinu.GetPoints().GetData()) #print ar temp=[]
for item in ar: if item[2]>0.899999: temp+=[item]
temp=array(temp) x1=temp[:,0] y1=temp[:,1]
scatter(x1,y1) show()
ren = vtk.vtkRenderer() ren.AddActor(skinActor) renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin)
ren.ResetCamera() renWin.Render() iren.Initialize() iren.Start()
=========================================