vtkPNGReader/vtkPNGWriter : Update() consistency ?


Calling Update() on vtkPNGReader performs a file read but calling Update() on vtkPNGWriter does not write out a proper PNG file, one has to call Write(), if I just call Update(), a file of the expected size is written but is not a valid PNG file.

I am building pipeline programmatically and was hoping I am able to call Update() for any vtkAlgorithm derived classes.

Have I done something wrong or misunderstood the purpose of Update() ?

import vtk

reader = vtk.vtkPNGReader()

writer = vtk.vtkPNGWriter()
# writer.Write()


Using Write is the correct API for writer.
It uses Update internally.

I agree that it is confusing though, I think vtkWriter should put that in protected members to avoid the confusion.

If you want to automate calls to Update or Write, you can just check if vtkXMLWriterBase::SafeDownCast returns nullptr, and call Update or Write accordingly.

Actually, no you can’t, we don’t have a base writer class for all writers… In addition to vtkXMLWriterBase, you’d need to check for vtkImageWriter and vtkWriter as well.