Input/Outputs

vtkIO module of geos-mesh package contains generic methods to read and write different format of VTK meshes.

geos.mesh.io.vtkIO module

Input and Output methods for various VTK mesh formats. Supports reading: .vtk (legacy), .vtu, .vts, .vti, .vtp, .vtr, .pvtu, .pvts, .pvti, .pvtp, .pvtr Supports writing: .vtk, .vtu, .vts Uses vtkXMLGenericDataObjectReader for automatic XML format detection.

class geos.mesh.io.vtkIO.VtkFormat(value)[source]

Bases: Enum

Enumeration for supported VTK file formats and their extensions.

PVTI = '.pvti'
PVTP = '.pvtp'
PVTR = '.pvtr'
PVTS = '.pvts'
PVTU = '.pvtu'
VTI = '.vti'
VTK = '.vtk'
VTP = '.vtp'
VTR = '.vtr'
VTS = '.vts'
VTU = '.vtu'
class geos.mesh.io.vtkIO.VtkOutput(output, isDataModeBinary=True)[source]

Bases: object

Configuration for writing a VTK file.

isDataModeBinary = True
output
geos.mesh.io.vtkIO.readMesh(filepath)[source]

Reads a VTK file, automatically detecting the format.

Uses vtkXMLGenericDataObjectReader for all XML-based formats (.vtu, .vts, .vti, .vtp, .vtr and their parallel variants) and vtkUnstructuredGridReader for legacy .vtk format.

Parameters:

filepath (str) – The path to the VTK file.

Raises:
  • FileNotFoundError – If the input file does not exist.

  • ValueError – If no suitable reader can be found for the file.

Returns:

The resulting mesh data.

Return type:

vtkPointSet

geos.mesh.io.vtkIO.readUnstructuredGrid(filepath)[source]

Reads a VTK file and ensures it is a vtkUnstructuredGrid.

This function uses the general readMesh to load the data and then validates its type.

Parameters:

filepath (str) – The path to the VTK file.

Raises:
  • FileNotFoundError – If the input file does not exist.

  • ValueError – If no suitable reader can be found for the file.

  • TypeError – If the file is read successfully but is not a vtkUnstructuredGrid.

Returns:

The resulting unstructured grid data.

Return type:

vtkUnstructuredGrid

geos.mesh.io.vtkIO.writeMesh(mesh, vtkOutput, canOverwrite=False)[source]

Writes a vtkPointSet to a file.

The format is determined by the file extension in VtkOutput.output.

Parameters:
  • mesh (vtkPointSet) – The grid data to write.

  • vtkOutput (VtkOutput) – Configuration for the output file.

  • canOverwrite (bool, optional) – If False, raises an error if the file already exists. Defaults to False.

Raises:
  • FileExistsError – If the output file exists and canOverwrite is False.

  • ValueError – If the file extension is not a supported write format.

  • RuntimeError – If the VTK writer fails to write the file.

Returns:

Returns 1 on success, consistent with the VTK writer’s return code.

Return type:

int