{"id":16304280,"url":"https://github.com/elrnv/vtkio","last_synced_at":"2025-04-09T11:10:30.311Z","repository":{"id":45957668,"uuid":"145658387","full_name":"elrnv/vtkio","owner":"elrnv","description":"Visualization ToolKit (VTK) file parser and writer","archived":false,"fork":false,"pushed_at":"2024-09-06T16:24:52.000Z","size":396,"stargazers_count":55,"open_issues_count":10,"forks_count":12,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-17T23:32:55.936Z","etag":null,"topics":["parser","vtk","writer"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elrnv.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-22T05:01:59.000Z","updated_at":"2024-10-16T00:27:18.000Z","dependencies_parsed_at":"2024-07-22T01:28:25.017Z","dependency_job_id":"9d304f43-875b-4a57-b3cf-6cb50a09c550","html_url":"https://github.com/elrnv/vtkio","commit_stats":{"total_commits":191,"total_committers":8,"mean_commits":23.875,"dds":"0.18848167539267013","last_synced_commit":"661f7cd4900f76cd9e77ec04cb62a27ea3c2453e"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elrnv%2Fvtkio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elrnv%2Fvtkio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elrnv%2Fvtkio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elrnv%2Fvtkio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elrnv","download_url":"https://codeload.github.com/elrnv/vtkio/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248027407,"owners_count":21035594,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["parser","vtk","writer"],"created_at":"2024-10-10T21:03:00.600Z","updated_at":"2025-04-09T11:10:30.259Z","avatar_url":"https://github.com/elrnv.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# vtkio\n\nA parser and writer for the Visualization Toolkit (VTK) [file\nformats](https://kitware.github.io/vtk-examples/site/VTKFileFormats/).\n\n[![On crates.io](https://img.shields.io/crates/v/vtkio.svg)](https://crates.io/crates/vtkio)\n[![On docs.rs](https://docs.rs/vtkio/badge.svg)](https://docs.rs/vtkio/)\n[![Build Status](https://github.com/elrnv/vtkio/workflows/CI/badge.svg)](https://github.com/elrnv/vtkio/actions)\n\nThis is meant to be a feature complete parser of Legacy and XML VTK file formats. Both serial and\nparallel XML file formats are supported.\n\nThe Legacy format parser is written using [nom](https://crates.io/crates/nom).\nXML VTK files are import and exported with [`quick-xml`](https://crates.io/crates/quick-xml) and [`serde`](https://crates.io/crates/serde) crates.\n\n\n# Usage\n\nTo use this library simply add the crate name to your `Cargo.toml` file:\n\n```rust\n[dependencies]\nvtkio = \"0.7\"\n```\n\n\n## Examples\n\nMany sample files can be found in the `assets` directory. Below are some examples for using this library. \n\n### Import/Export\n\nBelow we load a VTK file named `tet.vtk`, modify it and write it back in Legacy ASCII format.\n\n```rust\nuse vtkio::model::*; // import model definition of a VTK file\nfn main() {\n    use std::path::PathBuf;\n    let file_path = PathBuf::from(\"assets/tet.vtk\");\n\n    let mut vtk_file = Vtk::import(\u0026file_path)\n        .expect(\u0026format!(\"Failed to load file: {:?}\", file_path));\n\n    vtk_file.version = Version::new((4,2)); // arbitrary change\n\n    vtk_file.export_ascii(\u0026file_path)\n        .expect(\u0026format!(\"Failed to save file: {:?}\", file_path));\n}\n```\n\nThe next two examples show how to create new `Vtk` instances manually.\n\n\n### Simple triangular cell\n\nHere, we create a Vtk instance containing a single triangle represented as a cell of an unstructured grid.\n\n```rust\nfn make_triangle() -\u003e Vtk {\n    Vtk {\n        version: Version { major: 4, minor: 2 },\n        title: String::new(),\n        byte_order: ByteOrder::BigEndian,\n        file_path: None,\n        data: DataSet::inline(UnstructuredGridPiece {\n            points: IOBuffer::F64(vec![\n              // coordinates of node 0\n              -1.0, -1.0, 0.0,\n\n               // coordinates of node 1\n               1.0, -1.0, 0.0,\n\n               // coordinates of node 2\n               1.0,  1.0, 0.0,\n            ]),\n            cells: Cells {\n                cell_verts: VertexNumbers::XML {\n                    // connect node 0, 1, 2 (in this order)\n                    connectivity: vec![0, 1, 2],\n\n                    // only one group of size 3\n                    offsets: vec![3],\n                },\n                // only one cell of type triangle\n                types: vec![CellType::Triangle; 1],\n            },\n            data: Attributes {\n                ..Default::default()\n            },\n        }),\n    }\n}\n```\n\n\n### Mixing Cell Types\n\nThe following example creates a mesh with a triangle and a quadrilateral.\n\n```rust\nfn make_mixed_flat_elements() -\u003e Vtk {\n    Vtk {\n        version: Version { major: 4, minor: 2 },\n        title: String::new(),\n        byte_order: ByteOrder::BigEndian,\n        file_path: None,\n        data: DataSet::inline(UnstructuredGridPiece {\n            points: IOBuffer::F64(vec![\n                -1.0, -1.0, 0.0,\n                 1.0, -1.0, 0.0,\n                 1.0,  1.0, 0.0,\n                -1.0,  1.0, 0.0,\n                 2.0, -1.0, 0.2,\n                 2.0,  1.0, 0.2,\n            ]),\n            cells: Cells {\n                cell_verts: VertexNumbers::XML {\n                    connectivity: vec![\n                      // nodes of triangle\n                      0, 1, 2,\n\n                      // nodes of quadrilateral\n                      1, 4, 5, 2,\n                    ],\n                    offsets: vec![\n                      // number of nodes cell 1\n                      3,\n\n                      // number of nodes cell 1 + number of nodes of cell 2\n                      // 3 + 4 = 7\n                      7\n                    ],\n                },\n                types: vec![\n                  CellType::Triangle,\n                  CellType::Quad\n                ],\n            },\n            data: Attributes {\n                ..Default::default()\n            },\n        }),\n    }\n}\n```\n\n### Extract field data\n\nOnce a Vtk file is read or loaded from a file, it is useful to extract useful data from it.\nIn the following snippet, an \"id\" field attached to vertices is extracted from a Vtk struct.\n\n```rust\nfn extract_id_field(vtk: Vtk) -\u003e Vec\u003ci32\u003e {\n    let pieces = if let DataSet::UnstructuredGrid { pieces, .. } = vtk.data {\n        pieces\n    } else {\n        panic!(\"Wrong vtk data type\");\n    };\n\n    // If piece is already inline, this just returns a piece data clone.\n    let piece = pieces[0].load_piece_data(None).expect(\"Failed to load piece data\");\n\n    let attribute = \u0026piece.data.point[0];\n\n    if let Attribute::Field { data_array, .. } = attribute {\n         data_array\n            .iter()\n            .find(|\u0026DataArrayBase { name, .. }| name == \"id\")\n            .expect(\"Failed to find id field\")\n            .data\n            .cast_into::\u003ci32\u003e()\n            .expect(\"Failed cast\")\n    } else {\n        panic!(\"No field attribute found\");\n    }\n}\n```\n\n\n## Features\n\nThere are two main features available:\n\n- XML File support via the `xml` feature flag (enabled by default).\n  This allows importing and exporting VTK files in the modern XML format. If disabled, only the legacy\n  file format is supported, however the build is faster since it does not include additional\n  dependencies (`serde` and `quick-xml`) and code needed to parse and write XML files.\n- Compression via the `compression` feature flag (enabled by default).\n  This flag exposes additional APIs to export and import compressed VTK files (only for XML format).\n  This feature has no benefit when the `xml` feature is disabled.\n\nTo disable the features above simply set `default-features` to `false`. To enable a specific feature\nadd it to the list under `features`. For instance to disable only the `compression` feature, add the\n`vtkio` dependency as\n\n```rust\n[dependencies]\nvtkio = { version = \"0.7\", default-features = false, features = [\"xml\"] }\n```\n\nTo disable all additional features use\n\n```rust\n[dependencies]\nvtkio = { version = \"0.7\", default-features = false }\n```\n\n# Changes\n\nVersion 0.3 of the crate supports only Legacy VTK formats. For a list of changes\nintroduced in the new versions of `vtkio` (v0.4+) see the [CHANGELOG](CHANGELOG.md).\n\n# License\n\nThis repository is licensed under either of\n\n * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or https://www.apache.org/licenses/LICENSE-2.0)\n * MIT License ([LICENSE-MIT](LICENSE-MIT) or https://opensource.org/licenses/MIT)\n\nat your option.\n\nUnless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in\nthe Work by You, as defined in the Apache-2.0 license, shall be dual licensed as above, without\nany additional terms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felrnv%2Fvtkio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felrnv%2Fvtkio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felrnv%2Fvtkio/lists"}