[vtkusers] writing binary files with pyvtk - bug in PyVTK or in VTK?
Hans Fangohr
H.FANGOHR at soton.ac.uk
Fri Jan 24 14:10:02 EST 2003
Dear all,
if you want to write vtk-files from a python script, the PyVTK package
is a great tool (http://cens.ioc.ee/projects/pyvtk/).
The MayaVi-package (http://mayavi.sourceforge.net/) is a great tool to
interactively use VTK, and can read vtk-files.
Now I have discovered one problem with PyVTK/VTK and the PyVTK author
suggested to ask this mailing list about it.
Short version of the problem:
=============================
PyVTK can write ascii and binary vtk-files (i.e. the data
being written as text or binary).
When writing UnstructuredGrids, the ascii version can be read by
MayaVi (which can import vtk-files) but the binary version causes
MayaVi (or rather VTK?) to print the following error messages when
importing the vtk-file:
ERROR: In /usr/local/VTK/nightly/VTK/IO/vtkUnstructuredGridReader.cxx, line 343
vtkUnstructuredGridReader (0x8553e50): Unrecognized keyword:
ERROR: In /usr/local/VTK/nightly/VTK/IO/vtkUnstructuredGridReader.cxx, line 343
vtkUnstructuredGridReader (0x8553e50): Unrecognized keyword:
I attach the files example3.vtk (text) and example3b.vtk (binary),
they are also available from http://www.soton.ac.uk/~fangohr/geheim/vtk.
The question to the VTK cracks is:
Can you see why VTK has trouble reading the binary file? (Or should
there be a bug in vtkUnstructuredGridReader.cxx?)
Maybe my comparing the binary and the ascii-version (as attached) an
expert can spot the offending byte/structure etc.
Thanks for any feedback!
More details:
============================
For the really interested, here are some more details:
- the problem occurs only when a binary vtk file is written. The lines
above work fine if line 6 ends with format='ascii' (as stated abover)
- here is a part of the source of example3.py (as comes with PyVTK in
the examples-subdirectory), and which has been used to create the
attached vtk-data files
1 vtk = VtkData(\
2 UnstructuredGrid(points,
3 hexahedron=[[0,1,4,3,6,7,10,9],
4 [1,2,5,4,7,8,11,10]],
5 tetra=[[6,10,9,12],
6 [5,11,10,14]],
7 polygon=[15,16,17,14,13,12],
8 triangle_strip=[18,15,19,16,20,17],
9 quad=[22,23,20,19],
10 triangle=[[21,22,18],
11 [22,19,18]],
12 line=[26,25],
13 vertex=[24]
14 ),
The problem disappears when one writes only _one_ data structure (such
as only tetrahedra or only triangles). To be clear: if you comment out all but one
structure between lines 3--13, then the binary file turns out to be
okay (i.e. can be read by MayaVi and thus by VTK).
Writing several data structures together (as in lines 3 to 13 in the
code above) seems to cause the problem.
So possibly, it is something _between_ the different data sets. But what? And how to fix it?
P.S. I am using (the latest) PyVTK-0.4.62, and have tried VTK nightly and VTK 4.0. All produce the same error.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: example3b.vtk
Type: application/octet-stream
Size: 1257 bytes
Desc:
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20030124/c942140f/attachment.obj>
-------------- next part --------------
# vtk DataFile Version 2.0
Unstructured Grid Example
ASCII
DATASET UNSTRUCTURED_GRID
POINTS 27 int
0 0 0
1 0 0
2 0 0
0 1 0
1 1 0
2 1 0
0 0 1
1 0 1
2 0 1
0 1 1
1 1 1
2 1 1
0 1 2
1 1 2
2 1 2
0 1 3
1 1 3
2 1 3
0 1 4
1 1 4
2 1 4
0 1 5
1 1 5
2 1 5
0 1 6
1 1 6
2 1 6
CELLS 11 60
3 21 22 18
3 22 19 18
6 15 16 17 14 13 12
4 6 10 9 12
4 5 11 10 14
1 24
6 18 15 19 16 20 17
4 22 23 20 19
2 26 25
8 0 1 4 3 6 7 10 9
8 1 2 5 4 7 8 11 10
CELL_TYPES 11
5 5 7 10 10 1 6 9 3 12 12
POINT_DATA 27
VECTORS Vectors0 int
1 0 0
1 1 0
0 2 0
1 0 0
1 1 0
0 2 0
1 0 0
1 1 0
0 2 0
1 0 0
1 1 0
0 2 0
0 0 1
0 0 1
0 0 1
0 0 1
0 0 1
0 0 1
0 0 1
0 0 1
0 0 1
0 0 1
0 0 1
0 0 1
0 0 1
0 0 1
0 0 1
SCALARS Scalars0 int 1
LOOKUP_TABLE default
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
More information about the vtkusers
mailing list