Skip to main content

conspire/geometry/mesh/remesh/
mod.rs

1#[cfg(test)]
2mod test;
3
4mod adaptive;
5mod triangles;
6mod uniform;
7
8use crate::{
9    geometry::mesh::Mesh,
10    math::{Quantity, Scalar},
11    units::Length,
12};
13
14const D: usize = 3;
15
16/// A remeshing scheme with a number of iterations and a metric.
17pub struct Remeshing {
18    /// Number of remeshing iterations.
19    pub iterations: usize,
20    /// The metric (isotropic or anisotropic).
21    pub metric: RemeshingMetric,
22}
23
24/// Different metrics for remeshing.
25pub enum RemeshingMetric {
26    /// Isotropic remeshing (circular/spherical target metric).
27    Isotropic(IsotropicSizing),
28    /// Anisotropic remeshing (directional, curvature-aligned target metric).
29    Anisotropic(AnisotropicSizing),
30}
31
32/// Sizing for isotropic remeshing.
33pub enum IsotropicSizing {
34    /// Constant target edge length over the whole mesh ([`None`] = mean edge length).
35    Uniform { length: Option<Quantity<Length>> },
36    /// Curvature-driven scalar size field (Dunyach).
37    Adaptive {
38        tolerance: Quantity<Length>,
39        minimum: Quantity<Length>,
40        maximum: Quantity<Length>,
41        gradation: Scalar,
42    },
43}
44
45/// Sizing for anisotropic remeshing (not implemented yet; parameters to be determined).
46pub enum AnisotropicSizing {
47    Uniform,
48    Adaptive,
49}
50
51impl Mesh<D> {
52    pub fn remesh(self, remeshing: Remeshing) -> Result<Self, &'static str> {
53        let Remeshing { iterations, metric } = remeshing;
54        match metric {
55            RemeshingMetric::Isotropic(sizing) => match sizing {
56                IsotropicSizing::Uniform { length } => self.uniform_remesh(iterations, length),
57                IsotropicSizing::Adaptive {
58                    tolerance,
59                    minimum,
60                    maximum,
61                    gradation,
62                } => self.adaptive_remesh(iterations, tolerance, minimum, maximum, gradation),
63            },
64            RemeshingMetric::Anisotropic(_) => Err("anisotropic remeshing is not implemented yet"),
65        }
66    }
67}