Tries to load particles from the given file path, automatically detecting supported file extensions
(
input_file: P,
)
| 15 | |
| 16 | /// Tries to load particles from the given file path, automatically detecting supported file extensions |
| 17 | pub fn particles_from_file<R: Real, P: AsRef<Path>>( |
| 18 | input_file: P, |
| 19 | ) -> Result<Vec<Vector3<R>>, anyhow::Error> { |
| 20 | let input_file = input_file.as_ref(); |
| 21 | if let Some(extension) = input_file.extension() { |
| 22 | let extension = extension |
| 23 | .to_str() |
| 24 | .ok_or(anyhow!("Invalid extension of input file"))?; |
| 25 | |
| 26 | match extension.to_lowercase().as_str() { |
| 27 | "vtk" => vtk_format::particles_from_vtk(input_file), |
| 28 | "vtu" => vtk_format::particles_from_vtk(input_file), |
| 29 | "xyz" => xyz_format::particles_from_xyz(input_file), |
| 30 | "ply" => ply_format::particles_from_ply(input_file), |
| 31 | "bgeo" => bgeo_format::particles_from_bgeo(input_file), |
| 32 | "json" => json_format::particles_from_json(input_file), |
| 33 | _ => Err(anyhow!( |
| 34 | "Unsupported file format extension \"{}\" for reading particles", |
| 35 | extension |
| 36 | )), |
| 37 | } |
| 38 | } else { |
| 39 | Err(anyhow!( |
| 40 | "Unable to detect file format of particle input file (file name has to end with supported extension)", |
| 41 | )) |
| 42 | } |
| 43 | } |