#writer #mesh #io #vtk

vtkio

Parser and writer for the legacy VTK file format

20 unstable releases (5 breaking)

0.6.3 Mar 14, 2021
0.5.0 Dec 3, 2020
0.4.0 Nov 29, 2020
0.3.1 Dec 6, 2019
0.1.6 Nov 10, 2018

#1086 in Parser implementations

Download history 600/week @ 2023-11-20 575/week @ 2023-11-27 465/week @ 2023-12-04 307/week @ 2023-12-11 425/week @ 2023-12-18 271/week @ 2023-12-25 199/week @ 2024-01-01 301/week @ 2024-01-08 410/week @ 2024-01-15 419/week @ 2024-01-22 655/week @ 2024-01-29 650/week @ 2024-02-05 547/week @ 2024-02-12 499/week @ 2024-02-19 481/week @ 2024-02-26 428/week @ 2024-03-04

1,990 downloads per month
Used in 6 crates (4 directly)

MIT/Apache

425KB
8K SLoC

vtkio

A parser and writer for the Visualization Toolkit (VTK) file formats.

On crates.io On docs.rs Build Status

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:

[dependencies]
vtkio = "0.6"

Examples

Many sample files can be found in the assets directory. For the following example, we will load a VTK file named tet.vtk, modify it and write it back in Legacy ASCII format.

use vtkio::model::*; // import model definition of a VTK file
use vtkio::{import, export_ascii};
fn main() {
    use std::path::PathBuf;
    let file_path = PathBuf::from("assets/tet.vtk");
    
    let mut vtk_file = import(&file_path)
        .expect(&format!("Failed to load file: {:?}", file_path));
    
    vtk_file.version = Version::new((4,2)); // arbitrary change

    export_ascii(vtk_file, &file_path)
        .expect(&format!("Failed to save file: {:?}", file_path));
}

Features

There are two main features available:

  • XML File support via the xml feature 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 (serde and quick-xml) and code needed to parse and write XML files.
  • Compression via the compression feature 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 the xml feature 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

[dependencies]
vtkio = { version = "0.6", default-features = false, features = ["xml"] }

To disable all additional features use

[dependencies]
vtkio = { version = "0.6", default-features = false }

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

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.

Dependencies

~2.7–5MB
~93K SLoC