[vtkusers] vtkPolyDataConnectivityFilter() doesn't filter data when passed to out
Eric E. Monson
emonson at cs.duke.edu
Mon May 18 14:51:09 EDT 2009
Hey Peter,
Yeah, that's weird. I was able to reproduce what you're talking about.
It's really strange that the data gets passed to the numpy array but
doesn't show up in the render window. Not sure what's going on...
Since I didn't know about all of these options in the connectivity
filter before today, I would have done something like this to extract
the large region: Run the connectivity filter in the mode where it
passes all regions, but assigns region IDs, and then do a threshold
filter on the results. One variant of this is shown below. Beyond this
you'll probably have to get someone to chime in who understands the
connectivity filter better. (In my example, I used mayavi to do a 3d
plot of the points to see which are passed.)
===============
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)
skinThresh = vtk.vtkThresholdPoints()
skinThresh.SetInputConnection(skinNormals.GetOutputPort())
skinThresh.ThresholdByLower(0.5) # only pass region id = 0
skinMapper = vtk.vtkPolyDataMapper()
skinMapper.SetInputConnection(skinThresh.GetOutputPort())
skinMapper.ScalarVisibilityOn()
skinMapper.SetColorModeToMapScalars()
skinMapper.SelectColorArray('scalars')
skinActor = vtk.vtkActor()
skinActor.SetMapper(skinMapper)
skinu = skinThresh.GetOutput()
# Force the pipeline to execute
skinu.Update()
ar = VN.vtk_to_numpy(skinu.GetPoints().GetData())
# import enthought.mayavi.mlab as mlab
# mlab.points3d(ar[:,0],ar[:,1],ar[:,
2],scale_mode='none',scale_factor=0.02);
print ar.shape
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()
===============
Good luck,
-Eric
On May 18, 2009, at 12:37 PM, Peter Halverson wrote:
> >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
>
> ...
>
> 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.
>
> ...
>
> 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/e83e4a3f/attachment.htm>
More information about the vtkusers
mailing list