[vtkusers] Re: writing several scalars in one file (py and C)...
Dominik Szczerba
domi at vision.ee.ethz.ch
Thu Apr 5 14:31:49 EDT 2007
Looks roughly OK to me, but I was not critical as to your indexing
consistency. You still copy, though. I simply set the buffer in a vtkArray,
if I have it elsewhere. But maybe it is not possible with python.
Dominik
On Thursday 05 April 2007 20:00, fred wrote:
> 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,
--
Dominik Szczerba, PhD
Computer Vision Lab CH-8092 Zurich
http://www.vision.ee.ethz.ch/~domi
More information about the vtkusers
mailing list