[vtkusers] vtkPolyDataConnectivityFilter() doesn't filter data when passed to out
Peter Halverson
halverson at byu.edu
Mon May 18 12:37:50 EDT 2009
>this uses a standard vtk data set.
A standard vtk dataset, absolutely brilliant (I was wondering how to
demonstrate this)!
I ran the code with and without the commented section.
SetExtractionModeToLargestRegion() eliminates some of the data (size(ar)
shrinks from 618 to 597). However, I'm not sure what it eliminates. When I
plot a slice of ar (AR[2]>0.899999) I get the same plot. A link to a screen
shot of python running in two seperate process (uncommented is the upper) is
available at http://www.et.byu.edu/~pah32/VTK/ScreenCapture.PNG
The modified code is below
=========================================
cd C:\Users\Peter\Desktop\VTKTEMP
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())
# 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
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()
=========================================
Thanks for your help.
On Mon, May 18, 2009 at 7:48 AM, Eric E. Monson <emonson at cs.duke.edu> wrote:
> 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
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090518/8bc41076/attachment.htm>
More information about the vtkusers
mailing list