<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hey Peter,<div><br></div><div>I think you really need to call Update() before your conversion to a numpy array, or the pipeline (your filters) won't execute. The writers will automatically update the pipeline before writing out their data, but the vtk_to_numpy() won't, so you'll have to call Update() explicitly before that. For example, here is basically your pipeline, but reading one of the standard VTK data sets (in case you don't have it, you can download the VTK data sets from the site <a href="http://www.vtk.org/VTK/resources/software.html">http://www.vtk.org/VTK/resources/software.html</a> ).</div><div><br></div><div><div>=================</div></div><div><br></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.SetExtractionModeToLargestRegion()</div><div>skinConnect.SetInputConnection(skinExtractor.GetOutputPort())</div><div><br></div><div>skinNormals = vtk.vtkPolyDataNormals()</div><div>skinNormals.SetInputConnection(skinConnect.GetOutputPort()) </div><div>skinNormals.SetFeatureAngle(60.0)</div><div>skinu = skinNormals.GetOutput() </div><div><br></div><div># Force the pipeline to execute</div><div>skinu.Update() </div><div><br></div><div>ar = VN.vtk_to_numpy(skinu.GetPoints().GetData())</div><div><br></div><div>print ar</div><div><br></div><div>=================</div><div><br></div><div>Talk to you later,</div><div>-Eric</div><div><br></div><div apple-content-edited="true"> <span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>------------------------------------------------------</div><div>Eric E Monson</div><div>Duke Visualization Technology Group</div><div><br></div></div></span> </div><br><div><div>On May 12, 2009, at 10:16 PM, Peter Halverson wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Thank you for the fast response. That seems to work really well. Although it ignores my filters. My code is as follows<br><br> reader=vtk.vtkDICOMImageReader()<br> reader.SetDirectoryName('./SE1/')<br> reader.Update()<br> <br> skinExtractor = vtk.vtkContourFilter()<br> skinExtractor.SetInputConnection(reader.GetOutputPort())<br> skinExtractor.SetValue(SkinLow, SkinHigh)<br> <br> skinConnect=vtk.vtkPolyDataConnectivityFilter()<br> skinConnect.SetExtractionModeToLargestRegion()<br> skinConnect.SetInputConnection(skinExtractor.GetOutputPort())<br> <br> skinNormals = vtk.vtkPolyDataNormals()<br> skinNormals.SetInputConnection(skinConnect.GetOutputPort()) <br> skinNormals.SetFeatureAngle(60.0)<br> <div style="text-align: left;"><br></div> ar=vtk_to_numpy(skinNormals.GetOutput().GetPoints().GetData())<br> <br> <br> When I render the image (code shown below) my filters work fine and if I export it as an stl my filters work fine (code also below) [the latter being entirely unnecesarry, but a nice way to check]. As per the help files I've tried decorating the code with Update() <br>[ i.e.<br>skinu= skinNormals.GetOutput() <br>skinu.Update() <br>skinu.GetPoints().GetData()<br>]<br><br>but that hasn't done much...<br> <br> #Render<br> skinMapper = vtk.vtkPolyDataMapper()<br> skinMapper.SetInputConnection(skinNormals.GetOutputPort())<br> skinMapper.ScalarVisibilityOff()<br> <br> skin = vtk.vtkActor()<br> skin.SetMapper(skinMapper)<br> <br> #Export to STL<br> stlout = vtk.vtkSTLWriter()<br> stlout.SetFileName("hello.stl")<br> stlout.SetInput(skinNormals.GetOutput())<br> stlout.SetFileType(2)<br> stlout.Write()<br> <br><br><div class="gmail_quote">On Tue, May 12, 2009 at 1:15 PM, Eric E. Monson <span dir="ltr"><<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> Say pd is a vtkPolyData() object, then you can get the point coordinates with:<br> <br> vtk_to_numpy(pd.GetPoints().GetData())<br> <br> -Eric<br> <br> ------------------------------------------------------<br> Eric E Monson<br> Duke Visualization Technology Group<div><div></div><div class="h5"><br> <br> <br> On May 12, 2009, at 12:12 PM, 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 attempting to export VTK data into numpy using vtk_to_numpy. The program reads in a set of DICOM files using vtkDICOMImageReader. Filters the image using vtkContourFilter, and some other stuff and then displays the rendered solid. I would then like to export the data to Numpy so i do the following scalars=skin.GetMapper().GetInput().GetPointData().GetScalars()<br> <br> Which gives me the scalars that I am looking for. My question is how do get the [x,y,z] data to go with the scalars into numpy?<br> <br> skin.GetMapper().GetInput().GetWholeExtent() gives me the correct dimensions (0, 511, 0, 511, 0, 56) but I have exported less scalars than this...<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> _______________________________________________<br>Powered by <a href="http://www.kitware.com">www.kitware.com</a><br><br>Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html">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">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">http://www.vtk.org/mailman/listinfo/vtkusers</a><br></blockquote></div><br></div></body></html>