File format for polyhedron unstructured grid data


I’d like to write an exporter of 3D unstructured volume grids (cells composed of arbitrary shapes of polyhedrons, serial data format) to export the 3D grid to VTK. I guess my options include the XML Unstructured Grid format used by vtkXMLUnstructuredGridReader/Writer (.vtu format) or the legacy VTK file format (.vtk format)? I wonder which approach I should try to take. Looks like XML format supports arbitrary polyhedrons. I think the legacy VTK file format does not, so polyhedrons would need to be decomposed to supported cell types. Therefore XML format seems more promising. Thanks for VTK!

Is there some drawback/limitation for exporting all cell types (tetras, hexes, …) as Polyhedron cell type 42? That would make writing of export routine a bit easier.

Hi, definitely not an expert here, but I wrote this small example (1.5 KB) to write down a simple hexaedral cell both as an xml unstrucutred grid and a legacy unstructured grid.

It shows that:

  1. A vtk legacy file can have polyhedrons (and paraview will read it, if you try)
  2. How to actually write a polyhedron in the legacy format, by inspecting the resulting file

Still, the xml format is probably the one to be chosen in general.

1 Like