From f2503088797ac112704d8daeaefa823979632cfa Mon Sep 17 00:00:00 2001 From: JHenneberg Date: Wed, 24 Nov 2021 16:04:22 +0100 Subject: [PATCH] init Example CellType::Vertex --- src/examples/mod.rs | 1 + src/examples/vertex.rs | 24 ++++++++++++++++++++++++ src/lib.rs | 17 ++++++++++------- 3 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 src/examples/mod.rs create mode 100644 src/examples/vertex.rs diff --git a/src/examples/mod.rs b/src/examples/mod.rs new file mode 100644 index 0000000..f3d0c57 --- /dev/null +++ b/src/examples/mod.rs @@ -0,0 +1 @@ +mod vertex; diff --git a/src/examples/vertex.rs b/src/examples/vertex.rs new file mode 100644 index 0000000..32a955a --- /dev/null +++ b/src/examples/vertex.rs @@ -0,0 +1,24 @@ +use crate::model::*; + +/// Creates a single vertex +pub fn example_vertex() -> Vtk { + Vtk { + version: Version { major: 4, minor: 2 }, + title: String::new(), + byte_order: ByteOrder::BigEndian, + file_path: None, + data: DataSet::inline(UnstructuredGridPiece { + points: IOBuffer::F64(vec![1.0, 1.0, 0.0]), + cells: Cells { + cell_verts: VertexNumbers::XML { + connectivity: vec![0], + offsets: vec![1], + }, + types: vec![CellType::Vertex; 1], + }, + data: Attributes { + ..Default::default() + }, + }), + } +} diff --git a/src/lib.rs b/src/lib.rs index 4a24d83..20048b0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -47,17 +47,17 @@ //! println!("{}", output); //! } //! ``` -//! +//! //! To quickly extract some data from a file, you can cast it to an `f64` type as follows -//! +//! //! ```no_run //! use vtkio::model::*; // import model definition of a VTK file -//! +//! //! // Load up vtk file. //! let file_path = "../assets/para_tet.vtk"; //! let mut vtk = Vtk::import(&file_path) //! .expect(&format!("Failed to load file: {:?}", file_path)); -//! +//! //! // Get all the pieces knowing that type they are. //! let pieces = if let DataSet::UnstructuredGrid { pieces, .. } = vtk.data { //! pieces @@ -68,7 +68,7 @@ //! // Often files have only a single piece, so we load it up here. //! // To avoid cloning you can also use `into_loaded_piece_data` here. //! let piece = pieces[0].load_piece_data(None).unwrap(); -//! +//! //! // Get the first cell attribute. //! let attribute = &piece.data.cell[0]; //! @@ -86,12 +86,15 @@ //! } else { //! panic!("First attribute is not a field"); //! }; -//! +//! //! assert_eq!(data.as_slice(), &[0.0]); -//! ``` +//! ``` #[macro_use] extern crate nom; +#[doc = include_str!("examples/vertex.rs")] +mod examples; + #[macro_use] pub mod basic;