Tries to write `data` that is convertible to a VTK `DataSet` into a big endian VTK file
(
data: impl IntoVtkDataSet,
filename: P,
title: &str,
)
| 186 | |
| 187 | /// Tries to write `data` that is convertible to a VTK `DataSet` into a big endian VTK file |
| 188 | pub fn write_vtk<P: AsRef<Path>>( |
| 189 | data: impl IntoVtkDataSet, |
| 190 | filename: P, |
| 191 | title: &str, |
| 192 | ) -> Result<(), anyhow::Error> { |
| 193 | profile!("write_vtk"); |
| 194 | let vtk_file = Vtk { |
| 195 | version: Version::new_legacy(4, 2), |
| 196 | title: title.to_string(), |
| 197 | file_path: None, |
| 198 | byte_order: ByteOrder::BigEndian, |
| 199 | data: data.into_dataset(), |
| 200 | }; |
| 201 | |
| 202 | let filename = filename.as_ref(); |
| 203 | if let Some(dir) = filename.parent() { |
| 204 | create_dir_all(dir).context("Failed to create parent directory of output file")?; |
| 205 | } |
| 206 | vtk_file |
| 207 | .export_be(filename) |
| 208 | .context("Error while writing VTK output to file") |
| 209 | } |
| 210 | |
| 211 | /// Tries to read the given VTK file |
| 212 | pub fn read_vtk<P: AsRef<Path>>(filename: P) -> Result<Vtk, anyhow::Error> { |