[vtkusers] vtkPolyDataConnectivityFilter() doesn't filter data when passed to out
Eric E. Monson
emonson at cs.duke.edu
Mon May 18 09:48:39 EDT 2009
Hey Peter,
I think the filter is working correctly. Try this modification of your
earlier script. (Again, this uses a standard VTK data set.)
By default I've changed the option on the connectivity filter to grab
all regions, but color them by their region number. You should see two
sort of parabolic-shaped regions, one red and one blue. If you comment
out the "all regions" stuff and use the "largest region", you should
just see the large region in the render window. You can also see that
there are extra coordinate points printed out for the "all regions"
case, so I think the data is getting to the numpy array correctly.
===============
import vtk
import vtk.util.numpy_support as VN
reader = vtk.vtkRectilinearGridReader()
reader.SetFileName('/Users/emonson/Programming/VTK_cvs/VTKData/Data/
RectGrid2.vtk')
skinExtractor = vtk.vtkContourFilter()
skinExtractor.SetInputConnection(reader.GetOutputPort())
skinExtractor.SetValue(0, 5.2)
skinConnect=vtk.vtkPolyDataConnectivityFilter()
skinConnect.SetInputConnection(skinExtractor.GetOutputPort())
# All Regions:
skinConnect.SetExtractionModeToAllRegions()
skinConnect.SetColorRegions(1)
# Largest Region:
# 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
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()
===============
Hope this helps clear it up,
-Eric
------------------------------------------------------
Eric E Monson
Duke Visualization Technology Group
On May 14, 2009, at 10:52 AM, Peter Halverson wrote:
> I'm having some difficulty with vtkPolyDataConnectivityFilter().
> VTK is able to visualize it but I can't get the data out of it.
> I've written a program that works as follows
>
> 1. Uses vtkDICOMImageReader() to read in a CT image and pass that to
> 2. vtkContourfilter() to reduce that image and pass that to
> 3. vtkPolyDataConnectivityFilter() to get the largest connected
> region and pass that to
> 4. vtkPolyDataNormals() which passes it to
> 5. vtkPolyDataMapper() and then to
> 6. vtkActor() which is able to render only the largest connected
> region (the skin in this case)
>
> When I pass the data to python using
> vtk_ar
> =
> vtk_to_numpy(skinactor.GetMapper().GetInput().GetPoints().GetData())
> I get the output from step 2 which includes the disconnected
> regions. I've searched the vtk mail archives and the books but
> can't find out how to get the data after the ConnectivityFilter is
> called. I'm new to vtk, any help would be appreciated.
>
> Peter
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
More information about the vtkusers
mailing list