Skip to main content

conspire/geometry/mesh/remesh/
mod.rs

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