<div dir="ltr">Raphael,<div>Indeed, the FIELD definitions have to be after the dataset details according to:</div><div><br></div><div><a href="http://www.vtk.org/wp-content/uploads/2015/04/file-formats.pdf">http://www.vtk.org/wp-content/uploads/2015/04/file-formats.pdf</a><br></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Aug 6, 2015 at 11:14 AM Schubert, Raphael <<a href="mailto:raphael.schubert@iwm.fraunhofer.de">raphael.schubert@iwm.fraunhofer.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>
<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>
</div>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the ParaView Wiki at: <a href="http://paraview.org/Wiki/ParaView" rel="noreferrer" target="_blank">http://paraview.org/Wiki/ParaView</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=ParaView" rel="noreferrer" target="_blank">http://markmail.org/search/?q=ParaView</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/paraview" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/paraview</a><br>
</blockquote></div>