Is this the proper way to use vtkStructuredGridAppend?

I seem to have an issue with vtkStructuredGridAppend. I am not sure if I am doing something wrong. I have two small structured grids. Each contains scalar data and the scalar data has the same names in both files. I want to append these two grids. When I run the code below, there are no warnings or errors, but the result only includes the last grid added, rather than the appended grid.

I am using Python 3.7.5 with version 8.2.0 of the vtk module.

If I use vtkAppendFilter, the append works, but it results in an unstructured grid.

Thanks,

Kent

    import vtk

    file1='region_1/region_1.vtk'
    file2='region_2/region_2.vtk'

    # create an append filter to hold data
    append = vtk.vtkStructuredGridAppend()

    rdr = vtk.vtkStructuredGridReader()
    rdr.ReadAllScalarsOn()
    rdr.SetFileName(file1)
    rdr.Update()

    rdr2 = vtk.vtkStructuredGridReader()
    rdr2.ReadAllScalarsOn()
    rdr2.SetFileName(file2)
    rdr2.Update()

    append.AddInputData(rdr.GetOutput())
    append.AddInputData(rdr2.GetOutput())
    append.Update()

    # write out appended data
    writer = vtk.vtkStructuredGridWriter()
    writer.SetFileName("merged_data.vtk")
    writer.SetInputData(append.GetOutput())
    writer.Update()
    writer.Write()
1 Like

Have you tried :

`         

append.AddInputData(0, rdr.GetOutput())``
append.AddInputData(1, rdr2.GetOutput())

``

`

Thanks. I had tried that, but it fails:

ERROR: In …/Common/ExecutionModel/vtkAlgorithm.cxx, line 893
vtkStructuredGridAppend (0x2b6cfb7cc9d0): Attempt to connect input port index 1 for an algorithm with 1 input ports.

Hey @kabel,

facing this problem as well. What I found quite helpful was the tests for the vtkStructuredGridAppend

Link: https://gitlab.kitware.com/vtk/vtk/-/blob/v8.2.0/Filters/Core/Testing/Cxx/TestStructuredGridAppend.cxx

So far I wasn’t able to apply this approach to this topic as they are creating in the file and are not reading some vtk file.