I need to export both simple geometry and a vector field to some VTK files. I have managed to export the geometry, but am struggeling to figure out how to export the vector field. What is the structure/format of the file I need?
This is what I have so far (by the way, the vectors need to be arbitrarily placed, meaning that strucured grid and so on won’t work):
<?xml version="1.0"?>
<VTKFile type="PolyData" version="0.1" byte_order="LittleEndian">
<PolyData>
<Piece NumberOfPoints="8" NumberOfVerts="0" NumberOfLines="0" NumberOfStrips="0" NumberOfPolys="5">
<Points>
<DataArray type="Float32" NumberOfComponents="3" format="ascii">
//point data//
</DataArray>
</Points>
<Polys>
<DataArray type="Int32" Name="connectivity" format="ascii">
//connectivity data//
</DataArray>
<DataArray type="Int32" Name="offsets" format="ascii">
//offsett data//
</DataArray>
</Polys>
</Piece>
//Need to put vector field with it's own points here//
</PolyData>
</VTKFile>
Update: After suggestions from Chris (see answer below) I have updated the file to this form:
<?xml version="1.0"?>
<VTKFile type="UnstructuredGrid" version="0.1" byte_order="LittleEndian">
<UnstructuredGrid>
<Piece NumberOfPoints="50" NumberOfCells="0">
<PointData Vectors="Velocity">
<DataArray Vectors="Velocity">
//vector data//
</DataArray>
</PointData>
<Points>
<DataArray type="Float32" NumberOfComponents="3" format="ascii">
//point data//
</DataArray>
</Points>
<Cells/>
<CellData/>
</Piece>
</UnstructuredGrid>
</VTKFile>
From you example XML file it seems that the vector field is defined at different coordinates from the nodes of your PolyData. If this is the case then you will need to use two different files. From the VTK File Format specification, which is part of the VTK User’s Guide (see http://www.vtk.org/VTK/img/file-formats.pdf):
Your vector field sounds like
UnstructuredGriddata, where you have to specify the coordinates of the grid nodes explicitly (unlike, sayImageGrids, where the node coordinates are defined implicitly by the spacing and the extent of the data). This obviously cannot go in a PolyData VTK file (see the second line of your example XML file).So try writing a new file for your vector data with the outline (taken from the file formats document):
Update: As discussed in the comments, the
Cellselement must be specified (theCellDataelement can be left empty, as only point data is being speicifed). TheCellselement specifies the cell types, connectivity and offsets. For a series of unconnected points (i.e. particles) this information is specified as arrays of lengthn, wherenis the number of data points and where