Writes a mesh and its attribute data to the given file path, automatically detects the file format
(
mesh: &'a MeshWithData<R, MeshT>,
output_file: P,
_format_params: &OutputFormatParameters,
)
| 274 | |
| 275 | /// Writes a mesh and its attribute data to the given file path, automatically detects the file format |
| 276 | pub fn write_mesh<'a, R: Real, MeshT: Mesh3d<R>, P: AsRef<Path>>( |
| 277 | mesh: &'a MeshWithData<R, MeshT>, |
| 278 | output_file: P, |
| 279 | _format_params: &OutputFormatParameters, |
| 280 | ) -> Result<(), anyhow::Error> |
| 281 | where |
| 282 | for<'b> &'b MeshWithData<R, MeshT>: IntoVtkUnstructuredGridPiece, |
| 283 | { |
| 284 | let output_file = output_file.as_ref(); |
| 285 | info!( |
| 286 | "Writing mesh with {} vertices and {} cells to \"{}\"...", |
| 287 | mesh.mesh.vertices().len(), |
| 288 | mesh.mesh.cells().len(), |
| 289 | output_file.display() |
| 290 | ); |
| 291 | |
| 292 | if let Some(extension) = output_file.extension() { |
| 293 | let extension = extension |
| 294 | .to_str() |
| 295 | .ok_or(anyhow!("Invalid extension of output file"))?; |
| 296 | |
| 297 | match extension.to_lowercase().as_str() { |
| 298 | "vtk" => vtk_format::write_vtk(mesh, output_file, "mesh"), |
| 299 | "ply" => ply_format::mesh_to_ply(mesh, output_file), |
| 300 | "obj" => obj_format::mesh_to_obj(mesh, output_file), |
| 301 | _ => Err(anyhow!( |
| 302 | "Unsupported file format extension \"{}\"", |
| 303 | extension, |
| 304 | )), |
| 305 | }?; |
| 306 | } else { |
| 307 | return Err(anyhow!( |
| 308 | "Unable to detect file format of mesh output file (file name has to end with supported extension)", |
| 309 | )); |
| 310 | }; |
| 311 | |
| 312 | info!("Successfully wrote mesh to file."); |
| 313 | Ok(()) |
| 314 | } |
| 315 | |
| 316 | #[allow(dead_code)] |
| 317 | pub fn to_binary_f32<R: Real, P: AsRef<Path>>(file: P, values: &[R]) -> Result<(), anyhow::Error> { |
no test coverage detected