<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hey Peter,<div><br></div><div>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...</div><div><br></div><div>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.)</div><div><br></div><div>===============</div><div><div>import vtk</div><div>import vtk.util.numpy_support as VN</div><div><br></div><div>reader = vtk.vtkRectilinearGridReader()</div><div>reader.SetFileName('/Users/emonson/Programming/VTK_cvs/VTKData/Data/RectGrid2.vtk')</div><div><br></div><div>skinExtractor = vtk.vtkContourFilter()</div><div>skinExtractor.SetInputConnection(reader.GetOutputPort())</div><div>skinExtractor.SetValue(0, 5.2)</div><div><br></div><div>skinConnect=vtk.vtkPolyDataConnectivityFilter()</div><div>skinConnect.SetInputConnection(skinExtractor.GetOutputPort())</div><div><br></div><div># All Regions:</div><div>skinConnect.SetExtractionModeToAllRegions()</div><div>skinConnect.SetColorRegions(1)</div><div><br></div><div># Largest Region:</div><div># skinConnect.SetExtractionModeToLargestRegion()</div><div><br></div><div>skinNormals = vtk.vtkPolyDataNormals()</div><div>skinNormals.SetInputConnection(skinConnect.GetOutputPort())&nbsp;</div><div>skinNormals.SetFeatureAngle(60.0)</div><div><br></div><div>skinThresh = vtk.vtkThresholdPoints()</div><div>skinThresh.SetInputConnection(skinNormals.GetOutputPort())</div><div>skinThresh.ThresholdByLower(0.5)<span class="Apple-tab-span" style="white-space:pre">        </span># only pass region id = 0</div><div><br></div><div>skinMapper = vtk.vtkPolyDataMapper()</div><div>skinMapper.SetInputConnection(skinThresh.GetOutputPort())</div><div>skinMapper.ScalarVisibilityOn()</div><div>skinMapper.SetColorModeToMapScalars()</div><div>skinMapper.SelectColorArray('scalars')</div><div><br></div><div>skinActor = vtk.vtkActor()</div><div>skinActor.SetMapper(skinMapper)</div><div><br></div><div>skinu = skinThresh.GetOutput()&nbsp;</div><div># Force the pipeline to execute</div><div>skinu.Update()&nbsp;</div><div><br></div><div>ar = VN.vtk_to_numpy(skinu.GetPoints().GetData())</div><div># import enthought.mayavi.mlab as mlab</div><div># mlab.points3d(ar[:,0],ar[:,1],ar[:,2],scale_mode='none',scale_factor=0.02);</div><div><br></div><div>print ar.shape</div><div><br></div><div>ren = vtk.vtkRenderer()</div><div>ren.AddActor(skinActor)</div><div>renWin = vtk.vtkRenderWindow()</div><div>renWin.AddRenderer(ren)</div><div>iren = vtk.vtkRenderWindowInteractor()</div><div>iren.SetRenderWindow(renWin)</div><div><br></div><div>ren.ResetCamera()</div><div>renWin.Render()</div><div>iren.Initialize()</div><div>iren.Start()</div><div><br></div></div><div><div>===============</div><div><br></div><div>Good luck,</div><div>-Eric</div><div><br></div></div><div>&nbsp;<br><div><div>On May 18, 2009, at 12:37 PM, Peter Halverson wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">>this uses a standard vtk data set.<br>A standard vtk dataset, absolutely brilliant (I was wondering how to demonstrate this)! <br><br>&nbsp;I ran the code with and without the commented section.&nbsp; 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.&nbsp; A link to a screen shot of python running in two seperate process (uncommented is the upper) is available at <a href="http://www.et.byu.edu/~pah32/VTK/ScreenCapture.PNG">http://www.et.byu.edu/~pah32/VTK/ScreenCapture.PNG</a><br> <br>The modified code is below<br><br>...<br><br>Thanks for your help.<br><br><br><div class="gmail_quote"> On Mon, May 18, 2009 at 7:48 AM, Eric E. Monson <span dir="ltr">&lt;<a href="mailto:emonson@cs.duke.edu">emonson@cs.duke.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> Hey Peter,<br> <br> I think the filter is working correctly. Try this modification of your earlier script. (Again, this uses a standard VTK data set.)<br> <br> 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.<br> <br>...</blockquote></div></blockquote><blockquote type="cite"><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br> Hope this helps clear it up,<br> -Eric<br> <br> ------------------------------------------------------<br> Eric E Monson<br> Duke Visualization Technology Group<div><div></div><div class="h5"><br> <br> <br> On May 14, 2009, at 10:52 AM, Peter Halverson wrote:<br> <br> </div></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div class="h5"> I'm having some difficulty with vtkPolyDataConnectivityFilter(). &nbsp;VTK is able to visualize it but I can't get the data out of it. &nbsp;I've written a program that works as follows<br> <br> 1. Uses vtkDICOMImageReader() to read in a CT image and pass that to<br> 2. vtkContourfilter() to reduce that image and pass that to<br> 3. vtkPolyDataConnectivityFilter() to get the largest connected region and pass that to<br> 4. vtkPolyDataNormals() which passes it to<br> 5. vtkPolyDataMapper() and then to<br> 6. vtkActor() which is able to render only the largest connected region (the skin in this case)<br> <br> 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. &nbsp;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.<br> <br> Peter<br></div></div> _______________________________________________<br> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br> <br> Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br> <br> Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br> <br> Follow this link to subscribe/unsubscribe:<br> <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br> </blockquote> <br> </blockquote></div><br></blockquote></div><br></div></body></html>