Writes particles positions to the given file path, automatically detects the file format
(
particles: &[Vector3<R>],
output_file: P,
format_params: &OutputFormatParameters,
)
| 193 | |
| 194 | /// Writes particles positions to the given file path, automatically detects the file format |
| 195 | pub fn write_particle_positions<R: Real, P: AsRef<Path>>( |
| 196 | particles: &[Vector3<R>], |
| 197 | output_file: P, |
| 198 | format_params: &OutputFormatParameters, |
| 199 | ) -> Result<(), anyhow::Error> { |
| 200 | let output_file = output_file.as_ref(); |
| 201 | info!( |
| 202 | "Writing {} particles to \"{}\"...", |
| 203 | particles.len(), |
| 204 | output_file.display() |
| 205 | ); |
| 206 | |
| 207 | if let Some(extension) = output_file.extension() { |
| 208 | profile!("writing particle positions"); |
| 209 | |
| 210 | let extension = extension |
| 211 | .to_str() |
| 212 | .ok_or(anyhow!("Invalid extension of output file"))?; |
| 213 | |
| 214 | match extension.to_lowercase().as_str() { |
| 215 | "vtk" => vtk_format::particles_to_vtk(particles, output_file), |
| 216 | "bgeo" => bgeo_format::particles_to_bgeo( |
| 217 | particles, |
| 218 | output_file, |
| 219 | format_params.enable_compression, |
| 220 | ), |
| 221 | "json" => json_format::particles_to_json(particles, output_file), |
| 222 | _ => Err(anyhow!( |
| 223 | "Unsupported file format extension \"{}\" for writing particles", |
| 224 | extension |
| 225 | )), |
| 226 | }?; |
| 227 | } else { |
| 228 | return Err(anyhow!( |
| 229 | "Unable to detect file format of particle output file (file name has to end with supported extension)", |
| 230 | )); |
| 231 | }; |
| 232 | |
| 233 | info!("Successfully wrote particles to file."); |
| 234 | Ok(()) |
| 235 | } |
| 236 | |
| 237 | /// Loads a surface mesh from the given file path, automatically detects the file format |
| 238 | pub fn read_surface_mesh<R: Real, P: AsRef<Path>>( |
no test coverage detected