2011-12-28

An incompatible problem between python-vtk and pyvtk

I am using python-vtk (official Python binding of VTK) and pyvtk (only for VTK-format file I/O) these days. It's not a pleasant experience. It took me a few hours to debug my code and found out the problem at somewhere I never expected - the incompatibility of the libraries I am using. On top of that, one of them has compatibility issue with Python2.7.

I used python-vtk to read from VTK files (because I couldn't google out examples using pyvtk to do so). And then I used pyvtk to write into VTK files (because I couldn't google out examples using python-vtk to create scalar POINTDATA).

The problem is that in python-vtk, vtk.vtkDataSetReader().GetOutput().GetPoint() returns a 3-tuple, which is the X-, Y- and Z-coordinates of a POINT in DATASET POLYDATA block, whereas in pyvtk, pyvtk.PolyData() takes in coordinates as a list, not a 3-tuple.

I don't understand how this could cause problems, because lists and tuples are very similar in Python. After mandatory type conversion, the problem was gone.

pyvtk also has problem with Python2.7. I haven't debugged out the cause. But I just know it does not work with Python2.7.

PS: There is a great lack of resources on these two libraries. I use one library for reading VTK files and the other for writing VTK files, though each of them has the ability to do both. This "complimentary" combination is because I couldn't google out examples on using the opposite library for the opposite function. I really don't understand this. Without document, a software package is nothing.

I didn't find any documentation on pyvtk's website. For python-vtk, released with VTK (C++ mainly, along with Tcl, Python and Java bindings), I still didn't find docs for Python. I had to use iPython to learn.

Does anyone know why?

No comments: