vtk handling of python file-like objects, gzipped stls

Hello,

I am using python vtk for reading in, manipulating, and then exporting .stl files. Often these are gzipped, or download from/exported to a remote file system (amazon s3).

If there any way to use vtkSTLReader and vtkSTLWriter with python file-like objects? This would allow me to zip/unzip in a purely pythonic way, and obviate the need for writing temp files both in zipping and in down/uploading to s3. Or, any workaround that can skip the temp file creation?

Thanks!

VTK I/O filters tend to work with file names rather than stream objects (even passing a FILE* or std::istream/std::ostream to the filters is a no-go). I think this is because VTK filters like to open/close files explicitly rather than relying on “I’m done writing data” signals of any kind or needing some way to “rewind” a file that it wants to read again.

So, no, there’s probably no way to avoid the temporary file creation without some more thought put into VTK’s I/O strategies in use.

The vtkSTLReader checks the file size, which is a no-go for streaming (I’m not sure if it absolutely has to, but it does). And as Ben pointed out, it’s not uncommon for a reader to have to seek within the file.

I wrote the Python wrappers to be able to recognize std::istream and std::ostream parameters, but in the end I never hooked these up to Python streams because I found that the actual usefulness of this was less than I had originally thought. I’m willing to help if anyone wants to give it a go.