[vtkusers] Re: writing several scalars in one file (py and C)...
fred
fredmfp at gmail.com
Thu Apr 5 14:00:49 EDT 2007
Dominik Szczerba a écrit :
> InsertNextValue() reallocates memory if needed, probabely logarithmically. If
> you are not fine with it, and know the size beforehands, just set the size of
> the array at the beginning and write the buffer with [] operator instead of
> appending/reallocation. Read the vtkArray documentation for details.
> Dominik
>
>
Ok.
Does this few lines look right ?
def write_vtkdata_scalars(writer, data, format, name, Nx, Ny, Nz):
print name,
vtkdata = dico_vtkArray_fmt[format]()
vtkdata.SetNumberOfTuples(Nx*Ny*Nz)
vtkdata.SetName(name)
# vtkdata.SetNumberOfComponents(1) # set by default
for k in range(Nz):
for j in range(Ny):
for i in range(Nx):
vtkdata.SetTuple1(k*(Nx*Ny)+j*Nx+i, data[i][j][k])
if (writer.GetPointData().GetNumberOfArrays() == 0):
writer.GetPointData().SetScalars(vtkdata)
else:
writer.GetPointData().AddArray(vtkdata)
I use write_vtkdata_scalars() as
write_vtkdata_scalars(writer, data[0], format, 'raw', Nx, Ny, Nz)
write_vtkdata_scalars(writer, data[1], format, 'filtered', Nx, Ny, Nz)
write_vtkdata_scalars(writer, data[2], format, 'residue', Nx, Ny, Nz)
Can I do this in a better way ?
Thanks in advance.
Cheers,
--
/F
More information about the vtkusers
mailing list