<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style id="owaParaStyle" type="text/css">P {margin-top:0;margin-bottom:0;}</style>
</head>
<body ocsi="0" fpstyle="1">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">I use the following script to generate three vtk files containing different dataset types and an additional FIELD.<br>
<br>
import numpy as np<br>
import vtk<br>
from vtk.util.numpy_support import numpy_to_vtk<br>
<br>
for dataset in (vtk.vtkStructuredPoints, <br>
vtk.vtkRectilinearGrid, <br>
vtk.vtkPolyData):<br>
<br>
vtkData = dataset()<br>
<br>
if dataset is vtk.vtkStructuredPoints:<br>
vtkWriter = vtk.vtkStructuredPointsWriter()<br>
<br>
vtkData.SetOrigin(0.0, 0.0, 0.0)<br>
vtkData.SetSpacing(1.0, 1.0, 1.0)<br>
vtkData.SetExtent(0, 1, 0, 1, 0, 1)<br>
<br>
elif dataset is vtk.vtkPolyData:<br>
vtkWriter = vtk.vtkPolyDataWriter()<br>
<br>
vtkPoints = vtk.vtkPoints()<br>
vtkPoints.SetData(numpy_to_vtk(np.asarray(<br>
[[0.0, 0.0, 0.0], <br>
[1.0, 0.0, 0.0], <br>
[0.0, 1.0, 0.0], <br>
[1.0, 1.0, 0.0], <br>
[0.0, 0.0, 1.0],<br>
[1.0, 0.0, 1.0],<br>
[0.0, 1.0, 1.0],<br>
[1.0, 1.0, 1.0]])))<br>
vtkData.SetPoints(vtkPoints)<br>
<br>
elif dataset is vtk.vtkRectilinearGrid:<br>
vtkWriter = vtk.vtkRectilinearGridWriter()<br>
<br>
vtkData.SetDimensions(2,2,2)<br>
vtkData.SetXCoordinates(numpy_to_vtk(np.asarray([0.0, 1.0])))<br>
vtkData.SetYCoordinates(numpy_to_vtk(np.asarray([0.0, 1.0])))<br>
vtkData.SetZCoordinates(numpy_to_vtk(np.asarray([0.0, 1.0])))<br>
<br>
# file scope definition of Pi<br>
vtkArray = numpy_to_vtk(np.asarray(3.141).reshape(1,1),deep=1)<br>
vtkArray.SetName("Pi")<br>
vtkData.GetFieldData().AddArray(vtkArray)<br>
<br>
vtkWriter.SetFileName(str(dataset) + ".vtk")<br>
vtkWriter.SetHeader("")<br>
vtkWriter.SetFileTypeToASCII()<br>
<br>
vtkWriter.SetInput(vtkData)<br>
vtkWriter.Write()<br>
<br>
/endscript<br>
<br>
The files generated from this are<br>
# vtk DataFile Version 3.0<br>
<br>
ASCII<br>
DATASET POLYDATA<br>
FIELD FieldData 1<br>
Pi 1 1 double<br>
3.141 <br>
POINTS 8 double<br>
0 0 0 1 0 0 0 1 0 <br>
1 1 0 0 0 1 1 0 1 <br>
0 1 1 1 1 1 <br>
<br>
# vtk DataFile Version 3.0<br>
<br>
ASCII<br>
DATASET RECTILINEAR_GRID<br>
FIELD FieldData 1<br>
Pi 1 1 double<br>
3.141 <br>
DIMENSIONS 2 2 2<br>
X_COORDINATES 2 double<br>
0 1 <br>
Y_COORDINATES 2 double<br>
0 1 <br>
Z_COORDINATES 2 double<br>
0 1 <br>
<br>
# vtk DataFile Version 3.0<br>
<br>
ASCII<br>
DATASET STRUCTURED_POINTS<br>
FIELD FieldData 1<br>
Pi 1 1 double<br>
3.141 <br>
DIMENSIONS 2 2 2<br>
SPACING 1 1 1<br>
ORIGIN 0 0 0<br>
<br>
Note the FIELD preceding the dataset details. All files can be read back into python without problems, but when trying to view each file in using Paraview 4.3.1, things get interesting:<br>
<br>
- POLYDATA works.<br>
- RECTILINEAR_GRID produces an error (which, btw, contains a typo), refuses to render anything but displays everything correctly in the Information tab.<br>
<br>
ERROR: In /home/kitware/Dashboards/buildbot/paraview-debian4dash-linux-shared-release_qt4_superbuild/source-paraview/VTK/IO/Parallel/vtkPDataSetReader.cxx, line 701<br>
vtkPDataSetReader (0x8874010): Expecting 'DIMENSIONS' insted of: FIELD<br>
<br>
- STRUCTURED_POINTS does not produce any errors, still refuses to render but displays everything correctly in the Information tab.<br>
<br>
If I now (manually) put the FIELDS definition after the dataset details, everything works fine.<br>
<br>
Is this problem with Paraview, or am I doing something with the vtk format that should not be possible at all? I got the idea from
<a href="http://www.visitusers.org/index.php?title=Time_and_Cycle_in_VTK_files" target="_blank">
http://www.visitusers.org/index.php?title=Time_and_Cycle_in_VTK_files</a>.<br>
<br>
Thanks<br>
Raphael<br>
<br>
Software versions:<br>
<br>
Paraview 4.3.1 Linux 64bit<br>
<br>
Python 2.7.8 |Anaconda 2.1.0 (64-bit)| (default, Aug 21 2014, 18:22:21)<br>
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2<br>
<br>
vtk.vtkVersion().GetVTKVersion()<br>
'5.10.1'<br>
<br>
</div>
</body>
</html>