[vtkusers] Python vtkPointData Help!
Bruno da Silva de Oliveira
bruno at esss.com.br
Thu Sep 29 13:17:09 EDT 2005
Hi Charles,
Charles O'Connor wrote:
> Dear VTK users,
>
> I am new to VTK and trying to get my data read into its format. I have
> prepared my data as a VTK data array by doing the following:
>
> -------------------------------------------------------------
> aa = vtk.vtkFloatArray()
> aa.SetNumberOfValues( nxx * nyy )
> aa.SetName( 'pcmdiqnt' )
> k = 0
> for j in range( 0, nyy ):
> for i in range( 0, nxx ):
> aa.SetValue( k, vv[j,i] )
> k = k + 1
>
> bb = vtk.vtkPointData()
> bb.AddArray( aa )
> print 'debug PointData IsArrayAnAttribute', bb.IsArrayAnAttribute( 0 )
> print 'debug bb PointData array 0 name = ', bb.GetArrayName( 0 )
> print 'debug bb PointData array count = ', bb.GetNumberOfArrays( )
You must not create a vtk.vtkPointData by hand. You have to use the ones
avaiable in the vtk.vtkStructuredGrid itself.
> What I am ultimately after is:
>
> pp = vtk.vtkPoints()
> pp.SetNumberOfPoints( nxx * nyy )
> k = 0
> for j in range( 0, nyy ):
> for i in range( 0, nxx ):
> pp.SetPoint( k, xx[i], yy[j], 0.0 )
> k = k + 1
>
> ss = vtk.vtkStructuredGrid()
> ss.SetDimensions( nxx, nyy, 1 )
> ss.SetPoints( pp )
> ss.SetFieldData( bb )
> ss.Update()
> ss.UpdateData()
Try this (untested):
pp = vtk.vtkPoints()
for j in range( 0, nyy ):
for i in range( 0, nxx ):
pp.InsertNextPoint(xx[i], yy[j], 0.0)
ss = vtk.vtkStructuredGrid()
ss.SetDimensions( nxx, nyy, 1 )
ss.SetPoints( pp )
ss.GetPointData().AddArray( aa )
Hope that helps,
--
Bruno da Silva de Oliveira
bruno at esss.com.br
ESSS - Engineering Simulation and Scientific Software
http://www.esss.com.br
More information about the vtkusers
mailing list