Python wrappers: input/output to and from string broken
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
(This is using a recent (April 2007) CVS version)
The VTK classes vtkDataWriter and vtkDataReader provide methods for writing and reading to/from a string, instead of the usual file. These are really handy for situations where a dataset isn't supposed or doesn't need to hit the disk (like when transferring over a network).
Although VTK's Python wrappers do make the necessary methods available to Python scripts, they are not usable in their current form. This is because embedded NULL characters in input/output strings aren't correctly handled.
Specifically:
- vtkDataSetWriter.GetOutputString will return a Python string up to the first \x00 in the output, which for a binary VTK file, is somewhere after the header.
- Working around the limitation by setting the file type to ASCII (so no embedded NULLs are in the output string) usually fails in vtkDataSetWriter.Write(). This seems to be related to the amount of space reserved for the output string.
- vtkDataSetReader.Set(Binary)InputString does not allow to pass a Python string containing an embedded NULL character.
- A work-around exists by passing a vtkCharArray instead of a string for the previous point, but this is really inefficient
The problems at the VTK <-> Python boundary come from the specific Python C/API functions used to handle the string marshalling.