[vtkusers] VTK and Numpy

Peter Halverson halverson at byu.edu
Tue May 12 22:16:50 EDT 2009


Thank you for the fast response. That seems to work really well. Although it
ignores my filters. My code is as follows

reader=vtk.vtkDICOMImageReader()
reader.SetDirectoryName('./SE1/')
reader.Update()

skinExtractor = vtk.vtkContourFilter()
skinExtractor.SetInputConnection(reader.GetOutputPort())
skinExtractor.SetValue(SkinLow, SkinHigh)

skinConnect=vtk.vtkPolyDataConnectivityFilter()
skinConnect.SetExtractionModeToLargestRegion()
skinConnect.SetInputConnection(skinExtractor.GetOutputPort())

skinNormals = vtk.vtkPolyDataNormals()
skinNormals.SetInputConnection(skinConnect.GetOutputPort())
skinNormals.SetFeatureAngle(60.0)

ar=vtk_to_numpy(skinNormals.GetOutput().GetPoints().GetData())


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()
[ i.e.
skinu= skinNormals.GetOutput()
skinu.Update()
skinu.GetPoints().GetData()
]

but that hasn't done much...

#Render
skinMapper = vtk.vtkPolyDataMapper()
skinMapper.SetInputConnection(skinNormals.GetOutputPort())
skinMapper.ScalarVisibilityOff()

skin = vtk.vtkActor()
skin.SetMapper(skinMapper)

#Export to STL
stlout = vtk.vtkSTLWriter()
stlout.SetFileName("hello.stl")
stlout.SetInput(skinNormals.GetOutput())
stlout.SetFileType(2)
stlout.Write()


On Tue, May 12, 2009 at 1:15 PM, Eric E. Monson <emonson at cs.duke.edu> wrote:

> Hey Peter,
>
> Say pd is a vtkPolyData() object, then you can get the point coordinates
> with:
>
> vtk_to_numpy(pd.GetPoints().GetData())
>
> -Eric
>
> ------------------------------------------------------
> Eric E Monson
> Duke Visualization Technology Group
>
>
>
> On May 12, 2009, at 12:12 PM, Peter Halverson wrote:
>
>  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()
>>
>> 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?
>>
>> skin.GetMapper().GetInput().GetWholeExtent() gives me the correct
>> dimensions (0, 511, 0, 511, 0, 56) but I have exported less scalars than
>> this...
>> _______________________________________________
>> 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/20090512/3fa47008/attachment.htm>


More information about the vtkusers mailing list