MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/splashsurf / read_surface_mesh

Function read_surface_mesh

splashsurf/src/io.rs:238–273  ·  view source on GitHub ↗

Loads a surface mesh from the given file path, automatically detects the file format

(
    input_file: P,
    _format_params: &InputFormatParameters,
)

Source from the content-addressed store, hash-verified

236
237/// Loads a surface mesh from the given file path, automatically detects the file format
238pub fn read_surface_mesh<R: Real, P: AsRef<Path>>(
239 input_file: P,
240 _format_params: &InputFormatParameters,
241) -> Result<MeshWithData<R, TriMesh3d<R>>, anyhow::Error> {
242 let input_file = input_file.as_ref();
243 info!("Reading mesh from \"{}\"...", input_file.display());
244
245 let mesh = if let Some(extension) = input_file.extension() {
246 profile!("loading surface mesh");
247
248 let extension = extension
249 .to_str()
250 .ok_or(anyhow!("Invalid extension of input file"))?;
251
252 match extension.to_lowercase().as_str() {
253 "vtk" => vtk_format::surface_mesh_from_vtk(input_file),
254 "ply" => ply_format::surface_mesh_from_ply(input_file),
255 _ => Err(anyhow!(
256 "Unsupported file format extension \"{}\" for reading surface meshes",
257 extension
258 )),
259 }
260 } else {
261 Err(anyhow!(
262 "Unable to detect file format of mesh input file (file name has to end with supported extension)",
263 ))
264 }?;
265
266 info!(
267 "Successfully read mesh with {} vertices and {} cells.",
268 mesh.mesh.vertices().len(),
269 mesh.mesh.cells().len()
270 );
271
272 Ok(mesh)
273}
274
275/// Writes a mesh and its attribute data to the given file path, automatically detects the file format
276pub fn write_mesh<'a, R: Real, MeshT: Mesh3d<R>, P: AsRef<Path>>(

Callers 1

convert_meshFunction · 0.85

Calls 2

surface_mesh_from_vtkFunction · 0.85
surface_mesh_from_plyFunction · 0.85

Tested by

no test coverage detected