Skip to main content

conspire/geometry/mesh/from/voxels/
mod.rs

1#[cfg(test)]
2mod test;
3
4use crate::geometry::{Coordinate, grid::Voxels, mesh::Mesh};
5
6impl Mesh<3> {
7    pub fn from_voxels<T>(voxels: Voxels<T>, remove: Option<&[T]>) -> Self
8    where
9        T: Copy + PartialEq + Into<usize>,
10    {
11        Self::from_voxels_embedded(
12            voxels,
13            remove,
14            &Coordinate::from([1.0; 3]),
15            &Coordinate::from([0.0; 3]),
16        )
17    }
18    pub(super) fn from_voxels_embedded<T>(
19        voxels: Voxels<T>,
20        remove: Option<&[T]>,
21        scale: &Coordinate<3>,
22        translate: &Coordinate<3>,
23    ) -> Self
24    where
25        T: Copy + PartialEq + Into<usize>,
26    {
27        let nel = *voxels.nel();
28        Self::from_lattice_cells(
29            voxels
30                .logical_iter()
31                .filter(|&(_index, &block)| remove.is_none_or(|ids| !ids.contains(&block)))
32                .map(|(index, &block)| (index, block.into())),
33            nel,
34            scale,
35            translate,
36        )
37    }
38}