vtkXMLPolyData Writer/Reader 不可逆

vtkXMLPolyData Writer/Reader not reversible

我有一个 vtkPolyData 对象 c,我正在尝试使用 vtkXMLPolyDataWriter:

通过 XML 序列化它
import vtk

print(c.GetNumberOfCells(), c.GetNumberOfPoints())

writer = vtk.vtkXMLPolyDataWriter()
writer.SetInputData(c)
writer.WriteToOutputStringOn()
writer.Update()
s = writer.GetOutputString()

reader = vtk.vtkXMLPolyDataReader()
reader.SetInputString(s)
reader.Update()
c2 = reader.GetOutput()

print(c2.GetNumberOfCells(), c2.GetNumberOfPoints())

打印:

8 6
0 0

有没有办法让这个过程完全可逆?

看来,我在阅读过程中忘记了这行:

reader.ReadFromInputStringOn()

我也把vtkXMLPolyDataReader改成了vtkPolyDataReader(和Writer一样)。