[vtkusers] python numarray to vtk ?
rharder at uiuc.edu
rharder at uiuc.edu
Wed Mar 17 23:15:09 EST 2004
Hi,
Is there anything wrong with this method, or is there a better way? It works
but i hate to invest time into making this method the backbone of my
imageing bits if it's prone to something i don't understand. I'm primarily
concerned about the six or so commands.
from numarray import *
import vtk
a = array( (arange(1,10000)),type=Float64) #or any numarray
datastring = a.tostring()
data = vtk.vtkDoubleArray()
data.SetVoidArray( datastring, len(datastring)/data.GetDataTypeSize(), 1)
id = vtk.vtkImageData()
id.GetPointData().SetScalars(data)
id.SetDimensions(100,100,1)
id.SetSpacing(1.0,1.0,0.0)
id.SetOrigin(0.0,0.0,0.0)
#Then on through the usual mapper, actor, etc...
im = vtk.vtkImageMapper()
im.SetInput( id )
im.SetColorWindow( 10000.0 )
im.SetColorLevel( 5000. )
ia = vtk.vtkActor2D()
ia.SetMapper( im )
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.SetSize(100,100)
ren.AddActor(ia)
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow( renWin )
#iren.Initialize()
renWin.Render()
iren.Start()
Thanks for your advice,
Ross
More information about the vtkusers
mailing list