vtkio
A parser and writer for the Visualization Toolkit (VTK) file formats.
This is meant to be a feature complete parser of Legacy and XML VTK file formats. Both serial and parallel XML file formats are supported.
The Legacy format parser is written using nom.
XML VTK files are import and exported with quick-xml and serde crates.
Usage
To use this library simply add the crate name to your Cargo.toml file:
vtkio = "0.7"
Examples
Many sample files can be found in the assets directory. Below are some examples for using this library.
Import/Export
Below we load a VTK file named tet.vtk, modify it and write it back in Legacy ASCII format.
use *; // import model definition of a VTK file
The next two examples show how to create new Vtk instances manually.
Simple triangular cell
Here, we create a Vtk instance containing a single triangle represented as a cell of an unstructured grid.
Mixing Cell Types
The following example creates a mesh with a triangle and a quadrilateral.
Extract field data
Once a Vtk file is read or loaded from a file, it is useful to extract useful data from it. In the following snippet, an "id" field attached to vertices is extracted from a Vtk struct.
Features
There are two main features available:
- XML File support via the
xmlfeature flag (enabled by default). This allows importing and exporting VTK files in the modern XML format. If disabled, only the legacy file format is supported, however the build is faster since it does not include additional dependencies (serdeandquick-xml) and code needed to parse and write XML files. - Compression via the
compressionfeature flag (enabled by default). This flag exposes additional APIs to export and import compressed VTK files (only for XML format). This feature has no benefit when thexmlfeature is disabled.
To disable the features above simply set default-features to false. To enable a specific feature
add it to the list under features. For instance to disable only the compression feature, add the
vtkio dependency as
vtkio =
To disable all additional features use
vtkio =
Changes
Version 0.3 of the crate supports only Legacy VTK formats. For a list of changes
introduced in the new versions of vtkio (v0.4+) see the CHANGELOG.
License
This repository is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.