MCPcopy Index your code
hub / github.com/InteractiveComputerGraphics/splashsurf / keep_cells_impl

Function keep_cells_impl

splashsurf_lib/src/mesh.rs:393–445  ·  view source on GitHub ↗

Returns a new mesh keeping only the given cells and vertices in the mesh

(
    mesh: &MeshT,
    cell_indices: &[usize],
    vertex_keep_table: &[bool],
)

Source from the content-addressed store, hash-verified

391
392/// Returns a new mesh keeping only the given cells and vertices in the mesh
393fn keep_cells_impl<R: Real, MeshT: Mesh3d<R>>(
394 mesh: &MeshT,
395 cell_indices: &[usize],
396 vertex_keep_table: &[bool],
397) -> MeshT {
398 let vertices = mesh.vertices();
399 let cells = mesh.cells();
400
401 if vertex_keep_table.is_empty() {
402 MeshT::from_vertices_and_connectivity(
403 mesh.vertices().to_vec(),
404 cell_indices.iter().map(|&i| &cells[i]).cloned().collect(),
405 )
406 } else {
407 assert_eq!(mesh.vertices().len(), vertex_keep_table.len());
408
409 let old_to_new_label_map = {
410 let mut label_map = MapType::default();
411 let mut next_label = 0;
412 for (i, keep) in vertex_keep_table.iter().enumerate() {
413 if *keep {
414 label_map.insert(i, next_label);
415 next_label += 1;
416 }
417 }
418 label_map
419 };
420
421 let relabeled_cells: Vec<_> = cell_indices
422 .iter()
423 .map(|&i| &cells[i])
424 .cloned()
425 .map(|mut cell| {
426 for index in cell.vertices_mut() {
427 *index = *old_to_new_label_map
428 .get(index)
429 .expect("Index must be in map");
430 }
431 cell
432 })
433 .collect();
434
435 let relabeled_vertices: Vec<_> = vertex_keep_table
436 .iter()
437 .copied()
438 .enumerate()
439 .filter_map(|(i, should_keep)| if should_keep { Some(i) } else { None })
440 .map(|index| vertices[index])
441 .collect();
442
443 MeshT::from_vertices_and_connectivity(relabeled_vertices, relabeled_cells)
444 }
445}
446
447/// Basic interface for mesh cells consisting of a collection of vertex indices
448pub trait CellConnectivity {

Callers 2

keep_cellsMethod · 0.85
keep_cellsMethod · 0.85

Calls 8

cellsMethod · 0.80
is_emptyMethod · 0.80
to_vecMethod · 0.80
collectMethod · 0.80
vertices_mutMethod · 0.80
verticesMethod · 0.45
iterMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected