Search code examples
mergevtkparaview

Merging unstructured vtk file is not showing any display in paraview


I have two vtk files obtained after the simulation that needs to be merged for visualization. Initially, I had written the code with vtkPolyData, but since it is unstructured, I changed it to vtkAppendFiler. In both case, I am unable to see any visualization although the files contains the output contents.

Below is the code structure:

from vtk import vtkAppendFilter, vtkUnstructuredGridWriter, vtkPolyData, vtkUnstructuredGridReader

reader = vtkUnstructuredGridReader()
append = vtkAppendFilter()

filenames = ['file1.vtk', 'file2.vtk']
for file in filenames:
    reader.SetFileName(file)
    reader.Update()
    polydata = vtkPolyData()
    polydata.ShallowCopy(reader.GetOutput())
    append.AddInputData(polydata)

append.Update()    

writer = vtkUnstructuredGridWriter()
#writer = vtkPolyDataWriter()
writer.SetFileName('output.vtk')
writer.SetInputData(append.GetOutput())
writer.Write()

Solution

  • The output type of the reader is vtkUnstructuredGrid. As you put it into a vtkpolydata, you try to append empty datasets.

    Edit

    A vtk file contains only one dataset. Its type is defined at the top of the file and does not depends on the reader. If you know that in your case it is always an Unstructured Grid, you can use the vtkUnstructuredGridReader. And the output will always be a vtkUnstructuredGrid.

    You can change your script:

    - polydata = vtkPolyData()
    - polydata.ShallowCopy(reader.GetOutput())
    + unstructured = vtkUnstructuredGrid()
    + unstructured.ShallowCopy(reader.GetOutput())