[vtkusers] writing several scalars in one file (py and C)...

fred fredmfp at gmail.com
Wed Apr 4 07:40:12 EDT 2007


Hi all,

I wonder how can I write several scalars in one file, in C and python.

In C, I tried something like this:

car2[1] = 'v';
vtkXMLWriterC_SetPointData(writer, car2, VTK_DATA_TYPE, vtk_tab_scal_v, 
nbpoints, 1, "SCALARS");
car2[1] = 'x';
vtkXMLWriterC_SetPointData(writer, car2, VTK_DATA_TYPE, vtk_tab_scal_x, 
nbpoints, 1, "SCALARS");
car2[1] = 'y';
vtkXMLWriterC_SetPointData(writer, car2, VTK_DATA_TYPE, vtk_tab_scal_y, 
nbpoints, 1, "SCALARS");
car2[1] = 'z';
vtkXMLWriterC_SetPointData(writer, car2, VTK_DATA_TYPE, vtk_tab_scal_z, 
nbpoints, 1, "SCALARS");

vtkXMLWriterC_SetFileName(writer, filename);
vtkXMLWriterC_Write(writer);
vtkXMLWriterC_Delete(writer);

In python, I tried something like this:

    writer = vtkImageData()
    writer.SetExtent(0, Nx-1, 0, Ny-1, 0, Nz-1)
    writer.SetOrigin(x0, y0, z0)
    writer.SetSpacing(dx, dy, dz)

    vtkdata = vtkFloatArray()
    vtkdata.SetName('raw')
    for k in range(Nz):
        for j in range(Ny):
            for i in range(Nx):
                vtkdata.InsertNextValue(float(data1[i][j][k]))
    writer.GetPointData().SetScalars(vtkdata)

    vtkdata = vtkFloatArray()
    vtkdata.SetName('filtered')
    for k in range(Nz):
        for j in range(Ny):
            for i in range(Nx):
                vtkdata.InsertNextValue(float(data2[i][j][k]))
    writer.GetPointData().SetScalars(vtkdata)
   
    vtkdata = vtkFloatArray()
    vtkdata.SetName('residue')
    for k in range(Nz):
        for j in range(Ny):
            for i in range(Nx):
                vtkdata.InsertNextValue(float(data3[i][j][k]))
    writer.GetPointData().SetScalars(vtkdata)

    fd = vtkXMLImageDataWriter()
    fd.SetFileName(filename)
    fd.SetInput(writer)
    fd.Write()

But none works: the last scalar data erase the previous.

Where can I find info about this ? (gave a look in the VTK book, but
found nothing).

Any suggestion ?

Thanks in advance.

Cheers,

-- 
/F




More information about the vtkusers mailing list